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.gsfret.editor.options;
043:
044: import java.awt.event.ItemEvent;
045: import java.util.HashMap;
046: import java.util.Map;
047: import org.netbeans.editor.SettingsNames; //import org.netbeans.editor.ext.java.JavaSettingsNames;
048: import org.openide.util.NbBundle;
049:
050: /**
051: * This file is originally from Retouche, the Java Support
052: * infrastructure in NetBeans. I have modified the file as little
053: * as possible to make merging Retouche fixes back as simple as
054: * possible.
055: *
056: *
057: * @author Martin Roskanin
058: */
059: public class CodeFoldingEditorPanel extends javax.swing.JPanel {
060:
061: CodeFoldingEditor foldingEditor;
062:
063: /** Creates new form CodeFoldingEditorPanel */
064: public CodeFoldingEditorPanel(CodeFoldingEditor foldingEditor) {
065: this .foldingEditor = foldingEditor;
066: initComponents();
067: initAccessibility();
068: }
069:
070: private void initAccessibility() {
071: enableFoldingCB.setMnemonic(getBundleString(
072: "CFEP_UseCF_Mnemonic").charAt(0)); //NOI18N
073: methodCB.setMnemonic(getBundleString("CFEP_Method_Mnemonic")
074: .charAt(0)); //NOI18N
075: innerCB.setMnemonic(getBundleString("CFEP_InnerClass_Mnemonic")
076: .charAt(0)); //NOI18N
077: importCB.setMnemonic(getBundleString("CFEP_Import_Mnemonic")
078: .charAt(0)); //NOI18N
079: javadocCB.setMnemonic(getBundleString("CFEP_Javadoc_Mnemonic")
080: .charAt(0)); //NOI18N
081: initialCommentCB.setMnemonic(getBundleString(
082: "CFEP_InitialComment_Mnemonic").charAt(0)); //NOI18N
083: }
084:
085: /** This method is called from within the constructor to
086: * initialize the form.
087: * WARNING: Do NOT modify this code. The content of this method is
088: * always regenerated by the Form Editor.
089: */
090: private void initComponents() {//GEN-BEGIN:initComponents
091: java.awt.GridBagConstraints gridBagConstraints;
092:
093: enableFoldingCB = new javax.swing.JCheckBox();
094: jLabel1 = new javax.swing.JLabel();
095: methodCB = new javax.swing.JCheckBox();
096: innerCB = new javax.swing.JCheckBox();
097: importCB = new javax.swing.JCheckBox();
098: javadocCB = new javax.swing.JCheckBox();
099: initialCommentCB = new javax.swing.JCheckBox();
100:
101: setLayout(new java.awt.GridBagLayout());
102:
103: enableFoldingCB.setText(getBundleString("CFEP_UseCF"));
104: enableFoldingCB
105: .addItemListener(new java.awt.event.ItemListener() {
106: public void itemStateChanged(
107: java.awt.event.ItemEvent evt) {
108: checkBoxChange(evt);
109: }
110: });
111:
112: gridBagConstraints = new java.awt.GridBagConstraints();
113: gridBagConstraints.gridx = 0;
114: gridBagConstraints.gridy = 0;
115: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
116: gridBagConstraints.weightx = 1.0;
117: gridBagConstraints.insets = new java.awt.Insets(12, 12, 12, 0);
118: add(enableFoldingCB, gridBagConstraints);
119:
120: jLabel1.setText(getBundleString("CFEP_CollapsedByDefault"));
121: gridBagConstraints = new java.awt.GridBagConstraints();
122: gridBagConstraints.gridx = 0;
123: gridBagConstraints.gridy = 1;
124: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
125: gridBagConstraints.insets = new java.awt.Insets(0, 12, 5, 11);
126: add(jLabel1, gridBagConstraints);
127:
128: methodCB.setText(getBundleString("CFEP_Method"));
129: methodCB.addItemListener(new java.awt.event.ItemListener() {
130: public void itemStateChanged(java.awt.event.ItemEvent evt) {
131: methodCBItemStateChanged(evt);
132: }
133: });
134:
135: gridBagConstraints = new java.awt.GridBagConstraints();
136: gridBagConstraints.gridx = 0;
137: gridBagConstraints.gridy = 2;
138: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
139: gridBagConstraints.insets = new java.awt.Insets(0, 24, 0, 0);
140: add(methodCB, gridBagConstraints);
141:
142: innerCB.setText(getBundleString("CFEP_InnerClass"));
143: innerCB.addItemListener(new java.awt.event.ItemListener() {
144: public void itemStateChanged(java.awt.event.ItemEvent evt) {
145: innerCBItemStateChanged(evt);
146: }
147: });
148:
149: gridBagConstraints = new java.awt.GridBagConstraints();
150: gridBagConstraints.gridx = 0;
151: gridBagConstraints.gridy = 3;
152: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
153: gridBagConstraints.insets = new java.awt.Insets(0, 24, 0, 0);
154: add(innerCB, gridBagConstraints);
155:
156: importCB.setText(getBundleString("CFEP_Import"));
157: importCB.addItemListener(new java.awt.event.ItemListener() {
158: public void itemStateChanged(java.awt.event.ItemEvent evt) {
159: importCBItemStateChanged(evt);
160: }
161: });
162:
163: gridBagConstraints = new java.awt.GridBagConstraints();
164: gridBagConstraints.gridx = 0;
165: gridBagConstraints.gridy = 4;
166: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
167: gridBagConstraints.insets = new java.awt.Insets(0, 24, 0, 0);
168: add(importCB, gridBagConstraints);
169:
170: javadocCB.setText(getBundleString("CFEP_Javadoc"));
171: javadocCB.addItemListener(new java.awt.event.ItemListener() {
172: public void itemStateChanged(java.awt.event.ItemEvent evt) {
173: javadocCBItemStateChanged(evt);
174: }
175: });
176:
177: gridBagConstraints = new java.awt.GridBagConstraints();
178: gridBagConstraints.gridx = 0;
179: gridBagConstraints.gridy = 5;
180: gridBagConstraints.insets = new java.awt.Insets(0, 24, 0, 0);
181: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
182: add(javadocCB, gridBagConstraints);
183:
184: initialCommentCB
185: .setText(getBundleString("CFEP_InitialComment"));
186: initialCommentCB
187: .addItemListener(new java.awt.event.ItemListener() {
188: public void itemStateChanged(
189: java.awt.event.ItemEvent evt) {
190: initialCommentCBItemStateChanged(evt);
191: }
192: });
193:
194: gridBagConstraints = new java.awt.GridBagConstraints();
195: gridBagConstraints.gridx = 0;
196: gridBagConstraints.gridy = 6;
197: gridBagConstraints.insets = new java.awt.Insets(0, 24, 0, 0);
198: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
199: add(initialCommentCB, gridBagConstraints);
200:
201: }//GEN-END:initComponents
202:
203: private void initialCommentCBItemStateChanged(
204: java.awt.event.ItemEvent evt) {//GEN-FIRST:event_initialCommentCBItemStateChanged
205: notifyEditor();
206: }//GEN-LAST:event_initialCommentCBItemStateChanged
207:
208: private void javadocCBItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_javadocCBItemStateChanged
209: notifyEditor();
210: }//GEN-LAST:event_javadocCBItemStateChanged
211:
212: private void importCBItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_importCBItemStateChanged
213: notifyEditor();
214: }//GEN-LAST:event_importCBItemStateChanged
215:
216: private void innerCBItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_innerCBItemStateChanged
217: notifyEditor();
218: }//GEN-LAST:event_innerCBItemStateChanged
219:
220: private void methodCBItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_methodCBItemStateChanged
221: notifyEditor();
222: }//GEN-LAST:event_methodCBItemStateChanged
223:
224: private void checkBoxChange(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_checkBoxChange
225: setCBoxesEnabled(evt.getStateChange() == ItemEvent.SELECTED);
226: notifyEditor();
227: }//GEN-LAST:event_checkBoxChange
228:
229: private void notifyEditor() {
230: if (foldingEditor != null)
231: foldingEditor.customEditorChange();
232: }
233:
234: private void setCBoxesEnabled(boolean selected) {
235: methodCB.setEnabled(selected);
236: innerCB.setEnabled(selected);
237: importCB.setEnabled(selected);
238: javadocCB.setEnabled(selected);
239: initialCommentCB.setEnabled(selected);
240: }
241:
242: /**
243: * Fill in editor with initial values
244: */
245: public void setValue(Map m) {
246:
247: Boolean val = (Boolean) m
248: .get(SettingsNames.CODE_FOLDING_ENABLE);
249: if (val.booleanValue() == false) {
250: setCBoxesEnabled(false);
251: }
252: enableFoldingCB.setSelected(val.booleanValue());
253:
254: System.err.println("Not yet storing settings");
255: // val = (Boolean)m.get(JavaSettingsNames.CODE_FOLDING_COLLAPSE_METHOD);
256: // methodCB.setSelected(val.booleanValue());
257: //
258: // val = (Boolean)m.get(JavaSettingsNames.CODE_FOLDING_COLLAPSE_INNERCLASS);
259: // innerCB.setSelected(val.booleanValue());
260: //
261: // val = (Boolean)m.get(JavaSettingsNames.CODE_FOLDING_COLLAPSE_IMPORT);
262: // importCB.setSelected(val.booleanValue());
263: //
264: // val = (Boolean)m.get(JavaSettingsNames.CODE_FOLDING_COLLAPSE_JAVADOC);
265: // javadocCB.setSelected(val.booleanValue());
266: //
267: // val = (Boolean)m.get(JavaSettingsNames.CODE_FOLDING_COLLAPSE_INITIAL_COMMENT);
268: // initialCommentCB.setSelected(val.booleanValue());
269:
270: }
271:
272: /**
273: * Take the result of users modifications
274: */
275: public Map getValue() {
276: Map ret = new HashMap(10);
277: System.err.println("Not yet storing settings");
278: // ret.put(SettingsNames.CODE_FOLDING_ENABLE, Boolean.valueOf(enableFoldingCB.isSelected()));
279: // ret.put(JavaSettingsNames.CODE_FOLDING_COLLAPSE_METHOD, Boolean.valueOf(methodCB.isSelected()));
280: // ret.put(JavaSettingsNames.CODE_FOLDING_COLLAPSE_INNERCLASS, Boolean.valueOf(innerCB.isSelected()));
281: // ret.put(JavaSettingsNames.CODE_FOLDING_COLLAPSE_IMPORT, Boolean.valueOf(importCB.isSelected()));
282: // ret.put(JavaSettingsNames.CODE_FOLDING_COLLAPSE_JAVADOC, Boolean.valueOf(javadocCB.isSelected()));
283: // ret.put(JavaSettingsNames.CODE_FOLDING_COLLAPSE_INITIAL_COMMENT, Boolean.valueOf(initialCommentCB.isSelected()));
284: return ret;
285: }
286:
287: private String getBundleString(String s) {
288: return NbBundle.getMessage(CodeFoldingEditorPanel.class, s);
289: }
290:
291: // Variables declaration - do not modify//GEN-BEGIN:variables
292: private javax.swing.JCheckBox enableFoldingCB;
293: private javax.swing.JCheckBox importCB;
294: private javax.swing.JCheckBox initialCommentCB;
295: private javax.swing.JCheckBox innerCB;
296: private javax.swing.JLabel jLabel1;
297: private javax.swing.JCheckBox javadocCB;
298: private javax.swing.JCheckBox methodCB;
299: // End of variables declaration//GEN-END:variables
300:
301: }
|