1 19 20 package org.netbeans.modules.options.generaleditor; 21 22 import java.awt.Component ; 23 import java.awt.event.ActionEvent ; 24 import java.awt.event.ActionListener ; 25 import javax.swing.AbstractButton ; 26 import javax.swing.JLabel ; 27 import javax.swing.JPanel ; 28 import org.openide.awt.Mnemonics; 29 import org.openide.util.NbBundle; 30 31 36 public class GeneralEditorPanel extends JPanel implements ActionListener { 37 38 private boolean changed = false; 39 private boolean listen = false; 40 41 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 72 private void initComponents() { 74 lCodeFolding = new javax.swing.JLabel (); 75 lUseCodeFolding = new javax.swing.JLabel (); 76 lCollapseByDefault = new javax.swing.JLabel (); 77 cbUseCodeFolding = new javax.swing.JCheckBox (); 78 cbFoldMethods = new javax.swing.JCheckBox (); 79 cbFoldInnerClasses = new javax.swing.JCheckBox (); 80 cbFoldImports = new javax.swing.JCheckBox (); 81 cbFoldJavadocComments = new javax.swing.JCheckBox (); 82 cbFoldInitialComments = new javax.swing.JCheckBox (); 83 lCodeCompletion = new javax.swing.JLabel (); 84 jSeparator2 = new javax.swing.JSeparator (); 85 lCodeCompletion2 = new javax.swing.JLabel (); 86 cbAutoPopup = new javax.swing.JCheckBox (); 87 cbInsertSingleProposalsAutomatically = new javax.swing.JCheckBox (); 88 cbCaseSensitive = new javax.swing.JCheckBox (); 89 cbShowDeprecated = new javax.swing.JCheckBox (); 90 cbInsertClosingBracketsAutomatically = new javax.swing.JCheckBox (); 91 jSeparator1 = new javax.swing.JSeparator (); 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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 } 222 223 private javax.swing.JCheckBox cbAutoPopup; 225 private javax.swing.JCheckBox cbCaseSensitive; 226 private javax.swing.JCheckBox cbFoldImports; 227 private javax.swing.JCheckBox cbFoldInitialComments; 228 private javax.swing.JCheckBox cbFoldInnerClasses; 229 private javax.swing.JCheckBox cbFoldJavadocComments; 230 private javax.swing.JCheckBox cbFoldMethods; 231 private javax.swing.JCheckBox cbInsertClosingBracketsAutomatically; 232 private javax.swing.JCheckBox cbInsertSingleProposalsAutomatically; 233 private javax.swing.JCheckBox cbShowDeprecated; 234 private javax.swing.JCheckBox cbUseCodeFolding; 235 private javax.swing.JSeparator jSeparator1; 236 private javax.swing.JSeparator jSeparator2; 237 private javax.swing.JLabel lCodeCompletion; 238 private javax.swing.JLabel lCodeCompletion2; 239 private javax.swing.JLabel lCodeFolding; 240 private javax.swing.JLabel lCollapseByDefault; 241 private javax.swing.JLabel lUseCodeFolding; 242 244 245 private static String loc (String key) { 246 return NbBundle.getMessage (GeneralEditorPanel.class, key); 247 } 248 249 private static void loc (Component c, String key) { 250 if (!(c instanceof JLabel )) { 251 c.getAccessibleContext ().setAccessibleName (loc ("AN_" + key)); 252 c.getAccessibleContext ().setAccessibleDescription (loc ("AD_" + key)); 253 } 254 if (c instanceof AbstractButton ) { 255 Mnemonics.setLocalizedText ( 256 (AbstractButton ) c, 257 loc ("CTL_" + key) 258 ); 259 } else { 260 Mnemonics.setLocalizedText ( 261 (JLabel ) 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 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 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 model.setFoldingOptions ( 315 cbUseCodeFolding.isSelected (), 316 cbFoldImports.isSelected (), 317 cbFoldInitialComments.isSelected (), 318 cbFoldInnerClasses.isSelected (), 319 cbFoldJavadocComments.isSelected (), 320 cbFoldMethods.isSelected () 321 ); 322 323 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 e) { 347 if (!listen) return; 348 if (e.getSource () == cbUseCodeFolding) 349 updateEnabledState (); 350 changed = true; 351 } 352 353 354 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 |