KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > form > FormEditorCustomizer


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.form;
21
22 import java.lang.reflect.Modifier JavaDoc;
23 import java.awt.Color JavaDoc;
24 import java.awt.Component JavaDoc;
25 import java.awt.event.ActionEvent JavaDoc;
26 import java.awt.event.ActionListener JavaDoc;
27 import javax.swing.AbstractButton JavaDoc;
28 import javax.swing.ButtonGroup JavaDoc;
29 import javax.swing.JCheckBox JavaDoc;
30 import javax.swing.JComboBox JavaDoc;
31 import javax.swing.JLabel JavaDoc;
32 import javax.swing.JPanel JavaDoc;
33 import javax.swing.JRadioButton JavaDoc;
34 import javax.swing.border.TitledBorder JavaDoc;
35 import javax.swing.event.ChangeEvent JavaDoc;
36 import javax.swing.event.ChangeListener JavaDoc;
37
38 import org.jdesktop.layout.GroupLayout;
39 import org.jdesktop.layout.LayoutStyle;
40 import org.openide.awt.Mnemonics;
41 import org.openide.util.NbBundle;
42
43 /**
44  * Implementation of one panel in Options Dialog.
45  *
46  * @author Jan Stola, Jan Jancura
47  */

48 public final class FormEditorCustomizer extends JPanel JavaDoc implements ActionListener JavaDoc, ChangeListener JavaDoc {
49     private JCheckBox JavaDoc cbFold = new JCheckBox JavaDoc ();
50     private JCheckBox JavaDoc cbAssistant = new JCheckBox JavaDoc();
51     private JComboBox JavaDoc cbModifier = new JComboBox JavaDoc ();
52     private JRadioButton JavaDoc rbGenerateLocals = new JRadioButton JavaDoc ();
53     private JRadioButton JavaDoc rbGenerateFields = new JRadioButton JavaDoc ();
54     private JComboBox JavaDoc cbListenerStyle = new JComboBox JavaDoc ();
55     private JComboBox JavaDoc cbAutoI18n = new JComboBox JavaDoc();
56
57     private boolean changed = false;
58     private boolean listen = false;
59
60     public FormEditorCustomizer () {
61         ButtonGroup JavaDoc group = new ButtonGroup JavaDoc ();
62         loc(cbFold, "Fold"); // NOI18N
63
cbFold.setBackground (Color.white);
64         loc(cbAssistant, "Assistant"); // NOI18N
65
cbAssistant.setBackground(Color.white);
66         loc(rbGenerateLocals, "Generate_Locals"); // NOI18N
67
rbGenerateLocals.setBackground (Color.white);
68         group.add (rbGenerateLocals);
69         loc(rbGenerateFields, "Generate_Fields"); // NOI18N
70
rbGenerateFields.setBackground (Color.white);
71         group.add (rbGenerateFields);
72         cbModifier.addItem(loc("Public_Modifier")); // NOI18N
73
cbModifier.addItem(loc("Default_Modifier")); // NOI18N
74
cbModifier.addItem(loc("Protected_Modifier")); // NOI18N
75
cbModifier.addItem(loc("Private_Modifier")); // NOI18N
76
cbListenerStyle.addItem(loc("Anonymous")); // NOI18N
77
cbListenerStyle.addItem(loc("InnerClass")); // NOI18N
78
cbListenerStyle.addItem(loc("MainClass")); // NOI18N
79
cbAutoI18n.addItem(loc("CTL_AUTO_I18N_DEFAULT")); // NOI18N
80
cbAutoI18n.addItem(loc("CTL_AUTO_I18N_ON")); // NOI18N
81
cbAutoI18n.addItem(loc("CTL_AUTO_I18N_OFF")); // NOI18N
82

83         JLabel JavaDoc generateComponetsLabel = new JLabel JavaDoc(loc("Generate_Components")); // NOI18N
84
JLabel JavaDoc variableModifierLabel = new JLabel JavaDoc(loc("Variable_Modifier")); // NOI18N
85
JLabel JavaDoc listenerStyleLabel = new JLabel JavaDoc(loc("Listener_Style")); // NOI18N
86
JLabel JavaDoc autoI18nLabel = new JLabel JavaDoc(loc("Auto_I18n")); // NOI18N
87

88         generateComponetsLabel.setToolTipText(loc("Generate_Components_Hint")); // NOI18N
89
variableModifierLabel.setToolTipText(loc("HINT_VARIABLES_MODIFIER")); // NOI18N
90
listenerStyleLabel.setToolTipText(loc("HINT_LISTENER_GENERATION_STYLE")); // NOI18N
91
autoI18nLabel.setToolTipText(loc("HINT_AUTO_I18N_GLOBAL")); // NOI18N
92
cbFold.setToolTipText(loc("HINT_FOLD_GENERATED_CODE")); // NOI18N
93
cbAssistant.setToolTipText(loc("HINT_ASSISTANT_SHOWN")); // NOI18N
94

95         variableModifierLabel.setLabelFor(cbModifier);
96         listenerStyleLabel.setLabelFor(cbListenerStyle);
97         autoI18nLabel.setLabelFor(cbAutoI18n);
98
99         GroupLayout layout = new GroupLayout(this);
100         setLayout(layout);
101         layout.setHorizontalGroup(
102             layout.createSequentialGroup()
103                 .addContainerGap()
104                 .add(layout.createParallelGroup(GroupLayout.LEADING)
105                     .add(generateComponetsLabel)
106                     .add(variableModifierLabel)
107                     .add(listenerStyleLabel)
108                     .add(autoI18nLabel))
109                 .addPreferredGap(LayoutStyle.RELATED)
110                 .add(layout.createParallelGroup(GroupLayout.LEADING, false)
111                     .add(rbGenerateLocals)
112                     .add(rbGenerateFields)
113                     .add(cbFold)
114                     .add(cbAssistant)
115                     .add(cbModifier, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
116                     .add(cbListenerStyle, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
117                     .add(cbAutoI18n, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
118                 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
119         );
120         layout.setVerticalGroup(
121             layout.createSequentialGroup()
122                 .addContainerGap()
123                 .add(layout.createParallelGroup(GroupLayout.BASELINE)
124                     .add(generateComponetsLabel)
125                     .add(rbGenerateLocals))
126                 .addPreferredGap(LayoutStyle.RELATED)
127                 .add(rbGenerateFields)
128                 .addPreferredGap(LayoutStyle.RELATED)
129                 .add(layout.createParallelGroup(GroupLayout.BASELINE)
130                     .add(variableModifierLabel)
131                     .add(cbModifier))
132                 .addPreferredGap(LayoutStyle.RELATED)
133                 .add(layout.createParallelGroup(GroupLayout.BASELINE)
134                     .add(listenerStyleLabel)
135                     .add(cbListenerStyle))
136                 .addPreferredGap(LayoutStyle.RELATED)
137                 .add(layout.createParallelGroup(GroupLayout.BASELINE)
138                     .add(autoI18nLabel)
139                     .add(cbAutoI18n))
140                 .addPreferredGap(LayoutStyle.RELATED)
141                 .add(cbFold)
142                 .add(cbAssistant)
143                 .addContainerGap()
144         );
145         setBorder(new TitledBorder JavaDoc(loc("Code_Generation"))); // NOI18N
146
setBackground (Color.white);
147
148         cbFold.addActionListener (this);
149         cbAssistant.addActionListener(this);
150         cbListenerStyle.addActionListener (this);
151         cbModifier.addActionListener (this);
152         rbGenerateFields.addActionListener (this);
153         rbGenerateLocals.addActionListener (this);
154         cbAutoI18n.addActionListener(this);
155     }
156     
157     private static String JavaDoc loc (String JavaDoc key) {
158         return NbBundle.getMessage (FormEditorCustomizer.class, key);
159     }
160     
161     private static void loc (Component JavaDoc c, String JavaDoc key) {
162         if (c instanceof AbstractButton JavaDoc) {
163             Mnemonics.setLocalizedText((AbstractButton JavaDoc)c, loc(key));
164         } else {
165             Mnemonics.setLocalizedText((JLabel JavaDoc)c, loc(key));
166         }
167     }
168     
169     
170     // other methods ...........................................................
171

172     void update () {
173         listen = false;
174         FormLoaderSettings options = FormLoaderSettings.getInstance ();
175         
176         cbFold.setSelected (options.getFoldGeneratedCode ());
177         cbAssistant.setSelected(options.getAssistantShown());
178         rbGenerateLocals.setSelected (options.getVariablesLocal ());
179         rbGenerateFields.setSelected (!options.getVariablesLocal ());
180         if ((options.getVariablesModifier () & Modifier.PUBLIC) > 0)
181             cbModifier.setSelectedIndex (0);
182         else
183         if ((options.getVariablesModifier () & Modifier.PROTECTED) > 0)
184             cbModifier.setSelectedIndex (2);
185         else
186         if ((options.getVariablesModifier () & Modifier.PRIVATE) > 0)
187             cbModifier.setSelectedIndex (3);
188         else
189             cbModifier.setSelectedIndex (1);
190         cbListenerStyle.setSelectedIndex (options.getListenerGenerationStyle ());
191         cbAutoI18n.setSelectedIndex(options.getI18nAutoMode());
192         listen = true;
193         changed = false;
194     }
195     
196     void applyChanges () {
197         FormLoaderSettings options = FormLoaderSettings.getInstance ();
198         
199         options.setFoldGeneratedCode (cbFold.isSelected ());
200         options.setAssistantShown(cbAssistant.isSelected());
201         options.setListenerGenerationStyle (cbListenerStyle.getSelectedIndex ());
202         options.setI18nAutoMode(cbAutoI18n.getSelectedIndex());
203         options.setVariablesLocal (rbGenerateLocals.isSelected ());
204         switch (cbModifier.getSelectedIndex ()) {
205             case 0: options.setVariablesModifier (Modifier.PUBLIC);
206                     break;
207             case 1: options.setVariablesModifier (0);
208                     break;
209             case 2: options.setVariablesModifier (Modifier.PROTECTED);
210                     break;
211             case 3: options.setVariablesModifier (Modifier.PRIVATE);
212                     break;
213         }
214         changed = false;
215     }
216     
217     void cancel () {
218         changed = false;
219     }
220     
221     boolean dataValid () {
222         return true;
223     }
224     
225     boolean isChanged () {
226         return changed;
227     }
228     
229     public void actionPerformed (ActionEvent JavaDoc e) {
230         if (listen)
231             changed = true;
232     }
233     
234     public void stateChanged (ChangeEvent JavaDoc e) {
235         if (listen)
236             changed = true;
237     }
238 }
Popular Tags