1 19 20 package org.netbeans.modules.form; 21 22 import java.lang.reflect.Modifier ; 23 import java.awt.Color ; 24 import java.awt.Component ; 25 import java.awt.event.ActionEvent ; 26 import java.awt.event.ActionListener ; 27 import javax.swing.AbstractButton ; 28 import javax.swing.ButtonGroup ; 29 import javax.swing.JCheckBox ; 30 import javax.swing.JComboBox ; 31 import javax.swing.JLabel ; 32 import javax.swing.JPanel ; 33 import javax.swing.JRadioButton ; 34 import javax.swing.border.TitledBorder ; 35 import javax.swing.event.ChangeEvent ; 36 import javax.swing.event.ChangeListener ; 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 48 public final class FormEditorCustomizer extends JPanel implements ActionListener , ChangeListener { 49 private JCheckBox cbFold = new JCheckBox (); 50 private JCheckBox cbAssistant = new JCheckBox (); 51 private JComboBox cbModifier = new JComboBox (); 52 private JRadioButton rbGenerateLocals = new JRadioButton (); 53 private JRadioButton rbGenerateFields = new JRadioButton (); 54 private JComboBox cbListenerStyle = new JComboBox (); 55 private JComboBox cbAutoI18n = new JComboBox (); 56 57 private boolean changed = false; 58 private boolean listen = false; 59 60 public FormEditorCustomizer () { 61 ButtonGroup group = new ButtonGroup (); 62 loc(cbFold, "Fold"); cbFold.setBackground (Color.white); 64 loc(cbAssistant, "Assistant"); cbAssistant.setBackground(Color.white); 66 loc(rbGenerateLocals, "Generate_Locals"); rbGenerateLocals.setBackground (Color.white); 68 group.add (rbGenerateLocals); 69 loc(rbGenerateFields, "Generate_Fields"); rbGenerateFields.setBackground (Color.white); 71 group.add (rbGenerateFields); 72 cbModifier.addItem(loc("Public_Modifier")); cbModifier.addItem(loc("Default_Modifier")); cbModifier.addItem(loc("Protected_Modifier")); cbModifier.addItem(loc("Private_Modifier")); cbListenerStyle.addItem(loc("Anonymous")); cbListenerStyle.addItem(loc("InnerClass")); cbListenerStyle.addItem(loc("MainClass")); cbAutoI18n.addItem(loc("CTL_AUTO_I18N_DEFAULT")); cbAutoI18n.addItem(loc("CTL_AUTO_I18N_ON")); cbAutoI18n.addItem(loc("CTL_AUTO_I18N_OFF")); 83 JLabel generateComponetsLabel = new JLabel (loc("Generate_Components")); JLabel variableModifierLabel = new JLabel (loc("Variable_Modifier")); JLabel listenerStyleLabel = new JLabel (loc("Listener_Style")); JLabel autoI18nLabel = new JLabel (loc("Auto_I18n")); 88 generateComponetsLabel.setToolTipText(loc("Generate_Components_Hint")); variableModifierLabel.setToolTipText(loc("HINT_VARIABLES_MODIFIER")); listenerStyleLabel.setToolTipText(loc("HINT_LISTENER_GENERATION_STYLE")); autoI18nLabel.setToolTipText(loc("HINT_AUTO_I18N_GLOBAL")); cbFold.setToolTipText(loc("HINT_FOLD_GENERATED_CODE")); cbAssistant.setToolTipText(loc("HINT_ASSISTANT_SHOWN")); 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 (loc("Code_Generation"))); 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 loc (String key) { 158 return NbBundle.getMessage (FormEditorCustomizer.class, key); 159 } 160 161 private static void loc (Component c, String key) { 162 if (c instanceof AbstractButton ) { 163 Mnemonics.setLocalizedText((AbstractButton )c, loc(key)); 164 } else { 165 Mnemonics.setLocalizedText((JLabel )c, loc(key)); 166 } 167 } 168 169 170 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 e) { 230 if (listen) 231 changed = true; 232 } 233 234 public void stateChanged (ChangeEvent e) { 235 if (listen) 236 changed = true; 237 } 238 } | Popular Tags |