1 19 20 package org.netbeans.modules.websvc.core.webservices.ui.panels; 21 22 import java.awt.Dialog ; 23 import javax.swing.JRadioButton ; 24 25 import org.openide.DialogDescriptor; 26 import org.openide.DialogDisplayer; 27 import org.openide.util.NbBundle; 28 29 34 public class ProxySettingsDlg extends javax.swing.JPanel { 35 private String detectedProxy = null; 36 private boolean isDetectedProxy = true; 37 40 public ProxySettingsDlg() { 41 String fromSystem = System.getProperty("netbeans.system_http_proxy"); 42 isDetectedProxy = fromSystem != null; 43 detectedProxy = isDetectedProxy ? fromSystem : ""; 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 62 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 64 65 proxyChoiceButtons = new javax.swing.ButtonGroup (); 66 directConnection = new javax.swing.JRadioButton (); 67 autoDetectProxy = new javax.swing.JRadioButton (); 68 manualProxy = new javax.swing.JRadioButton (); 69 manualSettingsPanel = new javax.swing.JPanel (); 70 hostLabel = new javax.swing.JLabel (); 71 portLabel = new javax.swing.JLabel (); 72 portTextField = new javax.swing.JTextField (); 73 hostTextField = new javax.swing.JTextField (); 74 75 proxyChoiceButtons.add (directConnection); 76 if (isDetectedProxy) proxyChoiceButtons.add (autoDetectProxy); 77 proxyChoiceButtons.add (manualProxy); 78 79 setLayout(new java.awt.GridBagLayout ()); 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 () { 85 public void actionPerformed(java.awt.event.ActionEvent evt) { 86 directConnectionActionPerformed(evt); 87 } 88 }); 89 90 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (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 [] {isDetectedProxy ? detectedProxy : NbBundle.getMessage(ProxySettingsDlg.class, "MSG_ProxySettingsDlg_ProxyNotFound")})); 102 autoDetectProxy.setEnabled(isDetectedProxy); 103 autoDetectProxy.addActionListener(new java.awt.event.ActionListener () { 104 public void actionPerformed(java.awt.event.ActionEvent evt) { 105 autoDetectProxyActionPerformed(evt); 106 } 107 }); 108 109 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (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 () { 122 public void actionPerformed(java.awt.event.ActionEvent evt) { 123 manualProxyActionPerformed(evt); 124 } 125 }); 126 127 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (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 ()); 138 139 hostLabel.setLabelFor(hostTextField); 140 org.openide.awt.Mnemonics.setLocalizedText(hostLabel, getBundle("ProxySettingsDlg.hostLabel.text")); 141 gridBagConstraints = new java.awt.GridBagConstraints (); 142 gridBagConstraints.gridx = 0; 143 gridBagConstraints.gridy = 0; 144 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 145 gridBagConstraints.insets = new java.awt.Insets (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 (); 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 () { 161 public void focusGained(java.awt.event.FocusEvent evt) { 162 portTextFieldFocusGained(evt); 163 } 164 public void focusLost(java.awt.event.FocusEvent evt) { 165 portTextFieldFocusLost(evt); 166 } 167 }); 168 169 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (0, 8, 0, 0); 178 manualSettingsPanel.add(portTextField, gridBagConstraints); 179 180 hostTextField.setColumns(30); 181 hostTextField.addActionListener(new java.awt.event.ActionListener () { 182 public void actionPerformed(java.awt.event.ActionEvent evt) { 183 hostTextFieldActionPerformed(evt); 184 } 185 }); 186 hostTextField.addFocusListener(new java.awt.event.FocusAdapter () { 187 public void focusGained(java.awt.event.FocusEvent evt) { 188 hostTextFieldFocusGained(evt); 189 } 190 public void focusLost(java.awt.event.FocusEvent evt) { 191 hostTextFieldFocusLost(evt); 192 } 193 }); 194 195 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (0, 8, 8, 0); 201 manualSettingsPanel.add(hostTextField, gridBagConstraints); 202 203 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (2, 28, 10, 24); 210 add(manualSettingsPanel, gridBagConstraints); 211 212 } 214 private void hostTextFieldActionPerformed (java.awt.event.ActionEvent evt) { } 218 private void portTextFieldFocusLost (java.awt.event.FocusEvent evt) { portTextField.select (0, 0); 220 } 222 private void portTextFieldFocusGained (java.awt.event.FocusEvent evt) { portTextField.selectAll (); 224 } 226 private void hostTextFieldFocusLost (java.awt.event.FocusEvent evt) { hostTextField.select (0, 0); 228 } 230 private void hostTextFieldFocusGained (java.awt.event.FocusEvent evt) { hostTextField.selectAll (); 232 } 234 private void manualProxyActionPerformed (java.awt.event.ActionEvent evt) { if (((JRadioButton )evt.getSource ()).isSelected ()) { 236 setProxyType (2 ); 237 hostTextField.requestFocus (); 238 } 239 } 241 private void autoDetectProxyActionPerformed (java.awt.event.ActionEvent evt) { if (((JRadioButton )evt.getSource ()).isSelected ()) { 243 setProxyType (1 ); 244 } 245 } 247 private void directConnectionActionPerformed (java.awt.event.ActionEvent evt) { if (((JRadioButton )evt.getSource ()).isSelected ()) { 249 setProxyType (0 ); 250 } 251 } 253 254 private javax.swing.JRadioButton autoDetectProxy; 256 private javax.swing.JRadioButton directConnection; 257 private javax.swing.JLabel hostLabel; 258 private javax.swing.JTextField hostTextField; 259 private javax.swing.JRadioButton manualProxy; 260 private javax.swing.JPanel manualSettingsPanel; 261 private javax.swing.JLabel portLabel; 262 private javax.swing.JTextField portTextField; 263 private javax.swing.ButtonGroup proxyChoiceButtons; 264 266 private void setProxyType (int proxyType) { 267 switch (proxyType) { 268 case 0 : 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 : 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 : 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, DialogDescriptor.OK_CANCEL_OPTION, DialogDescriptor.OK_OPTION, DialogDescriptor.BOTTOM_ALIGN, null, null ); 311 312 313 Dialog 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 getUserProxyHost () { 328 return hostTextField.getText (); 329 } 330 331 String 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 assert false : "Any button must be selected"; 346 347 return 1; 348 } 349 350 private static String getBundle( String key ) { 351 return NbBundle.getMessage( ProxySettingsDlg.class, key ); 352 } 353 } | Popular Tags |