001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.form;
043:
044: import java.lang.reflect.Modifier;
045: import java.awt.Component;
046: import java.awt.event.ActionEvent;
047: import java.awt.event.ActionListener;
048: import javax.swing.AbstractButton;
049: import javax.swing.ButtonGroup;
050: import javax.swing.JCheckBox;
051: import javax.swing.JComboBox;
052: import javax.swing.JLabel;
053: import javax.swing.JPanel;
054: import javax.swing.JRadioButton;
055: import javax.swing.border.TitledBorder;
056: import javax.swing.event.ChangeEvent;
057: import javax.swing.event.ChangeListener;
058:
059: import org.jdesktop.layout.GroupLayout;
060: import org.jdesktop.layout.LayoutStyle;
061: import org.openide.awt.Mnemonics;
062: import org.openide.util.NbBundle;
063:
064: /**
065: * Implementation of one panel in Options Dialog.
066: *
067: * @author Jan Stola, Jan Jancura
068: */
069: public final class FormEditorCustomizer extends JPanel implements
070: ActionListener, ChangeListener {
071: private JCheckBox cbFold = new JCheckBox();
072: private JCheckBox cbAssistant = new JCheckBox();
073: private JComboBox cbModifier = new JComboBox();
074: private JRadioButton rbGenerateLocals = new JRadioButton();
075: private JRadioButton rbGenerateFields = new JRadioButton();
076: private JComboBox cbListenerStyle = new JComboBox();
077: private JComboBox cbAutoI18n = new JComboBox();
078:
079: private boolean changed = false;
080: private boolean listen = false;
081:
082: public FormEditorCustomizer() {
083: ButtonGroup group = new ButtonGroup();
084: loc(cbFold, "Fold"); // NOI18N
085: loc(cbAssistant, "Assistant"); // NOI18N
086: loc(rbGenerateLocals, "Generate_Locals"); // NOI18N
087: group.add(rbGenerateLocals);
088: loc(rbGenerateFields, "Generate_Fields"); // NOI18N
089: group.add(rbGenerateFields);
090: cbModifier.addItem(loc("Public_Modifier")); // NOI18N
091: cbModifier.addItem(loc("Default_Modifier")); // NOI18N
092: cbModifier.addItem(loc("Protected_Modifier")); // NOI18N
093: cbModifier.addItem(loc("Private_Modifier")); // NOI18N
094: cbListenerStyle.addItem(loc("Anonymous")); // NOI18N
095: cbListenerStyle.addItem(loc("InnerClass")); // NOI18N
096: cbListenerStyle.addItem(loc("MainClass")); // NOI18N
097: cbAutoI18n.addItem(loc("CTL_AUTO_RESOURCE_DEFAULT")); // NOI18N
098: cbAutoI18n.addItem(loc("CTL_AUTO_RESOURCE_ON")); // NOI18N
099: cbAutoI18n.addItem(loc("CTL_AUTO_RESOURCE_OFF")); // NOI18N
100:
101: JLabel generateComponetsLabel = new JLabel(
102: loc("Generate_Components")); // NOI18N
103: JLabel variableModifierLabel = new JLabel();
104: JLabel listenerStyleLabel = new JLabel();
105: JLabel autoI18nLabel = new JLabel();
106: loc(variableModifierLabel, "Variable_Modifier"); // NOI18N
107: loc(listenerStyleLabel, "Listener_Style"); // NOI18N
108: loc(autoI18nLabel, "Auto_I18n"); // NOI18N
109:
110: generateComponetsLabel
111: .setToolTipText(loc("Generate_Components_Hint")); // NOI18N
112: variableModifierLabel
113: .setToolTipText(loc("HINT_VARIABLES_MODIFIER")); // NOI18N
114: listenerStyleLabel
115: .setToolTipText(loc("HINT_LISTENER_GENERATION_STYLE")); // NOI18N
116: autoI18nLabel.setToolTipText(loc("HINT_AUTO_RESOURCE_GLOBAL")); // NOI18N
117: cbFold.setToolTipText(loc("HINT_FOLD_GENERATED_CODE")); // NOI18N
118: cbAssistant.setToolTipText(loc("HINT_ASSISTANT_SHOWN")); // NOI18N
119: rbGenerateLocals.getAccessibleContext()
120: .setAccessibleDescription(loc("Generate_Locals_ACSD")); // NOI18N
121: rbGenerateFields.getAccessibleContext()
122: .setAccessibleDescription(loc("Generate_Fields_ACSD")); // NOI18N
123:
124: variableModifierLabel.setLabelFor(cbModifier);
125: listenerStyleLabel.setLabelFor(cbListenerStyle);
126: autoI18nLabel.setLabelFor(cbAutoI18n);
127:
128: GroupLayout layout = new GroupLayout(this );
129: setLayout(layout);
130: layout.setHorizontalGroup(layout.createSequentialGroup()
131: .addContainerGap().add(
132: layout.createParallelGroup(GroupLayout.LEADING)
133: .add(generateComponetsLabel).add(
134: variableModifierLabel).add(
135: listenerStyleLabel).add(
136: autoI18nLabel))
137: .addPreferredGap(LayoutStyle.RELATED).add(
138: layout.createParallelGroup(GroupLayout.LEADING,
139: false).add(rbGenerateLocals).add(
140: rbGenerateFields).add(cbFold).add(
141: cbAssistant).add(cbModifier,
142: GroupLayout.DEFAULT_SIZE,
143: GroupLayout.DEFAULT_SIZE,
144: Short.MAX_VALUE).add(cbListenerStyle,
145: GroupLayout.DEFAULT_SIZE,
146: GroupLayout.DEFAULT_SIZE,
147: Short.MAX_VALUE).add(cbAutoI18n,
148: GroupLayout.DEFAULT_SIZE,
149: GroupLayout.DEFAULT_SIZE,
150: Short.MAX_VALUE)).addContainerGap(
151: GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
152: layout.setVerticalGroup(layout.createSequentialGroup()
153: .addContainerGap().add(
154: layout
155: .createParallelGroup(
156: GroupLayout.BASELINE).add(
157: generateComponetsLabel).add(
158: rbGenerateLocals))
159: .addPreferredGap(LayoutStyle.RELATED).add(
160: rbGenerateFields).addPreferredGap(
161: LayoutStyle.RELATED).add(
162: layout
163: .createParallelGroup(
164: GroupLayout.BASELINE).add(
165: variableModifierLabel).add(
166: cbModifier)).addPreferredGap(
167: LayoutStyle.RELATED).add(
168: layout
169: .createParallelGroup(
170: GroupLayout.BASELINE).add(
171: listenerStyleLabel).add(
172: cbListenerStyle))
173: .addPreferredGap(LayoutStyle.RELATED).add(
174: layout
175: .createParallelGroup(
176: GroupLayout.BASELINE).add(
177: autoI18nLabel).add(cbAutoI18n))
178: .addPreferredGap(LayoutStyle.RELATED).add(cbFold).add(
179: cbAssistant).addContainerGap());
180: setBorder(new TitledBorder(loc("Code_Generation"))); // NOI18N
181:
182: cbFold.addActionListener(this );
183: cbAssistant.addActionListener(this );
184: cbListenerStyle.addActionListener(this );
185: cbModifier.addActionListener(this );
186: rbGenerateFields.addActionListener(this );
187: rbGenerateLocals.addActionListener(this );
188: cbAutoI18n.addActionListener(this );
189: }
190:
191: private static String loc(String key) {
192: return NbBundle.getMessage(FormEditorCustomizer.class, key);
193: }
194:
195: private static void loc(Component c, String key) {
196: if (c instanceof AbstractButton) {
197: Mnemonics.setLocalizedText((AbstractButton) c, loc(key));
198: } else {
199: Mnemonics.setLocalizedText((JLabel) c, loc(key));
200: }
201: }
202:
203: // other methods ...........................................................
204:
205: void update() {
206: listen = false;
207: FormLoaderSettings options = FormLoaderSettings.getInstance();
208:
209: cbFold.setSelected(options.getFoldGeneratedCode());
210: cbAssistant.setSelected(options.getAssistantShown());
211: rbGenerateLocals.setSelected(options.getVariablesLocal());
212: rbGenerateFields.setSelected(!options.getVariablesLocal());
213: if ((options.getVariablesModifier() & Modifier.PUBLIC) > 0)
214: cbModifier.setSelectedIndex(0);
215: else if ((options.getVariablesModifier() & Modifier.PROTECTED) > 0)
216: cbModifier.setSelectedIndex(2);
217: else if ((options.getVariablesModifier() & Modifier.PRIVATE) > 0)
218: cbModifier.setSelectedIndex(3);
219: else
220: cbModifier.setSelectedIndex(1);
221: cbListenerStyle.setSelectedIndex(options
222: .getListenerGenerationStyle());
223: cbAutoI18n.setSelectedIndex(options.getI18nAutoMode());
224: listen = true;
225: changed = false;
226: }
227:
228: void applyChanges() {
229: FormLoaderSettings options = FormLoaderSettings.getInstance();
230:
231: options.setFoldGeneratedCode(cbFold.isSelected());
232: options.setAssistantShown(cbAssistant.isSelected());
233: options.setListenerGenerationStyle(cbListenerStyle
234: .getSelectedIndex());
235: options.setI18nAutoMode(cbAutoI18n.getSelectedIndex());
236: options.setVariablesLocal(rbGenerateLocals.isSelected());
237: switch (cbModifier.getSelectedIndex()) {
238: case 0:
239: options.setVariablesModifier(Modifier.PUBLIC);
240: break;
241: case 1:
242: options.setVariablesModifier(0);
243: break;
244: case 2:
245: options.setVariablesModifier(Modifier.PROTECTED);
246: break;
247: case 3:
248: options.setVariablesModifier(Modifier.PRIVATE);
249: break;
250: }
251: changed = false;
252: }
253:
254: void cancel() {
255: changed = false;
256: }
257:
258: boolean dataValid() {
259: return true;
260: }
261:
262: boolean isChanged() {
263: return changed;
264: }
265:
266: public void actionPerformed(ActionEvent e) {
267: if (listen)
268: changed = true;
269: }
270:
271: public void stateChanged(ChangeEvent e) {
272: if (listen)
273: changed = true;
274: }
275: }
|