1 19 20 package org.netbeans.modules.java.editor.options; 21 22 import java.awt.event.ItemEvent ; 23 import java.util.HashMap ; 24 import java.util.Map ; 25 import org.netbeans.editor.SettingsNames; 26 import org.netbeans.editor.ext.java.JavaSettingsNames; 27 import org.openide.util.NbBundle; 28 29 33 public class CodeFoldingEditorPanel extends javax.swing.JPanel { 34 35 CodeFoldingEditor foldingEditor; 36 37 38 public CodeFoldingEditorPanel(CodeFoldingEditor foldingEditor) { 39 this.foldingEditor = foldingEditor; 40 initComponents(); 41 initAccessibility(); 42 } 43 44 private void initAccessibility(){ 45 enableFoldingCB.setMnemonic(getBundleString("CFEP_UseCF_Mnemonic").charAt(0)); methodCB.setMnemonic(getBundleString("CFEP_Method_Mnemonic").charAt(0)); innerCB.setMnemonic(getBundleString("CFEP_InnerClass_Mnemonic").charAt(0)); importCB.setMnemonic(getBundleString("CFEP_Import_Mnemonic").charAt(0)); javadocCB.setMnemonic(getBundleString("CFEP_Javadoc_Mnemonic").charAt(0)); initialCommentCB.setMnemonic(getBundleString("CFEP_InitialComment_Mnemonic").charAt(0)); } 52 53 58 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 60 61 enableFoldingCB = new javax.swing.JCheckBox (); 62 jLabel1 = new javax.swing.JLabel (); 63 methodCB = new javax.swing.JCheckBox (); 64 innerCB = new javax.swing.JCheckBox (); 65 importCB = new javax.swing.JCheckBox (); 66 javadocCB = new javax.swing.JCheckBox (); 67 initialCommentCB = new javax.swing.JCheckBox (); 68 69 setLayout(new java.awt.GridBagLayout ()); 70 71 enableFoldingCB.setText(getBundleString( "CFEP_UseCF" )); 72 enableFoldingCB.addItemListener(new java.awt.event.ItemListener () { 73 public void itemStateChanged(java.awt.event.ItemEvent evt) { 74 checkBoxChange(evt); 75 } 76 }); 77 78 gridBagConstraints = new java.awt.GridBagConstraints (); 79 gridBagConstraints.gridx = 0; 80 gridBagConstraints.gridy = 0; 81 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 82 gridBagConstraints.weightx = 1.0; 83 gridBagConstraints.insets = new java.awt.Insets (12, 12, 12, 0); 84 add(enableFoldingCB, gridBagConstraints); 85 86 jLabel1.setText(getBundleString( "CFEP_CollapsedByDefault" )); 87 gridBagConstraints = new java.awt.GridBagConstraints (); 88 gridBagConstraints.gridx = 0; 89 gridBagConstraints.gridy = 1; 90 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 91 gridBagConstraints.insets = new java.awt.Insets (0, 12, 5, 11); 92 add(jLabel1, gridBagConstraints); 93 94 methodCB.setText(getBundleString( "CFEP_Method" )); 95 methodCB.addItemListener(new java.awt.event.ItemListener () { 96 public void itemStateChanged(java.awt.event.ItemEvent evt) { 97 methodCBItemStateChanged(evt); 98 } 99 }); 100 101 gridBagConstraints = new java.awt.GridBagConstraints (); 102 gridBagConstraints.gridx = 0; 103 gridBagConstraints.gridy = 2; 104 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 105 gridBagConstraints.insets = new java.awt.Insets (0, 24, 0, 0); 106 add(methodCB, gridBagConstraints); 107 108 innerCB.setText(getBundleString( "CFEP_InnerClass" )); 109 innerCB.addItemListener(new java.awt.event.ItemListener () { 110 public void itemStateChanged(java.awt.event.ItemEvent evt) { 111 innerCBItemStateChanged(evt); 112 } 113 }); 114 115 gridBagConstraints = new java.awt.GridBagConstraints (); 116 gridBagConstraints.gridx = 0; 117 gridBagConstraints.gridy = 3; 118 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 119 gridBagConstraints.insets = new java.awt.Insets (0, 24, 0, 0); 120 add(innerCB, gridBagConstraints); 121 122 importCB.setText(getBundleString( "CFEP_Import" )); 123 importCB.addItemListener(new java.awt.event.ItemListener () { 124 public void itemStateChanged(java.awt.event.ItemEvent evt) { 125 importCBItemStateChanged(evt); 126 } 127 }); 128 129 gridBagConstraints = new java.awt.GridBagConstraints (); 130 gridBagConstraints.gridx = 0; 131 gridBagConstraints.gridy = 4; 132 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 133 gridBagConstraints.insets = new java.awt.Insets (0, 24, 0, 0); 134 add(importCB, gridBagConstraints); 135 136 javadocCB.setText(getBundleString( "CFEP_Javadoc" )); 137 javadocCB.addItemListener(new java.awt.event.ItemListener () { 138 public void itemStateChanged(java.awt.event.ItemEvent evt) { 139 javadocCBItemStateChanged(evt); 140 } 141 }); 142 143 gridBagConstraints = new java.awt.GridBagConstraints (); 144 gridBagConstraints.gridx = 0; 145 gridBagConstraints.gridy = 5; 146 gridBagConstraints.insets = new java.awt.Insets (0, 24, 0, 0); 147 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 148 add(javadocCB, gridBagConstraints); 149 150 initialCommentCB.setText(getBundleString( "CFEP_InitialComment" )); 151 initialCommentCB.addItemListener(new java.awt.event.ItemListener () { 152 public void itemStateChanged(java.awt.event.ItemEvent evt) { 153 initialCommentCBItemStateChanged(evt); 154 } 155 }); 156 157 gridBagConstraints = new java.awt.GridBagConstraints (); 158 gridBagConstraints.gridx = 0; 159 gridBagConstraints.gridy = 6; 160 gridBagConstraints.insets = new java.awt.Insets (0, 24, 0, 0); 161 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 162 add(initialCommentCB, gridBagConstraints); 163 164 } 166 private void initialCommentCBItemStateChanged(java.awt.event.ItemEvent evt) { notifyEditor(); 168 } 170 private void javadocCBItemStateChanged(java.awt.event.ItemEvent evt) { notifyEditor(); 172 } 174 private void importCBItemStateChanged(java.awt.event.ItemEvent evt) { notifyEditor(); 176 } 178 private void innerCBItemStateChanged(java.awt.event.ItemEvent evt) { notifyEditor(); 180 } 182 private void methodCBItemStateChanged(java.awt.event.ItemEvent evt) { notifyEditor(); 184 } 186 private void checkBoxChange(java.awt.event.ItemEvent evt) { setCBoxesEnabled(evt.getStateChange() == ItemEvent.SELECTED); 188 notifyEditor(); 189 } 191 192 private void notifyEditor() { 193 if( foldingEditor != null ) foldingEditor.customEditorChange(); 194 } 195 196 private void setCBoxesEnabled(boolean selected){ 197 methodCB.setEnabled(selected); 198 innerCB.setEnabled(selected); 199 importCB.setEnabled(selected); 200 javadocCB.setEnabled(selected); 201 initialCommentCB.setEnabled(selected); 202 } 203 204 207 public void setValue( Map m ) { 208 209 Boolean val = (Boolean )m.get(SettingsNames.CODE_FOLDING_ENABLE); 210 if (val.booleanValue() == false){ 211 setCBoxesEnabled(false); 212 } 213 enableFoldingCB.setSelected(val.booleanValue()); 214 215 val = (Boolean )m.get(JavaSettingsNames.CODE_FOLDING_COLLAPSE_METHOD); 216 methodCB.setSelected(val.booleanValue()); 217 218 val = (Boolean )m.get(JavaSettingsNames.CODE_FOLDING_COLLAPSE_INNERCLASS); 219 innerCB.setSelected(val.booleanValue()); 220 221 val = (Boolean )m.get(JavaSettingsNames.CODE_FOLDING_COLLAPSE_IMPORT); 222 importCB.setSelected(val.booleanValue()); 223 224 val = (Boolean )m.get(JavaSettingsNames.CODE_FOLDING_COLLAPSE_JAVADOC); 225 javadocCB.setSelected(val.booleanValue()); 226 227 val = (Boolean )m.get(JavaSettingsNames.CODE_FOLDING_COLLAPSE_INITIAL_COMMENT); 228 initialCommentCB.setSelected(val.booleanValue()); 229 230 } 231 232 235 public Map getValue() { 236 Map ret = new HashMap (10); 237 ret.put(SettingsNames.CODE_FOLDING_ENABLE, Boolean.valueOf(enableFoldingCB.isSelected())); 238 ret.put(JavaSettingsNames.CODE_FOLDING_COLLAPSE_METHOD, Boolean.valueOf(methodCB.isSelected())); 239 ret.put(JavaSettingsNames.CODE_FOLDING_COLLAPSE_INNERCLASS, Boolean.valueOf(innerCB.isSelected())); 240 ret.put(JavaSettingsNames.CODE_FOLDING_COLLAPSE_IMPORT, Boolean.valueOf(importCB.isSelected())); 241 ret.put(JavaSettingsNames.CODE_FOLDING_COLLAPSE_JAVADOC, Boolean.valueOf(javadocCB.isSelected())); 242 ret.put(JavaSettingsNames.CODE_FOLDING_COLLAPSE_INITIAL_COMMENT, Boolean.valueOf(initialCommentCB.isSelected())); 243 return ret; 244 } 245 246 private String getBundleString(String s) { 247 return NbBundle.getMessage(CodeFoldingEditorPanel.class, s); 248 } 249 250 251 private javax.swing.JCheckBox enableFoldingCB; 253 private javax.swing.JCheckBox importCB; 254 private javax.swing.JCheckBox initialCommentCB; 255 private javax.swing.JCheckBox innerCB; 256 private javax.swing.JLabel jLabel1; 257 private javax.swing.JCheckBox javadocCB; 258 private javax.swing.JCheckBox methodCB; 259 261 } 262 | Popular Tags |