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.options.generaleditor;
043:
044: import java.awt.Component;
045: import java.awt.event.ActionEvent;
046: import java.awt.event.ActionListener;
047: import javax.swing.AbstractButton;
048: import javax.swing.JLabel;
049: import javax.swing.JPanel;
050: import org.openide.awt.Mnemonics;
051: import org.openide.util.NbBundle;
052:
053: /**
054: * Implementation of one panel in Options Dialog.
055: *
056: * @author Jan Jancura
057: */
058: public class GeneralEditorPanel extends JPanel implements
059: ActionListener {
060:
061: private boolean changed = false;
062: private boolean listen = false;
063:
064: /**
065: * Creates new form GeneralEditorPanel.
066: */
067: public GeneralEditorPanel() {
068: initComponents();
069:
070: setName(loc("General_Tab"));
071:
072: loc(lCodeFolding, "Code_Folding");
073: loc(lUseCodeFolding, "Code_Folding_Section");
074: loc(lCollapseByDefault, "Fold_by_Default");
075: loc(lCodeCompletion, "Code_Completion");
076: loc(lCodeCompletion2, "Code_Completion_Section");
077:
078: loc(cbUseCodeFolding, "Use_Folding");
079: loc(cbFoldMethods, "Fold_Methods");
080: loc(cbFoldInnerClasses, "Fold_Classes");
081: loc(cbFoldImports, "Fold_Imports");
082: loc(cbFoldJavadocComments, "Fold_JavaDoc");
083: loc(cbFoldInitialComments, "Fold_Licence");
084:
085: loc(cbAutoPopup, "Auto_Popup_Completion_Window");
086: loc(cbInsertSingleProposalsAutomatically,
087: "Insert_Single_Proposals_Automatically");
088: loc(cbCaseSensitive, "Case_Sensitive_Code_Completion");
089: loc(cbShowDeprecated, "Show_Deprecated_Members");
090: loc(cbInsertClosingBracketsAutomatically,
091: "Pair_Character_Completion");
092:
093: loc(lCamelCaseBehavior, "Camel_Case_Behavior");
094: loc(cbCamelCaseBehavior, "Enable_Camel_Case_In_Java");
095: loc(lCamelCaseBehaviorExample, "Camel_Case_Behavior_Example");
096:
097: }
098:
099: /** This method is called from within the constructor to
100: * initialize the form.
101: * WARNING: Do NOT modify this code. The content of this method is
102: * always regenerated by the Form Editor.
103: */
104: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
105: private void initComponents() {
106:
107: lCodeFolding = new javax.swing.JLabel();
108: lUseCodeFolding = new javax.swing.JLabel();
109: lCollapseByDefault = new javax.swing.JLabel();
110: cbUseCodeFolding = new javax.swing.JCheckBox();
111: cbFoldMethods = new javax.swing.JCheckBox();
112: cbFoldInnerClasses = new javax.swing.JCheckBox();
113: cbFoldImports = new javax.swing.JCheckBox();
114: cbFoldJavadocComments = new javax.swing.JCheckBox();
115: cbFoldInitialComments = new javax.swing.JCheckBox();
116: lCodeCompletion = new javax.swing.JLabel();
117: jSeparator2 = new javax.swing.JSeparator();
118: lCodeCompletion2 = new javax.swing.JLabel();
119: cbAutoPopup = new javax.swing.JCheckBox();
120: cbInsertSingleProposalsAutomatically = new javax.swing.JCheckBox();
121: cbCaseSensitive = new javax.swing.JCheckBox();
122: cbShowDeprecated = new javax.swing.JCheckBox();
123: cbInsertClosingBracketsAutomatically = new javax.swing.JCheckBox();
124: jSeparator1 = new javax.swing.JSeparator();
125: lCamelCaseBehavior = new javax.swing.JLabel();
126: jSeparator3 = new javax.swing.JSeparator();
127: cbCamelCaseBehavior = new javax.swing.JCheckBox();
128: lCamelCaseBehaviorExample = new javax.swing.JLabel();
129:
130: setForeground(new java.awt.Color(99, 130, 191));
131:
132: lCodeFolding.setText("Code Folding");
133:
134: lUseCodeFolding.setText("Use Code Folding:");
135:
136: lCollapseByDefault.setText("Collapse by Default:");
137:
138: cbUseCodeFolding.setBorder(javax.swing.BorderFactory
139: .createEmptyBorder(0, 0, 0, 0));
140: cbUseCodeFolding.setMargin(new java.awt.Insets(0, 0, 0, 0));
141:
142: cbFoldMethods.setText("Methods");
143: cbFoldMethods.setBorder(javax.swing.BorderFactory
144: .createEmptyBorder(0, 0, 0, 0));
145: cbFoldMethods.setMargin(new java.awt.Insets(0, 0, 0, 0));
146:
147: cbFoldInnerClasses.setText("Inner Classes");
148: cbFoldInnerClasses.setBorder(javax.swing.BorderFactory
149: .createEmptyBorder(0, 0, 0, 0));
150: cbFoldInnerClasses.setMargin(new java.awt.Insets(0, 0, 0, 0));
151:
152: cbFoldImports.setText("Imports");
153: cbFoldImports.setBorder(javax.swing.BorderFactory
154: .createEmptyBorder(0, 0, 0, 0));
155: cbFoldImports.setMargin(new java.awt.Insets(0, 0, 0, 0));
156:
157: cbFoldJavadocComments.setText("Javadoc Comments");
158: cbFoldJavadocComments.setBorder(javax.swing.BorderFactory
159: .createEmptyBorder(0, 0, 0, 0));
160: cbFoldJavadocComments
161: .setMargin(new java.awt.Insets(0, 0, 0, 0));
162:
163: cbFoldInitialComments.setText("Initial Comments");
164: cbFoldInitialComments.setBorder(javax.swing.BorderFactory
165: .createEmptyBorder(0, 0, 0, 0));
166: cbFoldInitialComments
167: .setMargin(new java.awt.Insets(0, 0, 0, 0));
168:
169: lCodeCompletion.setText("Code Completion");
170:
171: lCodeCompletion2.setText("Code Completion:");
172:
173: cbAutoPopup.setText("Auto Popup Code Completion Window");
174: cbAutoPopup.setBorder(javax.swing.BorderFactory
175: .createEmptyBorder(0, 0, 0, 0));
176: cbAutoPopup.setMargin(new java.awt.Insets(0, 0, 0, 0));
177:
178: cbInsertSingleProposalsAutomatically
179: .setText("Insert Single Proposals Automatically");
180: cbInsertSingleProposalsAutomatically
181: .setBorder(javax.swing.BorderFactory.createEmptyBorder(
182: 0, 0, 0, 0));
183: cbInsertSingleProposalsAutomatically
184: .setMargin(new java.awt.Insets(0, 0, 0, 0));
185:
186: cbCaseSensitive.setText("Case Sensitive Code Completion");
187: cbCaseSensitive.setBorder(javax.swing.BorderFactory
188: .createEmptyBorder(0, 0, 0, 0));
189: cbCaseSensitive.setMargin(new java.awt.Insets(0, 0, 0, 0));
190:
191: cbShowDeprecated
192: .setText("Show Deprecated Members In Code Completion");
193: cbShowDeprecated.setBorder(javax.swing.BorderFactory
194: .createEmptyBorder(0, 0, 0, 0));
195: cbShowDeprecated.setMargin(new java.awt.Insets(0, 0, 0, 0));
196:
197: cbInsertClosingBracketsAutomatically
198: .setText("Insert Closing Brackets Automatically");
199: cbInsertClosingBracketsAutomatically
200: .setBorder(javax.swing.BorderFactory.createEmptyBorder(
201: 0, 0, 0, 0));
202: cbInsertClosingBracketsAutomatically
203: .setMargin(new java.awt.Insets(0, 0, 0, 0));
204:
205: lCamelCaseBehavior.setText("Camel Case Behavior");
206:
207: cbCamelCaseBehavior
208: .setText("Enable Camel Case Navigation For Java");
209: cbCamelCaseBehavior.setBorder(javax.swing.BorderFactory
210: .createEmptyBorder(0, 0, 0, 0));
211: cbCamelCaseBehavior.setMargin(new java.awt.Insets(0, 0, 0, 0));
212:
213: lCamelCaseBehaviorExample
214: .setText("(Example: Caret stops at J, T, N in \"JavaTypeName\" when using next/previous word acctions)");
215: lCamelCaseBehaviorExample.setEnabled(false);
216:
217: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
218: this );
219: this .setLayout(layout);
220: layout
221: .setHorizontalGroup(layout
222: .createParallelGroup(
223: org.jdesktop.layout.GroupLayout.LEADING)
224: .add(
225: layout
226: .createSequentialGroup()
227: .add(
228: layout
229: .createParallelGroup(
230: org.jdesktop.layout.GroupLayout.LEADING)
231: .add(
232: layout
233: .createSequentialGroup()
234: .addContainerGap()
235: .add(
236: layout
237: .createParallelGroup(
238: org.jdesktop.layout.GroupLayout.LEADING)
239: .add(
240: lUseCodeFolding)
241: .add(
242: lCodeCompletion2)
243: .add(
244: lCollapseByDefault)))
245: .add(
246: lCamelCaseBehavior))
247: .addPreferredGap(
248: org.jdesktop.layout.LayoutStyle.RELATED)
249: .add(
250: layout
251: .createParallelGroup(
252: org.jdesktop.layout.GroupLayout.LEADING)
253: .add(
254: cbCamelCaseBehavior)
255: .add(
256: cbInsertClosingBracketsAutomatically)
257: .add(
258: cbShowDeprecated)
259: .add(
260: cbCaseSensitive)
261: .add(
262: cbInsertSingleProposalsAutomatically)
263: .add(
264: cbAutoPopup)
265: .add(
266: cbFoldInitialComments)
267: .add(
268: cbFoldJavadocComments)
269: .add(
270: cbFoldImports)
271: .add(
272: cbFoldInnerClasses)
273: .add(
274: cbFoldMethods)
275: .add(
276: cbUseCodeFolding))
277: .addContainerGap(391,
278: Short.MAX_VALUE))
279: .add(
280: layout.createSequentialGroup().add(138,
281: 138, 138).add(
282: lCamelCaseBehaviorExample)
283: .addContainerGap(168,
284: Short.MAX_VALUE))
285: .add(
286: layout
287: .createSequentialGroup()
288: .add(116, 116, 116)
289: .add(
290: jSeparator3,
291: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
292: 641, Short.MAX_VALUE))
293: .add(
294: layout
295: .createSequentialGroup()
296: .add(lCodeCompletion)
297: .addPreferredGap(
298: org.jdesktop.layout.LayoutStyle.RELATED)
299: .add(
300: jSeparator2,
301: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
302: 664, Short.MAX_VALUE))
303: .add(
304: layout
305: .createSequentialGroup()
306: .add(lCodeFolding)
307: .addPreferredGap(
308: org.jdesktop.layout.LayoutStyle.RELATED)
309: .add(
310: jSeparator1,
311: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
312: 683, Short.MAX_VALUE)));
313: layout
314: .setVerticalGroup(layout
315: .createParallelGroup(
316: org.jdesktop.layout.GroupLayout.LEADING)
317: .add(
318: layout
319: .createSequentialGroup()
320: .addContainerGap()
321: .add(
322: layout
323: .createParallelGroup(
324: org.jdesktop.layout.GroupLayout.TRAILING)
325: .add(
326: lCodeFolding)
327: .add(
328: jSeparator1,
329: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
330: 10,
331: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
332: .addPreferredGap(
333: org.jdesktop.layout.LayoutStyle.RELATED)
334: .add(
335: layout
336: .createParallelGroup(
337: org.jdesktop.layout.GroupLayout.BASELINE)
338: .add(
339: lUseCodeFolding)
340: .add(
341: cbUseCodeFolding))
342: .addPreferredGap(
343: org.jdesktop.layout.LayoutStyle.RELATED)
344: .add(
345: layout
346: .createParallelGroup(
347: org.jdesktop.layout.GroupLayout.BASELINE)
348: .add(
349: lCollapseByDefault)
350: .add(
351: cbFoldMethods))
352: .addPreferredGap(
353: org.jdesktop.layout.LayoutStyle.RELATED)
354: .add(cbFoldInnerClasses)
355: .addPreferredGap(
356: org.jdesktop.layout.LayoutStyle.RELATED)
357: .add(cbFoldImports)
358: .addPreferredGap(
359: org.jdesktop.layout.LayoutStyle.RELATED)
360: .add(cbFoldJavadocComments)
361: .addPreferredGap(
362: org.jdesktop.layout.LayoutStyle.RELATED)
363: .add(cbFoldInitialComments)
364: .add(8, 8, 8)
365: .add(
366: layout
367: .createParallelGroup(
368: org.jdesktop.layout.GroupLayout.TRAILING)
369: .add(
370: lCodeCompletion)
371: .add(
372: jSeparator2,
373: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
374: 10,
375: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
376: .addPreferredGap(
377: org.jdesktop.layout.LayoutStyle.RELATED)
378: .add(
379: layout
380: .createParallelGroup(
381: org.jdesktop.layout.GroupLayout.TRAILING)
382: .add(
383: lCodeCompletion2)
384: .add(
385: cbAutoPopup))
386: .addPreferredGap(
387: org.jdesktop.layout.LayoutStyle.RELATED)
388: .add(
389: cbInsertSingleProposalsAutomatically)
390: .addPreferredGap(
391: org.jdesktop.layout.LayoutStyle.RELATED)
392: .add(cbCaseSensitive)
393: .addPreferredGap(
394: org.jdesktop.layout.LayoutStyle.RELATED)
395: .add(cbShowDeprecated)
396: .addPreferredGap(
397: org.jdesktop.layout.LayoutStyle.RELATED)
398: .add(
399: cbInsertClosingBracketsAutomatically)
400: .addPreferredGap(
401: org.jdesktop.layout.LayoutStyle.RELATED)
402: .add(
403: layout
404: .createParallelGroup(
405: org.jdesktop.layout.GroupLayout.TRAILING)
406: .add(
407: lCamelCaseBehavior)
408: .add(
409: jSeparator3,
410: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
411: 10,
412: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
413: .addPreferredGap(
414: org.jdesktop.layout.LayoutStyle.RELATED)
415: .add(cbCamelCaseBehavior)
416: .addPreferredGap(
417: org.jdesktop.layout.LayoutStyle.RELATED)
418: .add(lCamelCaseBehaviorExample)
419: .addContainerGap(13,
420: Short.MAX_VALUE)));
421: }// </editor-fold>//GEN-END:initComponents
422:
423: // Variables declaration - do not modify//GEN-BEGIN:variables
424: private javax.swing.JCheckBox cbAutoPopup;
425: private javax.swing.JCheckBox cbCamelCaseBehavior;
426: private javax.swing.JCheckBox cbCaseSensitive;
427: private javax.swing.JCheckBox cbFoldImports;
428: private javax.swing.JCheckBox cbFoldInitialComments;
429: private javax.swing.JCheckBox cbFoldInnerClasses;
430: private javax.swing.JCheckBox cbFoldJavadocComments;
431: private javax.swing.JCheckBox cbFoldMethods;
432: private javax.swing.JCheckBox cbInsertClosingBracketsAutomatically;
433: private javax.swing.JCheckBox cbInsertSingleProposalsAutomatically;
434: private javax.swing.JCheckBox cbShowDeprecated;
435: private javax.swing.JCheckBox cbUseCodeFolding;
436: private javax.swing.JSeparator jSeparator1;
437: private javax.swing.JSeparator jSeparator2;
438: private javax.swing.JSeparator jSeparator3;
439: private javax.swing.JLabel lCamelCaseBehavior;
440: private javax.swing.JLabel lCamelCaseBehaviorExample;
441: private javax.swing.JLabel lCodeCompletion;
442: private javax.swing.JLabel lCodeCompletion2;
443: private javax.swing.JLabel lCodeFolding;
444: private javax.swing.JLabel lCollapseByDefault;
445: private javax.swing.JLabel lUseCodeFolding;
446:
447: // End of variables declaration//GEN-END:variables
448:
449: private static String loc(String key) {
450: return NbBundle.getMessage(GeneralEditorPanel.class, key);
451: }
452:
453: private static void loc(Component c, String key) {
454: if (!(c instanceof JLabel)) {
455: c.getAccessibleContext()
456: .setAccessibleName(loc("AN_" + key));
457: c.getAccessibleContext().setAccessibleDescription(
458: loc("AD_" + key));
459: }
460: if (c instanceof AbstractButton) {
461: Mnemonics.setLocalizedText((AbstractButton) c, loc("CTL_"
462: + key));
463: } else {
464: Mnemonics.setLocalizedText((JLabel) c, loc("CTL_" + key));
465: }
466: }
467:
468: private Model model;
469:
470: void update() {
471: listen = false;
472: if (model == null) {
473: model = new Model();
474: cbUseCodeFolding.addActionListener(this );
475: cbFoldMethods.addActionListener(this );
476: cbFoldInnerClasses.addActionListener(this );
477: cbFoldImports.addActionListener(this );
478: cbFoldJavadocComments.addActionListener(this );
479: cbFoldInitialComments.addActionListener(this );
480: cbAutoPopup.addActionListener(this );
481: cbInsertSingleProposalsAutomatically
482: .addActionListener(this );
483: cbCaseSensitive.addActionListener(this );
484: cbShowDeprecated.addActionListener(this );
485: cbInsertClosingBracketsAutomatically
486: .addActionListener(this );
487: cbCamelCaseBehavior.addActionListener(this );
488: }
489:
490: // init code folding
491: cbUseCodeFolding.setSelected(model.isShowCodeFolding());
492: cbFoldImports.setSelected(model.isFoldImports());
493: cbFoldInitialComments.setSelected(model.isFoldInitialComment());
494: cbFoldInnerClasses.setSelected(model.isFoldInnerClasses());
495: cbFoldJavadocComments
496: .setSelected(model.isFoldJavaDocComments());
497: cbFoldMethods.setSelected(model.isFoldMethods());
498:
499: // code completion options
500: cbInsertClosingBracketsAutomatically.setSelected(model
501: .isPairCharacterCompletion());
502: cbAutoPopup.setSelected(model.isCompletionAutoPopup());
503: cbShowDeprecated.setSelected(model.isShowDeprecatedMembers());
504: cbInsertSingleProposalsAutomatically.setSelected(model
505: .isCompletionInstantSubstitution());
506: cbCaseSensitive.setSelected(model.isCompletionCaseSensitive());
507:
508: // Java Camel Case Navigation
509: Boolean ccJava = model.isCamelCaseJavaNavigation();
510: if (ccJava == null) {
511: cbCamelCaseBehavior.setEnabled(false);
512: cbCamelCaseBehavior.setSelected(false);
513: } else {
514: cbCamelCaseBehavior.setEnabled(true);
515: cbCamelCaseBehavior.setSelected(ccJava);
516: }
517:
518: updateEnabledState();
519:
520: listen = true;
521: }
522:
523: void applyChanges() {
524:
525: if (model == null || !changed)
526: return;
527:
528: // code folding options
529: model.setFoldingOptions(cbUseCodeFolding.isSelected(),
530: cbFoldImports.isSelected(), cbFoldInitialComments
531: .isSelected(), cbFoldInnerClasses.isSelected(),
532: cbFoldJavadocComments.isSelected(), cbFoldMethods
533: .isSelected());
534:
535: // code completion options
536: model.setCompletionOptions(cbInsertClosingBracketsAutomatically
537: .isSelected(), cbAutoPopup.isSelected(),
538: cbShowDeprecated.isSelected(),
539: cbInsertSingleProposalsAutomatically.isSelected(),
540: cbCaseSensitive.isSelected());
541:
542: // java camel case navigation
543: model.setCamelCaseNavigation(cbCamelCaseBehavior.isSelected());
544:
545: changed = false;
546: }
547:
548: void cancel() {
549: changed = false;
550: }
551:
552: boolean dataValid() {
553: return true;
554: }
555:
556: boolean isChanged() {
557: return changed;
558: }
559:
560: public void actionPerformed(ActionEvent e) {
561: if (!listen)
562: return;
563: if (e.getSource() == cbUseCodeFolding)
564: updateEnabledState();
565: changed = true;
566: }
567:
568: // other methods ...........................................................
569:
570: private void updateEnabledState() {
571: boolean useCodeFolding = cbUseCodeFolding.isSelected();
572: cbFoldImports.setEnabled(useCodeFolding);
573: cbFoldInitialComments.setEnabled(useCodeFolding);
574: cbFoldInnerClasses.setEnabled(useCodeFolding);
575: cbFoldJavadocComments.setEnabled(useCodeFolding);
576: cbFoldMethods.setEnabled(useCodeFolding);
577: }
578: }
|