1 package org.netbeans.modules.options.general; 2 20 21 import java.awt.Component ; 22 import java.awt.event.ActionEvent ; 23 import java.awt.event.ActionListener ; 24 import java.lang.reflect.Method ; 25 import java.util.logging.Level ; 26 import java.util.logging.Logger ; 27 import javax.swing.AbstractButton ; 28 import javax.swing.ButtonGroup ; 29 import javax.swing.DefaultComboBoxModel ; 30 import javax.swing.JLabel ; 31 import javax.swing.JPanel ; 32 import org.netbeans.beaninfo.editors.HtmlBrowser; 33 import org.openide.DialogDescriptor; 34 import org.openide.DialogDisplayer; 35 import org.openide.awt.Mnemonics; 36 import org.openide.util.Lookup; 37 import org.openide.util.NbBundle; 38 39 44 public class GeneralOptionsPanel extends JPanel implements ActionListener { 45 46 private boolean changed = false; 47 private GeneralOptionsModel model; 48 private HtmlBrowser.FactoryEditor editor; 49 private AdvancedProxyPanel advancedPanel; 50 51 52 55 public GeneralOptionsPanel () { 56 initComponents (); 57 58 cbCheckPeriod.setModel (new DefaultComboBoxModel (new String [] { 60 loc ("CTL_Update_every_startup"), 61 loc ("CTL_Update_every_day"), 62 loc ("CTL_Update_every_week"), 63 loc ("CTL_Update_every_2weeks"), 64 loc ("CTL_Update_every_month"), 65 loc ("CTL_Update_never") 66 })); 67 loc (lGeneral, "General"); 68 loc (lViewJavaPackagesAs, "Package_View_Type"); 69 loc (lWebBrowser, "Web_Browser"); 70 loc (lProxy, "Proxy_Settings"); 71 loc (lWebProxy, "Web_Proxy"); 72 loc (lProxyHost, "Proxy_Host"); 73 loc (lProxyPort, "Proxy_Port"); 74 loc (lAutoUpdate, "Auto_Update"); 75 loc (lCheckPeriod, "Check_Period"); 76 loc (lAskBeforeCheck, "Ask_Before_Check"); 77 78 79 80 cbWebBrowser.getAccessibleContext ().setAccessibleName (loc ("AN_Web_Browser")); 81 cbWebBrowser.getAccessibleContext ().setAccessibleDescription (loc ("AD_Web_Browser")); 82 tfProxyHost.getAccessibleContext ().setAccessibleName (loc ("AN_Host")); 83 tfProxyHost.getAccessibleContext ().setAccessibleDescription (loc ("AD_Host")); 84 tfProxyPort.getAccessibleContext ().setAccessibleName (loc ("AN_Port")); 85 tfProxyPort.getAccessibleContext ().setAccessibleDescription (loc ("AD_Port")); 86 cbCheckPeriod.getAccessibleContext ().setAccessibleName (loc ("AN_Update_Period")); 87 cbCheckPeriod.getAccessibleContext ().setAccessibleDescription (loc ("AD_Update_Period")); 88 cbAskBeforeCheck.getAccessibleContext ().setAccessibleName (loc ("AN_Ask_Before_Check")); 89 cbAskBeforeCheck.getAccessibleContext ().setAccessibleDescription (loc ("AD_Ask_Before_Check")); 90 rbNoProxy.addActionListener (this); 91 rbUseSystemProxy.addActionListener (this); 92 rbHTTPProxy.addActionListener (this); 93 rbList.addActionListener (this); 94 rbTree.addActionListener (this); 95 cbWebBrowser.addActionListener (this); 96 tfProxyHost.addActionListener (this); 97 tfProxyPort.addActionListener (this); 98 cbCheckPeriod.addActionListener (this); 99 cbAskBeforeCheck.addActionListener (this); 100 101 ButtonGroup bgPackages = new ButtonGroup (); 102 bgPackages.add (rbList); 103 bgPackages.add (rbTree); 104 loc (rbList, "Flattern_Packages"); 105 loc (rbTree, "Tree_Packages"); 106 ButtonGroup bgProxy = new ButtonGroup (); 107 bgProxy.add (rbNoProxy); 108 bgProxy.add (rbUseSystemProxy); 109 bgProxy.add (rbHTTPProxy); 110 loc (rbNoProxy, "No_Proxy"); 111 loc (rbUseSystemProxy, "Use_System_Proxy_Settings"); 112 loc (rbHTTPProxy, "Use_HTTP_Proxy"); 113 114 if (System.getProperty("netbeans.system_http_proxy") == null) rbUseSystemProxy.setEnabled(false); 118 } 119 120 125 private void initComponents() { 127 128 lGeneral = new javax.swing.JLabel (); 129 jSeparator1 = new javax.swing.JSeparator (); 130 lViewJavaPackagesAs = new javax.swing.JLabel (); 131 rbList = new javax.swing.JRadioButton (); 132 rbTree = new javax.swing.JRadioButton (); 133 lWebBrowser = new javax.swing.JLabel (); 134 cbWebBrowser = new javax.swing.JComboBox (); 135 lProxy = new javax.swing.JLabel (); 136 lAutoUpdate = new javax.swing.JLabel (); 137 lCheckPeriod = new javax.swing.JLabel (); 138 cbCheckPeriod = new javax.swing.JComboBox (); 139 lAskBeforeCheck = new javax.swing.JLabel (); 140 cbAskBeforeCheck = new javax.swing.JCheckBox (); 141 jSeparator3 = new javax.swing.JSeparator (); 142 jSeparator2 = new javax.swing.JSeparator (); 143 lWebProxy = new javax.swing.JLabel (); 144 rbNoProxy = new javax.swing.JRadioButton (); 145 rbUseSystemProxy = new javax.swing.JRadioButton (); 146 rbHTTPProxy = new javax.swing.JRadioButton (); 147 lProxyHost = new javax.swing.JLabel (); 148 tfProxyHost = new javax.swing.JTextField (); 149 lProxyPort = new javax.swing.JLabel (); 150 tfProxyPort = new javax.swing.JTextField (); 151 bMoreProxy = new javax.swing.JButton (); 152 153 org.openide.awt.Mnemonics.setLocalizedText(lGeneral, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "GeneralOptionsPanel.lGeneral.text")); 155 org.openide.awt.Mnemonics.setLocalizedText(lViewJavaPackagesAs, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "GeneralOptionsPanel.lViewJavaPackagesAs.text")); 157 org.openide.awt.Mnemonics.setLocalizedText(rbList, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "GeneralOptionsPanel.rbList.text")); rbList.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 159 rbList.setMargin(new java.awt.Insets (0, 0, 0, 0)); 160 161 org.openide.awt.Mnemonics.setLocalizedText(rbTree, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "GeneralOptionsPanel.rbTree.text")); rbTree.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 163 rbTree.setMargin(new java.awt.Insets (0, 0, 0, 0)); 164 165 lWebBrowser.setLabelFor(cbWebBrowser); 166 org.openide.awt.Mnemonics.setLocalizedText(lWebBrowser, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "GeneralOptionsPanel.lWebBrowser.text")); 168 org.openide.awt.Mnemonics.setLocalizedText(lProxy, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "GeneralOptionsPanel.lProxy.text")); 170 org.openide.awt.Mnemonics.setLocalizedText(lAutoUpdate, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "GeneralOptionsPanel.lAutoUpdate.text")); 172 lCheckPeriod.setLabelFor(cbCheckPeriod); 173 org.openide.awt.Mnemonics.setLocalizedText(lCheckPeriod, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "GeneralOptionsPanel.lCheckPeriod.text")); 175 lAskBeforeCheck.setLabelFor(cbAskBeforeCheck); 176 org.openide.awt.Mnemonics.setLocalizedText(lAskBeforeCheck, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "GeneralOptionsPanel.lAskBeforeCheck.text")); 178 cbAskBeforeCheck.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 179 cbAskBeforeCheck.setMargin(new java.awt.Insets (0, 0, 0, 0)); 180 181 org.openide.awt.Mnemonics.setLocalizedText(lWebProxy, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "LBL_GeneralOptionsPanel_lWebProxy")); 183 org.openide.awt.Mnemonics.setLocalizedText(rbNoProxy, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "GeneralOptionsPanel.rbNoProxy.text")); rbNoProxy.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 185 rbNoProxy.setMargin(new java.awt.Insets (0, 0, 0, 0)); 186 187 org.openide.awt.Mnemonics.setLocalizedText(rbUseSystemProxy, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "GeneralOptionsPanel.rbUseSystemProxy.text")); rbUseSystemProxy.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 189 rbUseSystemProxy.setMargin(new java.awt.Insets (0, 0, 0, 0)); 190 191 org.openide.awt.Mnemonics.setLocalizedText(rbHTTPProxy, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "CTL_Use_HTTP_Proxy", new Object [] {})); rbHTTPProxy.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 193 rbHTTPProxy.setMargin(new java.awt.Insets (0, 0, 0, 0)); 194 195 lProxyHost.setLabelFor(tfProxyHost); 196 org.openide.awt.Mnemonics.setLocalizedText(lProxyHost, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "CTL_Proxy_Host", new Object [] {})); 198 tfProxyHost.addFocusListener(new java.awt.event.FocusAdapter () { 199 public void focusGained(java.awt.event.FocusEvent evt) { 200 tfProxyHostFocusGained(evt); 201 } 202 public void focusLost(java.awt.event.FocusEvent evt) { 203 tfProxyHostFocusLost(evt); 204 } 205 }); 206 207 lProxyPort.setLabelFor(tfProxyPort); 208 org.openide.awt.Mnemonics.setLocalizedText(lProxyPort, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "CTL_Proxy_Port", new Object [] {})); 210 tfProxyPort.setColumns(4); 211 tfProxyPort.addFocusListener(new java.awt.event.FocusAdapter () { 212 public void focusGained(java.awt.event.FocusEvent evt) { 213 tfProxyPortFocusGained(evt); 214 } 215 public void focusLost(java.awt.event.FocusEvent evt) { 216 tfProxyPortFocusLost(evt); 217 } 218 }); 219 220 org.openide.awt.Mnemonics.setLocalizedText(bMoreProxy, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "LBL_GeneralOptionsPanel_bMoreProxy")); bMoreProxy.addActionListener(new java.awt.event.ActionListener () { 222 public void actionPerformed(java.awt.event.ActionEvent evt) { 223 bMoreProxyActionPerformed(evt); 224 } 225 }); 226 227 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); 228 this.setLayout(layout); 229 layout.setHorizontalGroup( 230 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 231 .add(layout.createSequentialGroup() 232 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 233 .add(layout.createSequentialGroup() 234 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 235 .add(layout.createSequentialGroup() 236 .add(12, 12, 12) 237 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 238 .add(lViewJavaPackagesAs) 239 .add(lWebBrowser))) 240 .add(layout.createSequentialGroup() 241 .addContainerGap() 242 .add(lWebProxy)) 243 .add(layout.createSequentialGroup() 244 .add(12, 12, 12) 245 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 246 .add(lCheckPeriod) 247 .add(lAskBeforeCheck)))) 248 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 249 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 250 .add(rbList) 251 .add(rbTree, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 420, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 252 .add(rbNoProxy) 253 .add(rbUseSystemProxy) 254 .add(rbHTTPProxy) 255 .add(cbAskBeforeCheck, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 256 .add(layout.createSequentialGroup() 257 .add(17, 17, 17) 258 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 259 .add(bMoreProxy) 260 .add(layout.createSequentialGroup() 261 .add(lProxyHost) 262 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 263 .add(tfProxyHost, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 261, Short.MAX_VALUE) 264 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 265 .add(lProxyPort) 266 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 267 .add(tfProxyPort, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))) 268 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)) 269 .add(cbWebBrowser, 0, 463, Short.MAX_VALUE) 270 .add(cbCheckPeriod, 0, 463, Short.MAX_VALUE))) 271 .add(layout.createSequentialGroup() 272 .add(lAutoUpdate) 273 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 274 .add(jSeparator3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 539, Short.MAX_VALUE)) 275 .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() 276 .add(lProxy) 277 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 278 .add(jSeparator2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 0, Short.MAX_VALUE)) 279 .add(layout.createSequentialGroup() 280 .add(lGeneral) 281 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 282 .add(jSeparator1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 570, Short.MAX_VALUE))) 283 .addContainerGap()) 284 ); 285 layout.setVerticalGroup( 286 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 287 .add(layout.createSequentialGroup() 288 .addContainerGap() 289 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) 290 .add(lGeneral) 291 .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 292 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 293 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 294 .add(lViewJavaPackagesAs) 295 .add(rbList)) 296 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 297 .add(rbTree) 298 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 299 .add(layout.createSequentialGroup() 300 .add(20, 20, 20) 301 .add(lWebBrowser)) 302 .add(layout.createSequentialGroup() 303 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 304 .add(cbWebBrowser, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))) 305 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 306 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 307 .add(lProxy) 308 .add(layout.createSequentialGroup() 309 .add(5, 5, 5) 310 .add(jSeparator2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))) 311 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 312 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 313 .add(lWebProxy) 314 .add(layout.createSequentialGroup() 315 .add(rbNoProxy) 316 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 317 .add(rbUseSystemProxy) 318 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 319 .add(rbHTTPProxy))) 320 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 321 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 322 .add(lProxyHost) 323 .add(tfProxyPort, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 324 .add(lProxyPort) 325 .add(tfProxyHost, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 326 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 327 .add(bMoreProxy) 328 .add(28, 28, 28) 329 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) 330 .add(lAutoUpdate) 331 .add(jSeparator3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 332 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 333 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) 334 .add(lCheckPeriod) 335 .add(cbCheckPeriod, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 336 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 337 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 338 .add(lAskBeforeCheck) 339 .add(cbAskBeforeCheck)) 340 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 341 ); 342 } 344 private void bMoreProxyActionPerformed(java.awt.event.ActionEvent evt) { assert model != null : "Model found when AdvancedProxyPanel is created"; 346 if (advancedPanel == null) { 347 advancedPanel = new AdvancedProxyPanel (model); 348 } 349 DialogDescriptor dd = new DialogDescriptor (advancedPanel, loc ("LBL_AdvancedProxyPanel_Title")); 350 advancedPanel.update (tfProxyHost.getText (), tfProxyPort.getText ()); 351 DialogDisplayer.getDefault ().createDialog (dd).setVisible (true); 352 if (DialogDescriptor.OK_OPTION.equals (dd.getValue ())) { 353 advancedPanel.applyChanges (); 354 tfProxyHost.setText (model.getHttpProxyHost ()); 355 tfProxyPort.setText (model.getHttpProxyPort ()); 356 isChanged (); 357 } 358 } 360 private void tfProxyPortFocusLost (java.awt.event.FocusEvent evt) { tfProxyPort.select (0, 0); 362 } 364 private void tfProxyHostFocusLost (java.awt.event.FocusEvent evt) { tfProxyHost.select (0, 0); 366 } 368 private void tfProxyPortFocusGained (java.awt.event.FocusEvent evt) { tfProxyPort.setCaretPosition (0); 370 tfProxyPort.selectAll (); 371 } 373 private void tfProxyHostFocusGained (java.awt.event.FocusEvent evt) { tfProxyHost.setCaretPosition (0); 375 tfProxyHost.selectAll (); 376 } 378 379 private javax.swing.JButton bMoreProxy; 381 private javax.swing.JCheckBox cbAskBeforeCheck; 382 private javax.swing.JComboBox cbCheckPeriod; 383 private javax.swing.JComboBox cbWebBrowser; 384 private javax.swing.JSeparator jSeparator1; 385 private javax.swing.JSeparator jSeparator2; 386 private javax.swing.JSeparator jSeparator3; 387 private javax.swing.JLabel lAskBeforeCheck; 388 private javax.swing.JLabel lAutoUpdate; 389 private javax.swing.JLabel lCheckPeriod; 390 private javax.swing.JLabel lGeneral; 391 private javax.swing.JLabel lProxy; 392 private javax.swing.JLabel lProxyHost; 393 private javax.swing.JLabel lProxyPort; 394 private javax.swing.JLabel lViewJavaPackagesAs; 395 private javax.swing.JLabel lWebBrowser; 396 private javax.swing.JLabel lWebProxy; 397 private javax.swing.JRadioButton rbHTTPProxy; 398 private javax.swing.JRadioButton rbList; 399 private javax.swing.JRadioButton rbNoProxy; 400 private javax.swing.JRadioButton rbTree; 401 private javax.swing.JRadioButton rbUseSystemProxy; 402 private javax.swing.JTextField tfProxyHost; 403 private javax.swing.JTextField tfProxyPort; 404 406 407 private static String loc (String key) { 408 return NbBundle.getMessage (GeneralOptionsPanel.class, key); 409 } 410 411 private static void loc (Component c, String key) { 412 if (!(c instanceof JLabel )) { 413 c.getAccessibleContext ().setAccessibleName (loc ("AN_" + key)); 414 c.getAccessibleContext ().setAccessibleDescription (loc ("AD_" + key)); 415 } 416 if (c instanceof AbstractButton ) { 417 Mnemonics.setLocalizedText ( 418 (AbstractButton ) c, 419 loc ("CTL_" + key) 420 ); 421 } else { 422 Mnemonics.setLocalizedText ( 423 (JLabel ) c, 424 loc ("CTL_" + key) 425 ); 426 } 427 } 428 429 void update () { 430 model = new GeneralOptionsModel (); 431 432 rbList.setSelected (true); 433 434 switch (model.getProxyType ()) { 436 case 0: 437 rbNoProxy.setSelected (true); 438 tfProxyHost.setEnabled (false); 439 tfProxyPort.setEnabled (false); 440 bMoreProxy.setEnabled (false); 441 break; 442 case 1: 443 rbUseSystemProxy.setSelected (true); 444 tfProxyHost.setEnabled (false); 445 tfProxyPort.setEnabled (false); 446 bMoreProxy.setEnabled (false); 447 break; 448 default: 449 rbHTTPProxy.setSelected (true); 450 tfProxyHost.setEnabled (true); 451 tfProxyPort.setEnabled (true); 452 bMoreProxy.setEnabled (true); 453 break; 454 } 455 tfProxyHost.setText (model.getHttpProxyHost ()); 456 tfProxyPort.setText (model.getHttpProxyPort ()); 457 458 cbAskBeforeCheck.setSelected (model.getAutoUpdateAskBeforeCheck ()); 460 cbCheckPeriod.setSelectedIndex (model.getAutoUpdatePeriod ()); 461 462 if (editor == null) { 464 editor = (HtmlBrowser.FactoryEditor)Lookup.getDefault().lookup(HtmlBrowser.FactoryEditor.class); 465 } 466 cbWebBrowser.removeAllItems (); 467 String [] tags = editor.getTags (); 468 int i, k = tags.length; 469 for (i = 0; i < k; i++) 470 cbWebBrowser.addItem (tags [i]); 471 cbWebBrowser.setSelectedItem (editor.getAsText ()); 472 473 ClassLoader classLoader = (ClassLoader ) Lookup.getDefault ().lookup 475 (ClassLoader .class); 476 try { 477 Class clazz = classLoader.loadClass 478 ("org.netbeans.modules.java.project.JavaProjectSettings"); 479 Method method = clazz.getMethod ("getPackageViewType", new Class [0]); 480 Integer integer = (Integer ) method.invoke(null, new Object [] {}); 481 if (integer.intValue () == 0) 482 rbList.setSelected (true); 483 else 484 rbTree.setSelected (true); 485 rbList.setEnabled(true); 486 rbTree.setEnabled(true); 487 lViewJavaPackagesAs.setEnabled(true); 488 } catch (ClassNotFoundException x) { 489 rbList.setSelected(false); 491 rbList.setEnabled(false); 492 rbTree.setSelected(false); 493 rbTree.setEnabled(false); 494 lViewJavaPackagesAs.setEnabled(false); 495 } catch (Exception ex) { 496 Logger.getLogger(GeneralOptionsPanel.class.getName()).log(Level.WARNING, null, ex); 497 } 498 changed = false; 499 } 500 501 void applyChanges () { 502 505 if (model == null) return; 506 507 if (rbNoProxy.isSelected ()) { 509 model.setProxyType (0); 510 } else 511 if (rbUseSystemProxy.isSelected ()) { 512 model.setProxyType (1); 513 } else { 514 model.setProxyType (2); 515 } 516 517 model.setHttpProxyHost (tfProxyHost.getText ()); 518 model.setHttpProxyPort (tfProxyPort.getText ()); 519 520 model.setAutoUpdateAskBeforeCheck (cbAskBeforeCheck.isSelected ()); 522 model.setAutoUpdatePeriod (cbCheckPeriod.getSelectedIndex ()); 523 524 if (editor == null) { 526 editor = (HtmlBrowser.FactoryEditor)Lookup.getDefault().lookup(HtmlBrowser.FactoryEditor.class); 527 } 528 editor.setAsText ((String ) cbWebBrowser.getSelectedItem ()); 529 ClassLoader classLoader = (ClassLoader ) Lookup.getDefault ().lookup 531 (ClassLoader .class); 532 try { 533 Class clazz = classLoader.loadClass 534 ("org.netbeans.modules.java.project.JavaProjectSettings"); 535 Method method = clazz.getMethod("setPackageViewType", new Class [] {Integer.TYPE}); 536 Integer integer = new Integer (1); 537 if (rbList.isSelected ()) 538 integer = new Integer (0); 539 method.invoke (null, new Object [] {integer}); 540 } catch (ClassNotFoundException x) { 541 } catch (Exception ex) { 543 Logger.getLogger(GeneralOptionsPanel.class.getName()).log(Level.WARNING, null, ex); 544 } 545 } 546 547 void cancel () { 548 } 549 550 boolean dataValid () { 551 return true; 552 } 553 554 boolean isChanged () { 555 if (model == null) return false; 556 if (!tfProxyHost.getText ().equals (model.getHttpProxyHost ())) return true; 557 if (!tfProxyPort.getText ().equals (model.getHttpProxyPort ())) return true; 558 return changed; 559 } 560 561 public void actionPerformed (ActionEvent e) { 562 changed = true; 563 tfProxyHost.setEnabled (rbHTTPProxy.isSelected ()); 564 tfProxyPort.setEnabled (rbHTTPProxy.isSelected ()); 565 bMoreProxy.setEnabled (rbHTTPProxy.isSelected ()); 566 } 567 } 568 | Popular Tags |