KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > core > webservices > ui > panels > ProxySettingsDlg


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.websvc.core.webservices.ui.panels;
21
22 import java.awt.Dialog JavaDoc;
23 import javax.swing.JRadioButton JavaDoc;
24
25 import org.openide.DialogDescriptor;
26 import org.openide.DialogDisplayer;
27 import org.openide.util.NbBundle;
28
29 /**
30  *
31  * @author Jiri Rechtacek, Radko Najman
32  * @version
33  */

34 public class ProxySettingsDlg extends javax.swing.JPanel JavaDoc {
35     private String JavaDoc detectedProxy = null;
36     private boolean isDetectedProxy = true;
37     /**
38      * Creates new form ProxySettingsDlg
39      */

40     public ProxySettingsDlg() {
41         String JavaDoc fromSystem = System.getProperty("netbeans.system_http_proxy");
42         isDetectedProxy = fromSystem != null;
43         detectedProxy = isDetectedProxy ? fromSystem : ""; // NOI18N
44

45         initComponents ();
46
47         hostTextField.setText(WebProxySetter.getInstance().getProxyHost());
48         portTextField.setText(WebProxySetter.getInstance().getProxyPort());
49         setProxyType(WebProxySetter.getInstance().getProxyType());
50
51         getAccessibleContext().setAccessibleDescription(getBundle("CTL_ProxySettingsDlg_Title"));
52         getAccessibleContext().setAccessibleDescription(getBundle("ACS_ProxySettingsDlg"));
53         hostTextField.getAccessibleContext().setAccessibleDescription(getBundle("ACS_ProxySettingsDlg.hostTextField"));
54         portTextField.getAccessibleContext().setAccessibleDescription(getBundle("ACS_ProxySettingsDlg.portTextField"));
55     }
56
57     /** This method is called from within the constructor to
58      * initialize the form.
59      * WARNING: Do NOT modify this code. The content of this method is
60      * always regenerated by the FormEditor.
61      */

62     private void initComponents() {//GEN-BEGIN:initComponents
63
java.awt.GridBagConstraints JavaDoc gridBagConstraints;
64
65         proxyChoiceButtons = new javax.swing.ButtonGroup JavaDoc();
66         directConnection = new javax.swing.JRadioButton JavaDoc();
67         autoDetectProxy = new javax.swing.JRadioButton JavaDoc();
68         manualProxy = new javax.swing.JRadioButton JavaDoc();
69         manualSettingsPanel = new javax.swing.JPanel JavaDoc();
70         hostLabel = new javax.swing.JLabel JavaDoc();
71         portLabel = new javax.swing.JLabel JavaDoc();
72         portTextField = new javax.swing.JTextField JavaDoc();
73         hostTextField = new javax.swing.JTextField JavaDoc();
74
75         proxyChoiceButtons.add (directConnection);
76         if (isDetectedProxy) proxyChoiceButtons.add (autoDetectProxy);
77         proxyChoiceButtons.add (manualProxy);
78
79         setLayout(new java.awt.GridBagLayout JavaDoc());
80
81         setBorder(javax.swing.BorderFactory.createEmptyBorder(8, 8, 8, 8));
82         org.openide.awt.Mnemonics.setLocalizedText(directConnection, org.openide.util.NbBundle.getBundle(ProxySettingsDlg.class).getString("BTN_directConnection"));
83         directConnection.setToolTipText(org.openide.util.NbBundle.getBundle(ProxySettingsDlg.class).getString("TT_ProxySettingsDlg_directConnection"));
84         directConnection.addActionListener(new java.awt.event.ActionListener JavaDoc() {
85             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
86                 directConnectionActionPerformed(evt);
87             }
88         });
89
90         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
91         gridBagConstraints.gridx = 0;
92         gridBagConstraints.gridy = 0;
93         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
94         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
95         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
96         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 8, 0, 0);
97         add(directConnection, gridBagConstraints);
98         directConnection.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(ProxySettingsDlg.class).getString("ACD_directConnection"));
99
100         org.openide.awt.Mnemonics.setLocalizedText(autoDetectProxy, org.openide.util.NbBundle.getBundle(ProxySettingsDlg.class).getString("BTN_autoDetectProxy"));
101         autoDetectProxy.setToolTipText(org.openide.util.NbBundle.getMessage(ProxySettingsDlg.class, "TT_ProxySettingsDlg_autoDetectProxy", new Object JavaDoc[] {isDetectedProxy ? detectedProxy : NbBundle.getMessage(ProxySettingsDlg.class, "MSG_ProxySettingsDlg_ProxyNotFound")}));
102         autoDetectProxy.setEnabled(isDetectedProxy);
103         autoDetectProxy.addActionListener(new java.awt.event.ActionListener JavaDoc() {
104             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
105                 autoDetectProxyActionPerformed(evt);
106             }
107         });
108
109         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
110         gridBagConstraints.gridx = 0;
111         gridBagConstraints.gridy = 1;
112         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
113         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
114         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
115         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 8, 0, 0);
116         add(autoDetectProxy, gridBagConstraints);
117         autoDetectProxy.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(ProxySettingsDlg.class).getString("ACD_autoDetectProxy"));
118
119         org.openide.awt.Mnemonics.setLocalizedText(manualProxy, org.openide.util.NbBundle.getBundle(ProxySettingsDlg.class).getString("BTN_manualProxy"));
120         manualProxy.setToolTipText(org.openide.util.NbBundle.getBundle(ProxySettingsDlg.class).getString("TT_ProxySettingsDlg_manualProxy"));
121         manualProxy.addActionListener(new java.awt.event.ActionListener JavaDoc() {
122             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
123                 manualProxyActionPerformed(evt);
124             }
125         });
126
127         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
128         gridBagConstraints.gridx = 0;
129         gridBagConstraints.gridy = 2;
130         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
131         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
132         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
133         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 8, 0, 0);
134         add(manualProxy, gridBagConstraints);
135         manualProxy.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(ProxySettingsDlg.class).getString("ACD_manualProxy"));
136
137         manualSettingsPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
138
139         hostLabel.setLabelFor(hostTextField);
140         org.openide.awt.Mnemonics.setLocalizedText(hostLabel, getBundle("ProxySettingsDlg.hostLabel.text"));
141         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
142         gridBagConstraints.gridx = 0;
143         gridBagConstraints.gridy = 0;
144         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
145         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 8, 0);
146         manualSettingsPanel.add(hostLabel, gridBagConstraints);
147         hostLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(ProxySettingsDlg.class).getString("ACD_ProxySettingsDlg_hostLabel"));
148
149         portLabel.setLabelFor(portTextField);
150         org.openide.awt.Mnemonics.setLocalizedText(portLabel, getBundle("ProxySettingsDlg.portLabel.text"));
151         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
152         gridBagConstraints.gridx = 0;
153         gridBagConstraints.gridy = 1;
154         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
155         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
156         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
157         manualSettingsPanel.add(portLabel, gridBagConstraints);
158         portLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(ProxySettingsDlg.class).getString("ACD_ProxySettingsDlg_portLabel"));
159
160         portTextField.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
161             public void focusGained(java.awt.event.FocusEvent JavaDoc evt) {
162                 portTextFieldFocusGained(evt);
163             }
164             public void focusLost(java.awt.event.FocusEvent JavaDoc evt) {
165                 portTextFieldFocusLost(evt);
166             }
167         });
168
169         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
170         gridBagConstraints.gridx = 1;
171         gridBagConstraints.gridy = 1;
172         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
173         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
174         gridBagConstraints.ipadx = 50;
175         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
176         gridBagConstraints.weightx = 3.0;
177         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 8, 0, 0);
178         manualSettingsPanel.add(portTextField, gridBagConstraints);
179
180         hostTextField.setColumns(30);
181         hostTextField.addActionListener(new java.awt.event.ActionListener JavaDoc() {
182             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
183                 hostTextFieldActionPerformed(evt);
184             }
185         });
186         hostTextField.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
187             public void focusGained(java.awt.event.FocusEvent JavaDoc evt) {
188                 hostTextFieldFocusGained(evt);
189             }
190             public void focusLost(java.awt.event.FocusEvent JavaDoc evt) {
191                 hostTextFieldFocusLost(evt);
192             }
193         });
194
195         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
196         gridBagConstraints.gridx = 1;
197         gridBagConstraints.gridy = 0;
198         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
199         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
200         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 8, 8, 0);
201         manualSettingsPanel.add(hostTextField, gridBagConstraints);
202
203         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
204         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
205         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
206         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
207         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
208         gridBagConstraints.weightx = 1.0;
209         gridBagConstraints.insets = new java.awt.Insets JavaDoc(2, 28, 10, 24);
210         add(manualSettingsPanel, gridBagConstraints);
211
212     }//GEN-END:initComponents
213

214     private void hostTextFieldActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_hostTextFieldActionPerformed
215
// TODO add your handling code here:
216
}//GEN-LAST:event_hostTextFieldActionPerformed
217

218     private void portTextFieldFocusLost (java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_portTextFieldFocusLost
219
portTextField.select (0, 0);
220     }//GEN-LAST:event_portTextFieldFocusLost
221

222     private void portTextFieldFocusGained (java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_portTextFieldFocusGained
223
portTextField.selectAll ();
224     }//GEN-LAST:event_portTextFieldFocusGained
225

226     private void hostTextFieldFocusLost (java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_hostTextFieldFocusLost
227
hostTextField.select (0, 0);
228     }//GEN-LAST:event_hostTextFieldFocusLost
229

230     private void hostTextFieldFocusGained (java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_hostTextFieldFocusGained
231
hostTextField.selectAll ();
232     }//GEN-LAST:event_hostTextFieldFocusGained
233

234     private void manualProxyActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_manualProxyActionPerformed
235
if (((JRadioButton JavaDoc)evt.getSource ()).isSelected ()) {
236             setProxyType (2 /* MANUAL_SET_PROXY */);
237             hostTextField.requestFocus ();
238         }
239     }//GEN-LAST:event_manualProxyActionPerformed
240

241     private void autoDetectProxyActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_autoDetectProxyActionPerformed
242
if (((JRadioButton JavaDoc)evt.getSource ()).isSelected ()) {
243             setProxyType (1 /* AUTO_DETECT_PROXY */);
244         }
245     }//GEN-LAST:event_autoDetectProxyActionPerformed
246

247     private void directConnectionActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_directConnectionActionPerformed
248
if (((JRadioButton JavaDoc)evt.getSource ()).isSelected ()) {
249             setProxyType (0 /* DIRECT_CONNECTION */);
250         }
251     }//GEN-LAST:event_directConnectionActionPerformed
252

253
254     // Variables declaration - do not modify//GEN-BEGIN:variables
255
private javax.swing.JRadioButton JavaDoc autoDetectProxy;
256     private javax.swing.JRadioButton JavaDoc directConnection;
257     private javax.swing.JLabel JavaDoc hostLabel;
258     private javax.swing.JTextField JavaDoc hostTextField;
259     private javax.swing.JRadioButton JavaDoc manualProxy;
260     private javax.swing.JPanel JavaDoc manualSettingsPanel;
261     private javax.swing.JLabel JavaDoc portLabel;
262     private javax.swing.JTextField JavaDoc portTextField;
263     private javax.swing.ButtonGroup JavaDoc proxyChoiceButtons;
264     // End of variables declaration//GEN-END:variables
265

266     private void setProxyType (int proxyType) {
267         switch (proxyType) {
268             case 0 /* DIRECT_CONNECTION */ :
269                 directConnection.setSelected (true);
270                 manualSettingsPanel.setEnabled (false);
271                 hostTextField.setEnabled (false);
272                 portTextField.setEnabled (false);
273                 hostLabel.setEnabled (false);
274                 portLabel.setEnabled (false);
275                 break;
276             case 1 /* AUTO_DETECT_PROXY */ :
277                 autoDetectProxy.setSelected (true);
278                 manualSettingsPanel.setEnabled (false);
279                 hostTextField.setEnabled (false);
280                 portTextField.setEnabled (false);
281                 hostLabel.setEnabled (false);
282                 portLabel.setEnabled (false);
283                 break;
284             case 2 /* MANUAL_SET_PROXY */ :
285                 manualProxy.setSelected (true);
286                 manualSettingsPanel.setEnabled (true);
287                 hostTextField.setEnabled (true);
288                 portTextField.setEnabled (true);
289                 hostLabel.setEnabled (true);
290                 portLabel.setEnabled (true);
291                 break;
292             default:
293                 assert false : "Unknown proxy type: " + proxyType;
294         }
295     }
296
297     public static boolean showDialog() {
298         boolean result = false;
299
300         ProxySettingsDlg proxyPanel;
301
302         DialogDescriptor dd = new DialogDescriptor(
303                                   proxyPanel = new ProxySettingsDlg(),
304                                   getBundle( "CTL_ProxySettingsDlg_Title" ),
305                                   true, // Modal
306
DialogDescriptor.OK_CANCEL_OPTION, // Option list
307
DialogDescriptor.OK_OPTION, // Default
308
DialogDescriptor.BOTTOM_ALIGN, // Align
309
null, //new HelpCtx ( ProxySettingsDlg.class ), // Help
310
null );
311
312
313         Dialog JavaDoc dialog = DialogDisplayer.getDefault().createDialog( dd );
314         dialog.setVisible (true);
315
316         if ( dd.getValue() == DialogDescriptor.OK_OPTION ) {
317             WebProxySetter.getInstance().setProxyConfiguration (
318                                 proxyPanel.getProxyType (),
319                                 proxyPanel.getUserProxyHost (),
320                                 proxyPanel.getUserProxyPort ());
321             result = true;
322         }
323         
324         return result;
325     }
326     
327     String JavaDoc getUserProxyHost () {
328         return hostTextField.getText ();
329     }
330     
331     String JavaDoc getUserProxyPort () {
332         return portTextField.getText ();
333     }
334     
335     int getProxyType () {
336         if (directConnection.isSelected ()) {
337             return 0;
338         } else if (autoDetectProxy.isSelected ()) {
339             return 1;
340         } else if (manualProxy.isSelected ()) {
341             return 2;
342         }
343         
344         // no button is selected
345
assert false : "Any button must be selected";
346         
347         return 1;
348     }
349
350     private static String JavaDoc getBundle( String JavaDoc key ) {
351         return NbBundle.getMessage( ProxySettingsDlg.class, key );
352     }
353 }
Popular Tags