KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > options > generaleditor > GeneralEditorPanel


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.options.generaleditor;
21
22 import java.awt.Component JavaDoc;
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.awt.event.ActionListener JavaDoc;
25 import javax.swing.AbstractButton JavaDoc;
26 import javax.swing.JLabel JavaDoc;
27 import javax.swing.JPanel JavaDoc;
28 import org.openide.awt.Mnemonics;
29 import org.openide.util.NbBundle;
30
31 /**
32  * Implementation of one panel in Options Dialog.
33  *
34  * @author Jan Jancura
35  */

36 public class GeneralEditorPanel extends JPanel JavaDoc implements ActionListener JavaDoc {
37
38     private boolean changed = false;
39     private boolean listen = false;
40     
41     /**
42      * Creates new form GeneralEditorPanel.
43      */

44     public GeneralEditorPanel () {
45         initComponents ();
46         
47         loc (lCodeFolding, "Code_Folding");
48         loc (lUseCodeFolding, "Code_Folding_Section");
49         loc (lCollapseByDefault, "Fold_by_Default");
50         loc (lCodeCompletion, "Code_Completion");
51         loc (lCodeCompletion2, "Code_Completion_Section");
52             
53         loc (cbUseCodeFolding, "Use_Folding");
54         loc (cbFoldMethods, "Fold_Methods");
55         loc (cbFoldInnerClasses, "Fold_Classes");
56         loc (cbFoldImports, "Fold_Imports");
57         loc (cbFoldJavadocComments, "Fold_JavaDoc");
58         loc (cbFoldInitialComments, "Fold_Licence");
59
60         loc (cbAutoPopup, "Auto_Popup_Completion_Window");
61         loc (cbInsertSingleProposalsAutomatically, "Insert_Single_Proposals_Automatically");
62         loc (cbCaseSensitive, "Case_Sensitive_Code_Completion");
63         loc (cbShowDeprecated, "Show_Deprecated_Members");
64         loc (cbInsertClosingBracketsAutomatically, "Pair_Character_Completion");
65     }
66     
67     /** This method is called from within the constructor to
68      * initialize the form.
69      * WARNING: Do NOT modify this code. The content of this method is
70      * always regenerated by the Form Editor.
71      */

72     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
73
private void initComponents() {
74         lCodeFolding = new javax.swing.JLabel JavaDoc();
75         lUseCodeFolding = new javax.swing.JLabel JavaDoc();
76         lCollapseByDefault = new javax.swing.JLabel JavaDoc();
77         cbUseCodeFolding = new javax.swing.JCheckBox JavaDoc();
78         cbFoldMethods = new javax.swing.JCheckBox JavaDoc();
79         cbFoldInnerClasses = new javax.swing.JCheckBox JavaDoc();
80         cbFoldImports = new javax.swing.JCheckBox JavaDoc();
81         cbFoldJavadocComments = new javax.swing.JCheckBox JavaDoc();
82         cbFoldInitialComments = new javax.swing.JCheckBox JavaDoc();
83         lCodeCompletion = new javax.swing.JLabel JavaDoc();
84         jSeparator2 = new javax.swing.JSeparator JavaDoc();
85         lCodeCompletion2 = new javax.swing.JLabel JavaDoc();
86         cbAutoPopup = new javax.swing.JCheckBox JavaDoc();
87         cbInsertSingleProposalsAutomatically = new javax.swing.JCheckBox JavaDoc();
88         cbCaseSensitive = new javax.swing.JCheckBox JavaDoc();
89         cbShowDeprecated = new javax.swing.JCheckBox JavaDoc();
90         cbInsertClosingBracketsAutomatically = new javax.swing.JCheckBox JavaDoc();
91         jSeparator1 = new javax.swing.JSeparator JavaDoc();
92
93         lCodeFolding.setText("Code Folding");
94
95         lUseCodeFolding.setText("Use Code Folding:");
96
97         lCollapseByDefault.setText("Collapse by Default:");
98
99         cbUseCodeFolding.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
100         cbUseCodeFolding.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
101
102         cbFoldMethods.setText("Methods");
103         cbFoldMethods.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
104         cbFoldMethods.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
105
106         cbFoldInnerClasses.setText("Inner Classes");
107         cbFoldInnerClasses.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
108         cbFoldInnerClasses.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
109
110         cbFoldImports.setText("Imports");
111         cbFoldImports.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
112         cbFoldImports.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
113
114         cbFoldJavadocComments.setText("Javadoc Comments");
115         cbFoldJavadocComments.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
116         cbFoldJavadocComments.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
117
118         cbFoldInitialComments.setText("Initial Comments");
119         cbFoldInitialComments.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
120         cbFoldInitialComments.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
121
122         lCodeCompletion.setText("Code Completion");
123
124         lCodeCompletion2.setText("Code Completion:");
125
126         cbAutoPopup.setText("Auto Popup Code Completion Window");
127         cbAutoPopup.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
128         cbAutoPopup.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
129
130         cbInsertSingleProposalsAutomatically.setText("Insert Single Proposals Automatically");
131         cbInsertSingleProposalsAutomatically.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
132         cbInsertSingleProposalsAutomatically.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
133
134         cbCaseSensitive.setText("Case Sensitive Code Completion");
135         cbCaseSensitive.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
136         cbCaseSensitive.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
137
138         cbShowDeprecated.setText("Show Deprecated Members In Code Completion");
139         cbShowDeprecated.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
140         cbShowDeprecated.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
141
142         cbInsertClosingBracketsAutomatically.setText("Insert Closing Brackets Automatically");
143         cbInsertClosingBracketsAutomatically.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
144         cbInsertClosingBracketsAutomatically.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
145
146         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
147         this.setLayout(layout);
148         layout.setHorizontalGroup(
149             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
150             .add(layout.createSequentialGroup()
151                 .addContainerGap()
152                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
153                     .add(lUseCodeFolding)
154                     .add(lCodeCompletion2)
155                     .add(lCollapseByDefault))
156                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
157                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
158                     .add(cbUseCodeFolding)
159                     .add(cbFoldMethods)
160                     .add(cbFoldInnerClasses)
161                     .add(cbFoldImports)
162                     .add(cbFoldJavadocComments)
163                     .add(cbFoldInitialComments)
164                     .add(cbAutoPopup)
165                     .add(cbInsertSingleProposalsAutomatically)
166                     .add(cbCaseSensitive)
167                     .add(cbShowDeprecated)
168                     .add(cbInsertClosingBracketsAutomatically))
169                 .addContainerGap())
170             .add(layout.createSequentialGroup()
171                 .add(lCodeCompletion)
172                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
173                 .add(jSeparator2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 392, Short.MAX_VALUE))
174             .add(layout.createSequentialGroup()
175                 .add(lCodeFolding)
176                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
177                 .add(jSeparator1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 411, Short.MAX_VALUE))
178         );
179         layout.setVerticalGroup(
180             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
181             .add(layout.createSequentialGroup()
182                 .addContainerGap()
183                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
184                     .add(lCodeFolding)
185                     .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
186                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
187                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
188                     .add(lUseCodeFolding)
189                     .add(cbUseCodeFolding))
190                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
191                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
192                     .add(lCollapseByDefault)
193                     .add(cbFoldMethods))
194                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
195                 .add(cbFoldInnerClasses)
196                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
197                 .add(cbFoldImports)
198                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
199                 .add(cbFoldJavadocComments)
200                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
201                 .add(cbFoldInitialComments)
202                 .add(8, 8, 8)
203                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
204                     .add(lCodeCompletion)
205                     .add(jSeparator2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
206                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
207                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
208                     .add(lCodeCompletion2)
209                     .add(cbAutoPopup))
210                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
211                 .add(cbInsertSingleProposalsAutomatically)
212                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
213                 .add(cbCaseSensitive)
214                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
215                 .add(cbShowDeprecated)
216                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
217                 .add(cbInsertClosingBracketsAutomatically)
218                 .addContainerGap(73, Short.MAX_VALUE))
219         );
220     }// </editor-fold>//GEN-END:initComponents
221

222     
223     // Variables declaration - do not modify//GEN-BEGIN:variables
224
private javax.swing.JCheckBox JavaDoc cbAutoPopup;
225     private javax.swing.JCheckBox JavaDoc cbCaseSensitive;
226     private javax.swing.JCheckBox JavaDoc cbFoldImports;
227     private javax.swing.JCheckBox JavaDoc cbFoldInitialComments;
228     private javax.swing.JCheckBox JavaDoc cbFoldInnerClasses;
229     private javax.swing.JCheckBox JavaDoc cbFoldJavadocComments;
230     private javax.swing.JCheckBox JavaDoc cbFoldMethods;
231     private javax.swing.JCheckBox JavaDoc cbInsertClosingBracketsAutomatically;
232     private javax.swing.JCheckBox JavaDoc cbInsertSingleProposalsAutomatically;
233     private javax.swing.JCheckBox JavaDoc cbShowDeprecated;
234     private javax.swing.JCheckBox JavaDoc cbUseCodeFolding;
235     private javax.swing.JSeparator JavaDoc jSeparator1;
236     private javax.swing.JSeparator JavaDoc jSeparator2;
237     private javax.swing.JLabel JavaDoc lCodeCompletion;
238     private javax.swing.JLabel JavaDoc lCodeCompletion2;
239     private javax.swing.JLabel JavaDoc lCodeFolding;
240     private javax.swing.JLabel JavaDoc lCollapseByDefault;
241     private javax.swing.JLabel JavaDoc lUseCodeFolding;
242     // End of variables declaration//GEN-END:variables
243

244     
245     private static String JavaDoc loc (String JavaDoc key) {
246         return NbBundle.getMessage (GeneralEditorPanel.class, key);
247     }
248     
249     private static void loc (Component JavaDoc c, String JavaDoc key) {
250         if (!(c instanceof JLabel JavaDoc)) {
251             c.getAccessibleContext ().setAccessibleName (loc ("AN_" + key));
252             c.getAccessibleContext ().setAccessibleDescription (loc ("AD_" + key));
253         }
254         if (c instanceof AbstractButton JavaDoc) {
255             Mnemonics.setLocalizedText (
256                 (AbstractButton JavaDoc) c,
257                 loc ("CTL_" + key)
258             );
259         } else {
260             Mnemonics.setLocalizedText (
261                 (JLabel JavaDoc) c,
262                 loc ("CTL_" + key)
263             );
264         }
265     }
266     
267     private Model model;
268     
269     void update () {
270         listen = false;
271         if (model == null) {
272             model = new Model ();
273             cbUseCodeFolding.addActionListener (this);
274             cbFoldMethods.addActionListener (this);
275             cbFoldInnerClasses.addActionListener (this);
276             cbFoldImports.addActionListener (this);
277             cbFoldJavadocComments.addActionListener (this);
278             cbFoldInitialComments.addActionListener (this);
279             cbAutoPopup.addActionListener (this);
280             cbInsertSingleProposalsAutomatically.addActionListener (this);
281             cbCaseSensitive.addActionListener (this);
282             cbShowDeprecated.addActionListener (this);
283             cbInsertClosingBracketsAutomatically.addActionListener (this);
284         }
285         
286         // init code folding
287
cbUseCodeFolding.setSelected (model.isShowCodeFolding ());
288         cbFoldImports.setSelected (model.isFoldImports ());
289         cbFoldInitialComments.setSelected (model.isFoldInitialComment ());
290         cbFoldInnerClasses.setSelected (model.isFoldInnerClasses ());
291         cbFoldJavadocComments.setSelected (model.isFoldJavaDocComments ());
292         cbFoldMethods.setSelected (model.isFoldMethods ());
293         updateEnabledState ();
294         
295         // code completion options
296
cbInsertClosingBracketsAutomatically.setSelected
297             (model.isPairCharacterCompletion ());
298         cbAutoPopup.setSelected
299             (model.isCompletionAutoPopup ());
300         cbShowDeprecated.setSelected
301             (model.isShowDeprecatedMembers ());
302         cbInsertSingleProposalsAutomatically.setSelected
303             (model.isCompletionInstantSubstitution ());
304         cbCaseSensitive.setSelected
305             (model.isCompletionCaseSensitive ());
306         
307         listen = true;
308     }
309     
310     void applyChanges () {
311         
312         if (model == null) return;
313         // code folding options
314
model.setFoldingOptions (
315             cbUseCodeFolding.isSelected (),
316             cbFoldImports.isSelected (),
317             cbFoldInitialComments.isSelected (),
318             cbFoldInnerClasses.isSelected (),
319             cbFoldJavadocComments.isSelected (),
320             cbFoldMethods.isSelected ()
321         );
322         
323         // code completion options
324
model.setCompletionOptions (
325             cbInsertClosingBracketsAutomatically.isSelected (),
326             cbAutoPopup.isSelected (),
327             cbShowDeprecated.isSelected (),
328             cbInsertSingleProposalsAutomatically.isSelected (),
329             cbCaseSensitive.isSelected ()
330         );
331         changed = false;
332     }
333     
334     void cancel () {
335         changed = false;
336     }
337     
338     boolean dataValid () {
339         return true;
340     }
341     
342     boolean isChanged () {
343         return changed;
344     }
345     
346     public void actionPerformed (ActionEvent JavaDoc e) {
347         if (!listen) return;
348         if (e.getSource () == cbUseCodeFolding)
349             updateEnabledState ();
350         changed = true;
351     }
352     
353     
354     // other methods ...........................................................
355

356     private void updateEnabledState () {
357         boolean useCodeFolding = cbUseCodeFolding.isSelected ();
358         cbFoldImports.setEnabled (useCodeFolding);
359         cbFoldInitialComments.setEnabled (useCodeFolding);
360         cbFoldInnerClasses.setEnabled (useCodeFolding);
361         cbFoldJavadocComments.setEnabled (useCodeFolding);
362         cbFoldMethods.setEnabled (useCodeFolding);
363     }
364 }
365
Popular Tags