KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > editor > options > CodeFoldingEditorPanel


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.java.editor.options;
21
22 import java.awt.event.ItemEvent JavaDoc;
23 import java.util.HashMap JavaDoc;
24 import java.util.Map JavaDoc;
25 import org.netbeans.editor.SettingsNames;
26 import org.netbeans.editor.ext.java.JavaSettingsNames;
27 import org.openide.util.NbBundle;
28
29 /**
30  *
31  * @author Martin Roskanin
32  */

33 public class CodeFoldingEditorPanel extends javax.swing.JPanel JavaDoc {
34
35     CodeFoldingEditor foldingEditor;
36
37     /** Creates new form CodeFoldingEditorPanel */
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)); //NOI18N
46
methodCB.setMnemonic(getBundleString("CFEP_Method_Mnemonic").charAt(0)); //NOI18N
47
innerCB.setMnemonic(getBundleString("CFEP_InnerClass_Mnemonic").charAt(0)); //NOI18N
48
importCB.setMnemonic(getBundleString("CFEP_Import_Mnemonic").charAt(0)); //NOI18N
49
javadocCB.setMnemonic(getBundleString("CFEP_Javadoc_Mnemonic").charAt(0)); //NOI18N
50
initialCommentCB.setMnemonic(getBundleString("CFEP_InitialComment_Mnemonic").charAt(0)); //NOI18N
51
}
52     
53     /** This method is called from within the constructor to
54      * initialize the form.
55      * WARNING: Do NOT modify this code. The content of this method is
56      * always regenerated by the Form Editor.
57      */

58     private void initComponents() {//GEN-BEGIN:initComponents
59
java.awt.GridBagConstraints JavaDoc gridBagConstraints;
60
61         enableFoldingCB = new javax.swing.JCheckBox JavaDoc();
62         jLabel1 = new javax.swing.JLabel JavaDoc();
63         methodCB = new javax.swing.JCheckBox JavaDoc();
64         innerCB = new javax.swing.JCheckBox JavaDoc();
65         importCB = new javax.swing.JCheckBox JavaDoc();
66         javadocCB = new javax.swing.JCheckBox JavaDoc();
67         initialCommentCB = new javax.swing.JCheckBox JavaDoc();
68
69         setLayout(new java.awt.GridBagLayout JavaDoc());
70
71         enableFoldingCB.setText(getBundleString( "CFEP_UseCF" ));
72         enableFoldingCB.addItemListener(new java.awt.event.ItemListener JavaDoc() {
73             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
74                 checkBoxChange(evt);
75             }
76         });
77
78         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(12, 12, 12, 0);
84         add(enableFoldingCB, gridBagConstraints);
85
86         jLabel1.setText(getBundleString( "CFEP_CollapsedByDefault" ));
87         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
88         gridBagConstraints.gridx = 0;
89         gridBagConstraints.gridy = 1;
90         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
91         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 5, 11);
92         add(jLabel1, gridBagConstraints);
93
94         methodCB.setText(getBundleString( "CFEP_Method" ));
95         methodCB.addItemListener(new java.awt.event.ItemListener JavaDoc() {
96             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
97                 methodCBItemStateChanged(evt);
98             }
99         });
100
101         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
102         gridBagConstraints.gridx = 0;
103         gridBagConstraints.gridy = 2;
104         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
105         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 24, 0, 0);
106         add(methodCB, gridBagConstraints);
107
108         innerCB.setText(getBundleString( "CFEP_InnerClass" ));
109         innerCB.addItemListener(new java.awt.event.ItemListener JavaDoc() {
110             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
111                 innerCBItemStateChanged(evt);
112             }
113         });
114
115         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
116         gridBagConstraints.gridx = 0;
117         gridBagConstraints.gridy = 3;
118         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
119         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 24, 0, 0);
120         add(innerCB, gridBagConstraints);
121
122         importCB.setText(getBundleString( "CFEP_Import" ));
123         importCB.addItemListener(new java.awt.event.ItemListener JavaDoc() {
124             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
125                 importCBItemStateChanged(evt);
126             }
127         });
128
129         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
130         gridBagConstraints.gridx = 0;
131         gridBagConstraints.gridy = 4;
132         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
133         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 24, 0, 0);
134         add(importCB, gridBagConstraints);
135
136         javadocCB.setText(getBundleString( "CFEP_Javadoc" ));
137         javadocCB.addItemListener(new java.awt.event.ItemListener JavaDoc() {
138             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
139                 javadocCBItemStateChanged(evt);
140             }
141         });
142
143         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
144         gridBagConstraints.gridx = 0;
145         gridBagConstraints.gridy = 5;
146         gridBagConstraints.insets = new java.awt.Insets JavaDoc(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 JavaDoc() {
152             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
153                 initialCommentCBItemStateChanged(evt);
154             }
155         });
156
157         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
158         gridBagConstraints.gridx = 0;
159         gridBagConstraints.gridy = 6;
160         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 24, 0, 0);
161         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
162         add(initialCommentCB, gridBagConstraints);
163
164     }//GEN-END:initComponents
165

166     private void initialCommentCBItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_initialCommentCBItemStateChanged
167
notifyEditor();
168     }//GEN-LAST:event_initialCommentCBItemStateChanged
169

170     private void javadocCBItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_javadocCBItemStateChanged
171
notifyEditor();
172     }//GEN-LAST:event_javadocCBItemStateChanged
173

174     private void importCBItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_importCBItemStateChanged
175
notifyEditor();
176     }//GEN-LAST:event_importCBItemStateChanged
177

178     private void innerCBItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_innerCBItemStateChanged
179
notifyEditor();
180     }//GEN-LAST:event_innerCBItemStateChanged
181

182     private void methodCBItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_methodCBItemStateChanged
183
notifyEditor();
184     }//GEN-LAST:event_methodCBItemStateChanged
185

186     private void checkBoxChange(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_checkBoxChange
187
setCBoxesEnabled(evt.getStateChange() == ItemEvent.SELECTED);
188         notifyEditor();
189     }//GEN-LAST:event_checkBoxChange
190

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     /**
205      * Fill in editor with initial values
206      */

207     public void setValue( Map JavaDoc m ) {
208
209         Boolean JavaDoc val = (Boolean JavaDoc)m.get(SettingsNames.CODE_FOLDING_ENABLE);
210         if (val.booleanValue() == false){
211             setCBoxesEnabled(false);
212         }
213         enableFoldingCB.setSelected(val.booleanValue());
214         
215         val = (Boolean JavaDoc)m.get(JavaSettingsNames.CODE_FOLDING_COLLAPSE_METHOD);
216         methodCB.setSelected(val.booleanValue());
217
218         val = (Boolean JavaDoc)m.get(JavaSettingsNames.CODE_FOLDING_COLLAPSE_INNERCLASS);
219         innerCB.setSelected(val.booleanValue());
220
221         val = (Boolean JavaDoc)m.get(JavaSettingsNames.CODE_FOLDING_COLLAPSE_IMPORT);
222         importCB.setSelected(val.booleanValue());
223
224         val = (Boolean JavaDoc)m.get(JavaSettingsNames.CODE_FOLDING_COLLAPSE_JAVADOC);
225         javadocCB.setSelected(val.booleanValue());
226         
227         val = (Boolean JavaDoc)m.get(JavaSettingsNames.CODE_FOLDING_COLLAPSE_INITIAL_COMMENT);
228         initialCommentCB.setSelected(val.booleanValue());
229
230     }
231
232     /**
233      * Take the result of users modifications
234      */

235     public Map JavaDoc getValue() {
236         Map JavaDoc ret = new HashMap JavaDoc(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 JavaDoc getBundleString(String JavaDoc s) {
247         return NbBundle.getMessage(CodeFoldingEditorPanel.class, s);
248     }
249
250     
251     // Variables declaration - do not modify//GEN-BEGIN:variables
252
private javax.swing.JCheckBox JavaDoc enableFoldingCB;
253     private javax.swing.JCheckBox JavaDoc importCB;
254     private javax.swing.JCheckBox JavaDoc initialCommentCB;
255     private javax.swing.JCheckBox JavaDoc innerCB;
256     private javax.swing.JLabel JavaDoc jLabel1;
257     private javax.swing.JCheckBox JavaDoc javadocCB;
258     private javax.swing.JCheckBox JavaDoc methodCB;
259     // End of variables declaration//GEN-END:variables
260

261 }
262
Popular Tags