1 19 package org.netbeans.modules.options.general; 20 21 import javax.swing.event.DocumentEvent ; 22 import javax.swing.event.DocumentListener ; 23 24 28 public class AdvancedProxyPanel extends javax.swing.JPanel { 29 private GeneralOptionsModel options; 30 private String oldHttpsHost; 31 private String oldHttpsPort; 32 private String oldSocksHost; 33 private String oldSocksPort; 34 35 36 public AdvancedProxyPanel (GeneralOptionsModel model) { 37 options = model; 38 initComponents (); 39 tfHttpProxyHost.getDocument().addDocumentListener (new DocumentListener () { 40 public void insertUpdate(DocumentEvent arg0) { 41 followHttpHostIfDemand (); 42 } 43 44 public void removeUpdate(DocumentEvent arg0) { 45 followHttpHostIfDemand (); 46 } 47 48 public void changedUpdate(DocumentEvent arg0) { 49 followHttpHostIfDemand (); 50 } 51 }); 52 tfHttpProxyPort.getDocument().addDocumentListener (new DocumentListener () { 53 public void insertUpdate(DocumentEvent arg0) { 54 followHttpPortIfDemand (); 55 } 56 57 public void removeUpdate(DocumentEvent arg0) { 58 followHttpPortIfDemand (); 59 } 60 61 public void changedUpdate(DocumentEvent arg0) { 62 followHttpPortIfDemand (); 63 } 64 }); 65 } 66 67 69 public void update (String httpHost, String httpPort) { 70 readOptions (); 71 72 if (! options.getHttpProxyHost ().equals (httpHost)) { 73 tfHttpProxyHost.setText (httpHost); 74 } 75 if (! options.getHttpProxyPort ().equals (httpPort)) { 76 tfHttpProxyPort.setText (httpPort); 77 } 78 } 79 80 public void applyChanges() { 81 writeOptions (); 82 } 83 84 86 private void readOptions () { 87 cbSameProxySettings.setSelected (options.useProxyAllProtocols ()); 88 cbUseProxyAuthentication.setSelected(options.useProxyAuthentication ()); 89 tfHttpProxyHost.setText (options.getHttpProxyHost ()); 90 tfHttpProxyPort.setText (options.getHttpProxyPort ()); 91 tfHttpsProxyHost.setText (options.getHttpsProxyHost ()); 92 tfHttpsProxyPort.setText (options.getHttpsProxyPort ()); 93 tfSocksHost.setText (options.getSocksHost ()); 94 tfSocksPort.setText (options.getSocksPort ()); 95 tfUserName.setText (options.getProxyAuthenticationUsername ()); 96 pfUserPassword.setText (new String (options.getProxyAuthenticationPassword ())); 97 tfNonProxyHosts.setText (options.getNonProxyHosts ()); 98 99 oldHttpsHost = tfHttpsProxyHost.getText (); 100 oldHttpsPort = tfHttpsProxyPort.getText (); 101 oldSocksHost = tfSocksHost.getText (); 102 oldSocksPort = tfSocksPort.getText (); 103 104 followHttpProxyIfDemand(); 105 updateAuthentication (); 106 } 107 108 private void writeOptions () { 109 options.setUseProxyAllProtocols (cbSameProxySettings.isSelected ()); 110 options.setUseProxyAuthentication(cbUseProxyAuthentication.isSelected ()); 111 options.setHttpProxyHost (tfHttpProxyHost.getText ()); 112 options.setHttpProxyPort (tfHttpProxyPort.getText ()); 113 options.setHttpsProxyHost (tfHttpsProxyHost.getText ()); 114 options.setHttpsProxyPort (tfHttpsProxyPort.getText ()); 115 options.setSocksHost (tfSocksHost.getText ()); 116 options.setSocksPort (tfSocksPort.getText ()); 117 options.setNonProxyHosts (tfNonProxyHosts.getText ()); 118 options.setAuthenticationUsername (tfUserName.getText ()); 119 options.setAuthenticationPassword (pfUserPassword.getPassword ()); 120 } 121 122 private void followHttpProxyIfDemand () { 123 boolean same = cbSameProxySettings.isSelected (); 124 tfHttpsProxyHost.setEnabled (! same); 125 tfHttpsProxyPort.setEnabled (! same); 126 tfSocksHost.setEnabled (! same); 127 tfSocksPort.setEnabled (! same); 128 lHttpsProxyHost.setEnabled (! same); 129 lHttpsProxyPort.setEnabled (! same); 130 lSocksHost.setEnabled (! same); 131 lSocksPort.setEnabled (! same); 132 133 followHttpHostIfDemand (); 134 followHttpPortIfDemand (); 135 } 136 137 private void updateAuthentication () { 138 boolean use = cbUseProxyAuthentication.isSelected (); 139 tfUserName.setEnabled (use); 140 lUserName.setEnabled (use); 141 pfUserPassword.setEnabled (use); 142 lUserPassword.setEnabled (use); 143 } 144 145 private void followHttpHostIfDemand () { 146 if (! cbSameProxySettings.isSelected ()) { 147 return ; 148 } 149 String host = tfHttpProxyHost.getText (); 150 tfHttpsProxyHost.setText (host); 151 tfSocksHost.setText (host); 152 } 153 154 private void followHttpPortIfDemand () { 155 if (! cbSameProxySettings.isSelected ()) { 156 return ; 157 } 158 String port = tfHttpProxyPort.getText (); 159 tfHttpsProxyPort.setText (port); 160 tfSocksPort.setText (port); 161 } 162 163 168 private void initComponents() { 170 171 lHttpProxyHost = new javax.swing.JLabel (); 172 tfHttpProxyHost = new javax.swing.JTextField (); 173 cbSameProxySettings = new javax.swing.JCheckBox (); 174 lHttpsProxyHost = new javax.swing.JLabel (); 175 tfHttpsProxyHost = new javax.swing.JTextField (); 176 lSocksHost = new javax.swing.JLabel (); 177 tfSocksHost = new javax.swing.JTextField (); 178 lHttpProxyPort = new javax.swing.JLabel (); 179 lHttpsProxyPort = new javax.swing.JLabel (); 180 lSocksPort = new javax.swing.JLabel (); 181 tfHttpProxyPort = new javax.swing.JTextField (); 182 tfHttpsProxyPort = new javax.swing.JTextField (); 183 tfSocksPort = new javax.swing.JTextField (); 184 lNonProxyHosts = new javax.swing.JLabel (); 185 tfNonProxyHosts = new javax.swing.JTextField (); 186 lNonProxyHostsDescription = new javax.swing.JLabel (); 187 sSeparator = new javax.swing.JSeparator (); 188 cbUseProxyAuthentication = new javax.swing.JCheckBox (); 189 lUserName = new javax.swing.JLabel (); 190 lUserPassword = new javax.swing.JLabel (); 191 tfUserName = new javax.swing.JTextField (); 192 pfUserPassword = new javax.swing.JPasswordField (); 193 194 lHttpProxyHost.setLabelFor(tfHttpProxyHost); 195 org.openide.awt.Mnemonics.setLocalizedText(lHttpProxyHost, org.openide.util.NbBundle.getMessage(AdvancedProxyPanel.class, "LBL_AdvancedProxyPanel_lHttpProxyHost")); 197 org.openide.awt.Mnemonics.setLocalizedText(cbSameProxySettings, org.openide.util.NbBundle.getMessage(AdvancedProxyPanel.class, "LBL_AdvancedProxyPanel_cbSameProxySettings")); cbSameProxySettings.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 199 cbSameProxySettings.setMargin(new java.awt.Insets (0, 0, 0, 0)); 200 cbSameProxySettings.addActionListener(new java.awt.event.ActionListener () { 201 public void actionPerformed(java.awt.event.ActionEvent evt) { 202 cbSameProxySettingsActionPerformed(evt); 203 } 204 }); 205 206 lHttpsProxyHost.setLabelFor(tfHttpsProxyHost); 207 org.openide.awt.Mnemonics.setLocalizedText(lHttpsProxyHost, org.openide.util.NbBundle.getMessage(AdvancedProxyPanel.class, "LBL_AdvancedProxyPanel_lHttpsProxyHots")); 209 lSocksHost.setLabelFor(tfSocksHost); 210 org.openide.awt.Mnemonics.setLocalizedText(lSocksHost, org.openide.util.NbBundle.getMessage(AdvancedProxyPanel.class, "LBL_AdvancedProxyPanel_lSocksHost")); 212 lHttpProxyPort.setLabelFor(tfHttpProxyPort); 213 org.openide.awt.Mnemonics.setLocalizedText(lHttpProxyPort, org.openide.util.NbBundle.getMessage(AdvancedProxyPanel.class, "LBL_AdvancedProxyPanel_lHttpProxyPort")); 215 lHttpsProxyPort.setLabelFor(tfHttpsProxyPort); 216 org.openide.awt.Mnemonics.setLocalizedText(lHttpsProxyPort, org.openide.util.NbBundle.getMessage(AdvancedProxyPanel.class, "LBL_AdvancedProxyPanel_lHttpsProxyPort")); 218 lSocksPort.setLabelFor(tfSocksPort); 219 org.openide.awt.Mnemonics.setLocalizedText(lSocksPort, org.openide.util.NbBundle.getMessage(AdvancedProxyPanel.class, "LBL_AdvancedProxyPanel_lSocksPort")); 221 tfHttpProxyPort.setColumns(4); 222 223 tfHttpsProxyPort.setColumns(4); 224 225 tfSocksPort.setColumns(4); 226 227 lNonProxyHosts.setLabelFor(tfNonProxyHosts); 228 org.openide.awt.Mnemonics.setLocalizedText(lNonProxyHosts, org.openide.util.NbBundle.getMessage(AdvancedProxyPanel.class, "LBL_AdvancedProxyPanel_lNonProxyHosts")); 230 org.openide.awt.Mnemonics.setLocalizedText(lNonProxyHostsDescription, org.openide.util.NbBundle.getMessage(AdvancedProxyPanel.class, "LBL_AdvancedProxyPanel_lNonProxyHostsDescription")); 232 org.openide.awt.Mnemonics.setLocalizedText(cbUseProxyAuthentication, org.openide.util.NbBundle.getMessage(AdvancedProxyPanel.class, "LBL_AdvancedProxyPanel_cbUseProxyAuthentication")); cbUseProxyAuthentication.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 234 cbUseProxyAuthentication.addActionListener(new java.awt.event.ActionListener () { 235 public void actionPerformed(java.awt.event.ActionEvent evt) { 236 cbUseProxyAuthenticationActionPerformed(evt); 237 } 238 }); 239 240 lUserName.setLabelFor(tfUserName); 241 org.openide.awt.Mnemonics.setLocalizedText(lUserName, org.openide.util.NbBundle.getMessage(AdvancedProxyPanel.class, "LBL_AdvancedProxyPanel_lUserName")); 243 lUserPassword.setLabelFor(pfUserPassword); 244 org.openide.awt.Mnemonics.setLocalizedText(lUserPassword, org.openide.util.NbBundle.getMessage(AdvancedProxyPanel.class, "LBL_AdvancedProxyPanel_lUserPassword")); 246 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); 247 this.setLayout(layout); 248 layout.setHorizontalGroup( 249 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 250 .add(layout.createSequentialGroup() 251 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 252 .add(layout.createSequentialGroup() 253 .add(12, 12, 12) 254 .add(cbUseProxyAuthentication)) 255 .add(layout.createSequentialGroup() 256 .addContainerGap() 257 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 258 .add(lUserName) 259 .add(lUserPassword)) 260 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 261 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false) 262 .add(pfUserPassword) 263 .add(tfUserName, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 399, Short.MAX_VALUE))) 264 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) 265 .add(layout.createSequentialGroup() 266 .addContainerGap() 267 .add(sSeparator, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 414, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 268 .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup() 269 .add(12, 12, 12) 270 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 271 .add(lHttpProxyHost) 272 .add(lHttpsProxyHost) 273 .add(lSocksHost) 274 .add(lNonProxyHosts)) 275 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 276 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false) 277 .add(lNonProxyHostsDescription, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 349, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 278 .add(cbSameProxySettings, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 325, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 279 .add(layout.createSequentialGroup() 280 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false) 281 .add(org.jdesktop.layout.GroupLayout.LEADING, tfHttpProxyHost) 282 .add(org.jdesktop.layout.GroupLayout.LEADING, tfSocksHost) 283 .add(org.jdesktop.layout.GroupLayout.LEADING, tfHttpsProxyHost, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 281, Short.MAX_VALUE)) 284 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 285 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 286 .add(lHttpProxyPort) 287 .add(lHttpsProxyPort) 288 .add(lSocksPort)) 289 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 290 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false) 291 .add(tfHttpProxyPort) 292 .add(tfSocksPort) 293 .add(tfHttpsProxyPort))) 294 .add(tfNonProxyHosts))))) 295 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 296 ); 297 layout.setVerticalGroup( 298 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 299 .add(layout.createSequentialGroup() 300 .addContainerGap() 301 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 302 .add(lHttpProxyHost) 303 .add(tfHttpProxyHost, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 304 .add(lHttpProxyPort) 305 .add(tfHttpProxyPort, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 306 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 307 .add(cbSameProxySettings) 308 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 309 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 310 .add(lHttpsProxyHost) 311 .add(tfHttpsProxyHost, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 312 .add(lHttpsProxyPort) 313 .add(tfHttpsProxyPort, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 314 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 315 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 316 .add(lSocksHost) 317 .add(tfSocksHost, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 318 .add(lSocksPort) 319 .add(tfSocksPort, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 320 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 321 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 322 .add(lNonProxyHosts) 323 .add(tfNonProxyHosts, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 324 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 325 .add(lNonProxyHostsDescription) 326 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 327 .add(sSeparator, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 328 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 329 .add(cbUseProxyAuthentication) 330 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 331 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 332 .add(lUserName) 333 .add(tfUserName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 334 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 335 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 336 .add(lUserPassword) 337 .add(pfUserPassword, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 338 .addContainerGap(30, Short.MAX_VALUE)) 339 ); 340 341 tfHttpProxyHost.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(AdvancedProxyPanel.class, "ACD_AdvancedProxyPanel_tfHttpProxyHost")); cbSameProxySettings.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(AdvancedProxyPanel.class, "ACD_AdvancedProxyPanel_cbSameProxySettings")); tfHttpsProxyHost.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(AdvancedProxyPanel.class, "ACD_AdvancedProxyPanel_tfHttpsProxyHost")); tfSocksHost.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(AdvancedProxyPanel.class, "ACD_AdvancedProxyPanel_tfSocksHost")); tfHttpProxyPort.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(AdvancedProxyPanel.class, "ACD_AdvancedProxyPanel_tfHttpProxyPort")); tfHttpsProxyPort.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(AdvancedProxyPanel.class, "ACD_AdvancedProxyPanel_tfHttpsProxyPort")); tfSocksPort.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(AdvancedProxyPanel.class, "ACD_AdvancedProxyPanel_tfSocksPort")); tfNonProxyHosts.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(AdvancedProxyPanel.class, "ACD_AdvancedProxyPanel_tfNonProxyHosts")); cbUseProxyAuthentication.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(AdvancedProxyPanel.class, "ACD_AdvancedProxyPanel_cbUseProxyAuthentication")); tfUserName.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(AdvancedProxyPanel.class, "ACD_AdvancedProxyPanel_tfUserName")); pfUserPassword.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(AdvancedProxyPanel.class, "ACD_AdvancedProxyPanel_pfUserPassword")); 353 getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(AdvancedProxyPanel.class, "ACD_AdvancedProxyPanel")); } 356 private void cbUseProxyAuthenticationActionPerformed(java.awt.event.ActionEvent evt) { updateAuthentication (); 358 } 360 private void cbSameProxySettingsActionPerformed(java.awt.event.ActionEvent evt) { if (cbSameProxySettings.isSelected ()) { 362 oldHttpsHost = tfHttpsProxyHost.getText (); 363 oldHttpsPort = tfHttpsProxyPort.getText (); 364 oldSocksHost = tfSocksHost.getText (); 365 oldSocksPort = tfSocksPort.getText (); 366 } else { 367 tfHttpsProxyHost.setText (oldHttpsHost); 368 tfHttpsProxyPort.setText (oldHttpsPort); 369 tfSocksHost.setText (oldSocksHost); 370 tfSocksPort.setText (oldSocksPort); 371 } 372 followHttpProxyIfDemand (); 373 } 375 376 private javax.swing.JCheckBox cbSameProxySettings; 378 private javax.swing.JCheckBox cbUseProxyAuthentication; 379 private javax.swing.JLabel lHttpProxyHost; 380 private javax.swing.JLabel lHttpProxyPort; 381 private javax.swing.JLabel lHttpsProxyHost; 382 private javax.swing.JLabel lHttpsProxyPort; 383 private javax.swing.JLabel lNonProxyHosts; 384 private javax.swing.JLabel lNonProxyHostsDescription; 385 private javax.swing.JLabel lSocksHost; 386 private javax.swing.JLabel lSocksPort; 387 private javax.swing.JLabel lUserName; 388 private javax.swing.JLabel lUserPassword; 389 private javax.swing.JPasswordField pfUserPassword; 390 private javax.swing.JSeparator sSeparator; 391 private javax.swing.JTextField tfHttpProxyHost; 392 private javax.swing.JTextField tfHttpProxyPort; 393 private javax.swing.JTextField tfHttpsProxyHost; 394 private javax.swing.JTextField tfHttpsProxyPort; 395 private javax.swing.JTextField tfNonProxyHosts; 396 private javax.swing.JTextField tfSocksHost; 397 private javax.swing.JTextField tfSocksPort; 398 private javax.swing.JTextField tfUserName; 399 401 } 402 | Popular Tags |