KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > options > general > GeneralOptionsPanel


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

20
21 import java.awt.Component JavaDoc;
22 import java.awt.event.ActionEvent JavaDoc;
23 import java.awt.event.ActionListener JavaDoc;
24 import java.lang.reflect.Method JavaDoc;
25 import java.util.logging.Level JavaDoc;
26 import java.util.logging.Logger JavaDoc;
27 import javax.swing.AbstractButton JavaDoc;
28 import javax.swing.ButtonGroup JavaDoc;
29 import javax.swing.DefaultComboBoxModel JavaDoc;
30 import javax.swing.JLabel JavaDoc;
31 import javax.swing.JPanel JavaDoc;
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 /**
40  * Implementation of one panel in Options Dialog.
41  *
42  * @author Jan Jancura
43  */

44 public class GeneralOptionsPanel extends JPanel JavaDoc implements ActionListener JavaDoc {
45     
46     private boolean changed = false;
47     private GeneralOptionsModel model;
48     private HtmlBrowser.FactoryEditor editor;
49     private AdvancedProxyPanel advancedPanel;
50
51     
52     /**
53      * Creates new form GeneralOptionsPanel.
54      */

55     public GeneralOptionsPanel () {
56         initComponents ();
57         
58         // localization
59
cbCheckPeriod.setModel (new DefaultComboBoxModel JavaDoc (new String JavaDoc [] {
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 JavaDoc bgPackages = new ButtonGroup JavaDoc ();
102         bgPackages.add (rbList);
103         bgPackages.add (rbTree);
104         loc (rbList, "Flattern_Packages");
105         loc (rbTree, "Tree_Packages");
106         ButtonGroup JavaDoc bgProxy = new ButtonGroup JavaDoc ();
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 proxy setting is not detectable, disable this radio
115
// button
116
if (System.getProperty("netbeans.system_http_proxy") == null) // NOI18N
117
rbUseSystemProxy.setEnabled(false);
118     }
119     
120     /** This method is called from within the constructor to
121      * initialize the form.
122      * WARNING: Do NOT modify this code. The content of this method is
123      * always regenerated by the Form Editor.
124      */

125     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
126
private void initComponents() {
127
128         lGeneral = new javax.swing.JLabel JavaDoc();
129         jSeparator1 = new javax.swing.JSeparator JavaDoc();
130         lViewJavaPackagesAs = new javax.swing.JLabel JavaDoc();
131         rbList = new javax.swing.JRadioButton JavaDoc();
132         rbTree = new javax.swing.JRadioButton JavaDoc();
133         lWebBrowser = new javax.swing.JLabel JavaDoc();
134         cbWebBrowser = new javax.swing.JComboBox JavaDoc();
135         lProxy = new javax.swing.JLabel JavaDoc();
136         lAutoUpdate = new javax.swing.JLabel JavaDoc();
137         lCheckPeriod = new javax.swing.JLabel JavaDoc();
138         cbCheckPeriod = new javax.swing.JComboBox JavaDoc();
139         lAskBeforeCheck = new javax.swing.JLabel JavaDoc();
140         cbAskBeforeCheck = new javax.swing.JCheckBox JavaDoc();
141         jSeparator3 = new javax.swing.JSeparator JavaDoc();
142         jSeparator2 = new javax.swing.JSeparator JavaDoc();
143         lWebProxy = new javax.swing.JLabel JavaDoc();
144         rbNoProxy = new javax.swing.JRadioButton JavaDoc();
145         rbUseSystemProxy = new javax.swing.JRadioButton JavaDoc();
146         rbHTTPProxy = new javax.swing.JRadioButton JavaDoc();
147         lProxyHost = new javax.swing.JLabel JavaDoc();
148         tfProxyHost = new javax.swing.JTextField JavaDoc();
149         lProxyPort = new javax.swing.JLabel JavaDoc();
150         tfProxyPort = new javax.swing.JTextField JavaDoc();
151         bMoreProxy = new javax.swing.JButton JavaDoc();
152
153         org.openide.awt.Mnemonics.setLocalizedText(lGeneral, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "GeneralOptionsPanel.lGeneral.text")); // NOI18N
154

155         org.openide.awt.Mnemonics.setLocalizedText(lViewJavaPackagesAs, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "GeneralOptionsPanel.lViewJavaPackagesAs.text")); // NOI18N
156

157         org.openide.awt.Mnemonics.setLocalizedText(rbList, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "GeneralOptionsPanel.rbList.text")); // NOI18N
158
rbList.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
159         rbList.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
160
161         org.openide.awt.Mnemonics.setLocalizedText(rbTree, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "GeneralOptionsPanel.rbTree.text")); // NOI18N
162
rbTree.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
163         rbTree.setMargin(new java.awt.Insets JavaDoc(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")); // NOI18N
167

168         org.openide.awt.Mnemonics.setLocalizedText(lProxy, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "GeneralOptionsPanel.lProxy.text")); // NOI18N
169

170         org.openide.awt.Mnemonics.setLocalizedText(lAutoUpdate, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "GeneralOptionsPanel.lAutoUpdate.text")); // NOI18N
171

172         lCheckPeriod.setLabelFor(cbCheckPeriod);
173         org.openide.awt.Mnemonics.setLocalizedText(lCheckPeriod, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "GeneralOptionsPanel.lCheckPeriod.text")); // NOI18N
174

175         lAskBeforeCheck.setLabelFor(cbAskBeforeCheck);
176         org.openide.awt.Mnemonics.setLocalizedText(lAskBeforeCheck, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "GeneralOptionsPanel.lAskBeforeCheck.text")); // NOI18N
177

178         cbAskBeforeCheck.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
179         cbAskBeforeCheck.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
180
181         org.openide.awt.Mnemonics.setLocalizedText(lWebProxy, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "LBL_GeneralOptionsPanel_lWebProxy")); // NOI18N
182

183         org.openide.awt.Mnemonics.setLocalizedText(rbNoProxy, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "GeneralOptionsPanel.rbNoProxy.text")); // NOI18N
184
rbNoProxy.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
185         rbNoProxy.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
186
187         org.openide.awt.Mnemonics.setLocalizedText(rbUseSystemProxy, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "GeneralOptionsPanel.rbUseSystemProxy.text")); // NOI18N
188
rbUseSystemProxy.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
189         rbUseSystemProxy.setMargin(new java.awt.Insets JavaDoc(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 JavaDoc[] {})); // NOI18N
192
rbHTTPProxy.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
193         rbHTTPProxy.setMargin(new java.awt.Insets JavaDoc(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 JavaDoc[] {})); // NOI18N
197

198         tfProxyHost.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
199             public void focusGained(java.awt.event.FocusEvent JavaDoc evt) {
200                 tfProxyHostFocusGained(evt);
201             }
202             public void focusLost(java.awt.event.FocusEvent JavaDoc 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 JavaDoc[] {})); // NOI18N
209

210         tfProxyPort.setColumns(4);
211         tfProxyPort.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
212             public void focusGained(java.awt.event.FocusEvent JavaDoc evt) {
213                 tfProxyPortFocusGained(evt);
214             }
215             public void focusLost(java.awt.event.FocusEvent JavaDoc evt) {
216                 tfProxyPortFocusLost(evt);
217             }
218         });
219
220         org.openide.awt.Mnemonics.setLocalizedText(bMoreProxy, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "LBL_GeneralOptionsPanel_bMoreProxy")); // NOI18N
221
bMoreProxy.addActionListener(new java.awt.event.ActionListener JavaDoc() {
222             public void actionPerformed(java.awt.event.ActionEvent JavaDoc 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     }// </editor-fold>//GEN-END:initComponents
343

344 private void bMoreProxyActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_bMoreProxyActionPerformed
345
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 }//GEN-LAST:event_bMoreProxyActionPerformed
359

360     private void tfProxyPortFocusLost (java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_tfProxyPortFocusLost
361
tfProxyPort.select (0, 0);
362     }//GEN-LAST:event_tfProxyPortFocusLost
363

364     private void tfProxyHostFocusLost (java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_tfProxyHostFocusLost
365
tfProxyHost.select (0, 0);
366     }//GEN-LAST:event_tfProxyHostFocusLost
367

368     private void tfProxyPortFocusGained (java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_tfProxyPortFocusGained
369
tfProxyPort.setCaretPosition (0);
370         tfProxyPort.selectAll ();
371     }//GEN-LAST:event_tfProxyPortFocusGained
372

373     private void tfProxyHostFocusGained (java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_tfProxyHostFocusGained
374
tfProxyHost.setCaretPosition (0);
375         tfProxyHost.selectAll ();
376     }//GEN-LAST:event_tfProxyHostFocusGained
377

378     
379     // Variables declaration - do not modify//GEN-BEGIN:variables
380
private javax.swing.JButton JavaDoc bMoreProxy;
381     private javax.swing.JCheckBox JavaDoc cbAskBeforeCheck;
382     private javax.swing.JComboBox JavaDoc cbCheckPeriod;
383     private javax.swing.JComboBox JavaDoc cbWebBrowser;
384     private javax.swing.JSeparator JavaDoc jSeparator1;
385     private javax.swing.JSeparator JavaDoc jSeparator2;
386     private javax.swing.JSeparator JavaDoc jSeparator3;
387     private javax.swing.JLabel JavaDoc lAskBeforeCheck;
388     private javax.swing.JLabel JavaDoc lAutoUpdate;
389     private javax.swing.JLabel JavaDoc lCheckPeriod;
390     private javax.swing.JLabel JavaDoc lGeneral;
391     private javax.swing.JLabel JavaDoc lProxy;
392     private javax.swing.JLabel JavaDoc lProxyHost;
393     private javax.swing.JLabel JavaDoc lProxyPort;
394     private javax.swing.JLabel JavaDoc lViewJavaPackagesAs;
395     private javax.swing.JLabel JavaDoc lWebBrowser;
396     private javax.swing.JLabel JavaDoc lWebProxy;
397     private javax.swing.JRadioButton JavaDoc rbHTTPProxy;
398     private javax.swing.JRadioButton JavaDoc rbList;
399     private javax.swing.JRadioButton JavaDoc rbNoProxy;
400     private javax.swing.JRadioButton JavaDoc rbTree;
401     private javax.swing.JRadioButton JavaDoc rbUseSystemProxy;
402     private javax.swing.JTextField JavaDoc tfProxyHost;
403     private javax.swing.JTextField JavaDoc tfProxyPort;
404     // End of variables declaration//GEN-END:variables
405

406     
407     private static String JavaDoc loc (String JavaDoc key) {
408         return NbBundle.getMessage (GeneralOptionsPanel.class, key);
409     }
410     
411     private static void loc (Component JavaDoc c, String JavaDoc key) {
412         if (!(c instanceof JLabel JavaDoc)) {
413             c.getAccessibleContext ().setAccessibleName (loc ("AN_" + key));
414             c.getAccessibleContext ().setAccessibleDescription (loc ("AD_" + key));
415         }
416         if (c instanceof AbstractButton JavaDoc) {
417             Mnemonics.setLocalizedText (
418                 (AbstractButton JavaDoc) c,
419                 loc ("CTL_" + key)
420             );
421         } else {
422             Mnemonics.setLocalizedText (
423                 (JLabel JavaDoc) c,
424                 loc ("CTL_" + key)
425             );
426         }
427     }
428     
429     void update () {
430         model = new GeneralOptionsModel ();
431         
432         rbList.setSelected (true);
433         
434         // proxy settings
435
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         // Autoupdate settings
459
cbAskBeforeCheck.setSelected (model.getAutoUpdateAskBeforeCheck ());
460         cbCheckPeriod.setSelectedIndex (model.getAutoUpdatePeriod ());
461         
462         // web browser settings
463
if (editor == null) {
464             editor = (HtmlBrowser.FactoryEditor)Lookup.getDefault().lookup(HtmlBrowser.FactoryEditor.class);
465         }
466         cbWebBrowser.removeAllItems ();
467         String JavaDoc[] 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         // package view settings
474
ClassLoader JavaDoc classLoader = (ClassLoader JavaDoc) Lookup.getDefault ().lookup
475             (ClassLoader JavaDoc.class);
476         try {
477             Class JavaDoc clazz = classLoader.loadClass
478                 ("org.netbeans.modules.java.project.JavaProjectSettings");
479             Method JavaDoc method = clazz.getMethod ("getPackageViewType", new Class JavaDoc[0]);
480             Integer JavaDoc integer = (Integer JavaDoc) method.invoke(null, new Object JavaDoc[] {});
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 JavaDoc x) {
489             // ignore, module not installed
490
rbList.setSelected(false);
491             rbList.setEnabled(false);
492             rbTree.setSelected(false);
493             rbTree.setEnabled(false);
494             lViewJavaPackagesAs.setEnabled(false);
495         } catch (Exception JavaDoc ex) {
496             Logger.getLogger(GeneralOptionsPanel.class.getName()).log(Level.WARNING, null, ex);
497         }
498         changed = false;
499     }
500     
501     void applyChanges () {
502         // listening on JTextFields dont work!
503
// if (!changed) return;
504

505         if (model == null) return;
506         
507         // proxy settings
508
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         // Autoupdate settings
521
model.setAutoUpdateAskBeforeCheck (cbAskBeforeCheck.isSelected ());
522         model.setAutoUpdatePeriod (cbCheckPeriod.getSelectedIndex ());
523         
524         // web browser settings
525
if (editor == null) {
526             editor = (HtmlBrowser.FactoryEditor)Lookup.getDefault().lookup(HtmlBrowser.FactoryEditor.class);
527         }
528         editor.setAsText ((String JavaDoc) cbWebBrowser.getSelectedItem ());
529         // package view settings
530
ClassLoader JavaDoc classLoader = (ClassLoader JavaDoc) Lookup.getDefault ().lookup
531             (ClassLoader JavaDoc.class);
532         try {
533             Class JavaDoc clazz = classLoader.loadClass
534                 ("org.netbeans.modules.java.project.JavaProjectSettings");
535             Method JavaDoc method = clazz.getMethod("setPackageViewType", new Class JavaDoc [] {Integer.TYPE});
536             Integer JavaDoc integer = new Integer JavaDoc (1);
537             if (rbList.isSelected ())
538                 integer = new Integer JavaDoc (0);
539             method.invoke (null, new Object JavaDoc[] {integer});
540         } catch (ClassNotFoundException JavaDoc x) {
541             // ignore, module not installed
542
} catch (Exception JavaDoc 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 JavaDoc e) {
562         changed = true;
563         tfProxyHost.setEnabled (rbHTTPProxy.isSelected ());
564         tfProxyPort.setEnabled (rbHTTPProxy.isSelected ());
565         bMoreProxy.setEnabled (rbHTTPProxy.isSelected ());
566     }
567 }
568
Popular Tags