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.form;
043:
044: import java.awt.Color;
045: import java.util.*;
046: import java.util.prefs.Preferences;
047: import org.openide.util.HelpCtx;
048: import org.netbeans.modules.form.codestructure.*;
049: import org.openide.nodes.BeanNode;
050: import org.openide.util.NbPreferences;
051:
052: /**
053: * Settings for the form editor.
054: */
055: public class FormLoaderSettings implements HelpCtx.Provider {
056: private static final FormLoaderSettings INSTANCE = new FormLoaderSettings();
057: public static final String PROP_USE_INDENT_ENGINE = "useIndentEngine"; // NOI18N
058:
059: /** Property name of the eventVariableName property */
060: public static final String PROP_EVENT_VARIABLE_NAME = "eventVariableName"; // NOI18N
061:
062: /** Property name of the event listener code generation style option. */
063: public static final String PROP_LISTENER_GENERATION_STYLE = "listenerGenerationStyle"; // NOI18N
064:
065: /** Property name of the selectionBorderSize property */
066: public static final String PROP_SELECTION_BORDER_SIZE = "selectionBorderSize"; // NOI18N
067: /** Property name of the selectionBorderColor property */
068: public static final String PROP_SELECTION_BORDER_COLOR = "selectionBorderColor"; // NOI18N
069: /** Property name of the connectionBorderColor property */
070: public static final String PROP_CONNECTION_BORDER_COLOR = "connectionBorderColor"; // NOI18N
071: /** Property name of the dragBorderColor property */
072: public static final String PROP_DRAG_BORDER_COLOR = "dragBorderColor"; // NOI18N
073: /** Property name of the guidingLineColor property */
074: public static final String PROP_GUIDING_LINE_COLOR = "guidingLineColor"; // NOI18N
075: /** Property name of the formDesignerBackgroundColor property */
076: public static final String PROP_FORMDESIGNER_BACKGROUND_COLOR = "formDesignerBackgroundColor"; // NOI18N
077: /** Property name of the formDesignerBorderColor property */
078: public static final String PROP_FORMDESIGNER_BORDER_COLOR = "formDesignerBorderColor"; // NOI18N
079:
080: /** Property name of the gridX property */
081: public static final String PROP_GRID_X = "gridX"; // NOI18N
082: /** Property name of the gridY property */
083: public static final String PROP_GRID_Y = "gridY"; // NOI18N
084: /** Property name of the applyGridToPosition property */
085: public static final String PROP_APPLY_GRID_TO_POSITION = "applyGridToPosition"; // NOI18N
086: /** Property name of the applyGridToSize property */
087: public static final String PROP_APPLY_GRID_TO_SIZE = "applyGridToSize"; // NOI18N
088:
089: /** Property name of the variablesModifier property */
090: public static final String PROP_VARIABLES_MODIFIER = "variablesModifier"; // NOI18N
091: /** Property name of the variablesLocal property */
092: public static final String PROP_VARIABLES_LOCAL = "variablesLocal"; // NOI18N
093:
094: /** Property name of the autoSetComponentName property */
095: public static final String PROP_AUTO_SET_COMPONENT_NAME = "autoSetComponentName"; // NOI18N
096: static final int AUTO_NAMING_DEFAULT = 0;
097: static final int AUTO_NAMING_ON = 1;
098: static final int AUTO_NAMING_OFF = 2;
099:
100: /** Property name of the generateMnemonicsCode property */
101: public static final String PROP_GENERATE_MNEMONICS = "generateMnemonicsCode"; // NOI18N
102: /** Property name of the showMnemonicsDialog property */
103: public static final String PROP_SHOW_MNEMONICS_DIALOG = "showMnemonicsDialog"; // NOI18N
104:
105: /** Property name of the displayWritableOnly property */
106: public static final String PROP_DISPLAY_WRITABLE_ONLY = "displayWritableOnly"; // NOI18N
107:
108: /** Property name of the editorSearchPath property */
109: public static final String PROP_EDITOR_SEARCH_PATH = "editorSearchPath"; // NOI18N
110:
111: /** Property name of the toolBarPalette property */
112: public static final String PROP_PALETTE_IN_TOOLBAR = "toolBarPalette"; // NOI18N
113: /** Property name of the foldGeneratedCode property. */
114: public static final String PROP_FOLD_GENERATED_CODE = "foldGeneratedCode"; // NOI18N
115: /** Property name of the assistantShown property. */
116: public static final String PROP_ASSISTANT_SHOWN = "assistantShown"; // NOI18N
117: /** Property name of the designerLAF property. */
118: public static final String PROP_DESIGNER_LAF = "designerLAF"; // NOI18N
119:
120: /** Property name of the layout code target property. */
121: public static final String PROP_LAYOUT_CODE_TARGET = "layoutCodeTarget"; // NOI18N
122:
123: /** Name of the property for automatic resources/i18n management.
124: * The name refers only to i18n for compatibility reasons. */
125: public static final String PROP_AUTO_RESOURCING = "i18nAutoMode"; // NOI18N
126: static final int AUTO_RESOURCE_DEFAULT = 0;
127: static final int AUTO_RESOURCE_ON = 1;
128: static final int AUTO_RESOURCE_OFF = 2;
129: // public static final String PROP_CONTAINER_BEANS = "containerBeans"; // NOI18N
130:
131: // ------------------------------------------
132: /** The color of the drag border on selection border */
133: private static java.awt.Color dragBorderColor = java.awt.Color.gray;
134: /** Indicates whether to display automatically hint dialog advertising the
135: * Mnemonics generation feature. */
136: private static boolean showMnemonicsDialog = true;
137: /** Array of package names to search for property editors used in Form Editor */
138: private static String[] editorSearchPath = null;
139: /** Array of items [Class Name, Editor1, Editor2, ...] */
140: private static String[][] registeredEditors;
141: private static final int MIN_SELECTION_BORDER_SIZE = 1;
142: private static final int MAX_SELECTION_BORDER_SIZE = 15;
143:
144: private static final int MIN_GRID_X = 2;
145: private static final int MIN_GRID_Y = 2;
146:
147: // private static Map containerBeans;
148:
149: // --------
150:
151: public static final Preferences getPreferences() {
152: return NbPreferences.forModule(FormLoaderSettings.class);
153: }
154:
155: public static FormLoaderSettings getInstance() {
156: return INSTANCE;
157: }
158:
159: // ------------------------------------------
160: // property access methods
161:
162: public boolean getUseIndentEngine() {
163: return getPreferences().getBoolean(PROP_USE_INDENT_ENGINE,
164: false);
165: }
166:
167: public void setUseIndentEngine(boolean value) {
168: getPreferences().putBoolean(PROP_USE_INDENT_ENGINE, value);
169: }
170:
171: /**
172: * Returns event variable name.
173: *
174: * @return event variable name.
175: */
176: public String getEventVariableName() {
177: return getPreferences().get(PROP_EVENT_VARIABLE_NAME, "evt");
178: }
179:
180: /**
181: * Sets event variable name.
182: *
183: * @param value event variable name.
184: */
185: public void setEventVariableName(String value) {
186: getPreferences().put(PROP_EVENT_VARIABLE_NAME, value);
187: }
188:
189: /**
190: * Getter for the event listener code generation style option.
191: *
192: * @return listener generation style.
193: */
194: public int getListenerGenerationStyle() {
195: return getPreferences().getInt(PROP_LISTENER_GENERATION_STYLE,
196: 0);
197: }
198:
199: /**
200: * Setter for the event listener code generation style option.
201: *
202: * @param style listener generation style.
203: */
204: public void setListenerGenerationStyle(int style) {
205: getPreferences().putInt(PROP_LISTENER_GENERATION_STYLE, style);
206: }
207:
208: /**
209: * Getter for the selectionBorderSize option.
210: *
211: * @return selection border size.
212: */
213: public int getSelectionBorderSize() {
214: return getPreferences().getInt(PROP_SELECTION_BORDER_SIZE, 1);
215: }
216:
217: /**
218: * Setter for the selectionBorderSize option.
219: *
220: * @param value selection border size.
221: */
222: public void setSelectionBorderSize(int value) {
223: if (value < MIN_SELECTION_BORDER_SIZE)
224: value = MIN_SELECTION_BORDER_SIZE;
225: else if (value > MAX_SELECTION_BORDER_SIZE)
226: value = MAX_SELECTION_BORDER_SIZE;
227:
228: getPreferences().putInt(PROP_SELECTION_BORDER_SIZE, value);
229: }
230:
231: /**
232: * Getter for the selectionBorderColor option.
233: *
234: * @return color of selection border.
235: */
236: public java.awt.Color getSelectionBorderColor() {
237: int rgb = getPreferences().getInt(PROP_SELECTION_BORDER_COLOR,
238: new Color(255, 164, 0).getRGB());
239: return new Color(rgb);
240: }
241:
242: /**
243: * Setter for the selectionBorderColor option
244: *
245: * @param value color of selection border.
246: */
247: public void setSelectionBorderColor(java.awt.Color value) {
248: if (value == null) {
249: return;
250: }
251: getPreferences().putInt(PROP_SELECTION_BORDER_COLOR,
252: value.getRGB());
253: }
254:
255: /**
256: * Getter for the connectionBorderColor option.
257: *
258: * @return color of connection border.
259: */
260: public java.awt.Color getConnectionBorderColor() {
261: int rgb = getPreferences().getInt(PROP_CONNECTION_BORDER_COLOR,
262: Color.red.getRGB());
263: return new Color(rgb);
264: }
265:
266: /**
267: * Setter for the connectionBorderColor option.
268: *
269: * @param value color of connection border.
270: */
271: public void setConnectionBorderColor(java.awt.Color value) {
272: if (value == null) {
273: return;
274: }
275: getPreferences().putInt(PROP_CONNECTION_BORDER_COLOR,
276: value.getRGB());
277: }
278:
279: /**
280: * Getter for the dragBorderColor option.
281: *
282: * @return color of drag border.
283: */
284: public java.awt.Color getDragBorderColor() {
285: int rgb = getPreferences().getInt(PROP_DRAG_BORDER_COLOR,
286: Color.gray.getRGB());
287: return new Color(rgb);
288: }
289:
290: /**
291: * Setter for the dragBorderColor option.
292: *
293: * @param value color of drag border.
294: */
295: public void setDragBorderColor(java.awt.Color value) {
296: if (value == null) {
297: return;
298: }
299: getPreferences().putInt(PROP_DRAG_BORDER_COLOR, value.getRGB());
300: }
301:
302: /**
303: * Getter for the guidingLineColor option.
304: *
305: * @return color of guiding lines.
306: */
307: public java.awt.Color getGuidingLineColor() {
308: int rgb = getPreferences().getInt(PROP_GUIDING_LINE_COLOR,
309: new Color(143, 171, 196).getRGB());
310: return new Color(rgb);
311:
312: }
313:
314: /**
315: * Setter for the dragBorderColor option.
316: *
317: * @param value color of guiding lines.
318: */
319: public void setGuidingLineColor(java.awt.Color value) {
320: if (value == null) {
321: return;
322: }
323: getPreferences()
324: .putInt(PROP_GUIDING_LINE_COLOR, value.getRGB());
325: }
326:
327: /**
328: * Getter for the gridX option.
329: *
330: * @return size of horizontal grid.
331: */
332: public int getGridX() {
333: return getPreferences().getInt(PROP_GRID_X, 10);
334: }
335:
336: /**
337: * Setter for the gridX option.
338: *
339: * @param value size of horizontal grid.
340: */
341: public void setGridX(int value) {
342: if (value < MIN_GRID_X)
343: value = MIN_GRID_X;
344: getPreferences().putInt(PROP_GRID_X, value);
345: }
346:
347: /**
348: * Getter for the gridY option.
349: *
350: * @return size of vertical grid.
351: */
352: public int getGridY() {
353: return getPreferences().getInt(PROP_GRID_Y, 10);
354: }
355:
356: /**
357: * Setter for the gridY option.
358: *
359: * @param value size of vertical grid.
360: */
361: public void setGridY(int value) {
362: if (value < MIN_GRID_Y)
363: value = MIN_GRID_Y;
364: getPreferences().putInt(PROP_GRID_Y, value);
365: }
366:
367: /**
368: * Getter for the applyGridToPosition option.
369: *
370: * @return determines whether position of component should snap to grid.
371: */
372: public boolean getApplyGridToPosition() {
373: return getPreferences().getBoolean(PROP_APPLY_GRID_TO_POSITION,
374: true);
375: }
376:
377: /**
378: * Setter for the applyGridToPosition option.
379: *
380: * @param value determines whether position of component should snap to grid.
381: */
382: public void setApplyGridToPosition(boolean value) {
383: getPreferences().putBoolean(PROP_APPLY_GRID_TO_POSITION, value);
384: }
385:
386: /**
387: * Getter for the applyGridToSize option.
388: *
389: * @return determines whether size of component should snap to grid.
390: */
391: public boolean getApplyGridToSize() {
392: return getPreferences().getBoolean(PROP_APPLY_GRID_TO_SIZE,
393: true);
394:
395: }
396:
397: /**
398: * Setter for the applyGridToSize option.
399: *
400: * @param value determines whether size of component should snap to grid.
401: */
402: public void setApplyGridToSize(boolean value) {
403: getPreferences().putBoolean(PROP_APPLY_GRID_TO_SIZE, value);
404: }
405:
406: /**
407: * Getter for the variablesLocal option.
408: *
409: * @return determines whether variables should be local.
410: */
411: public boolean getVariablesLocal() {
412: return getPreferences().getBoolean(PROP_VARIABLES_LOCAL, false);
413: }
414:
415: /**
416: * Setter for the variablesLocal option.
417: *
418: * @param value determines whether variables should be local.
419: */
420: public void setVariablesLocal(boolean value) {
421: getPreferences().putBoolean(PROP_VARIABLES_LOCAL, value);
422: int variablesModifier = getVariablesModifier();
423: int varType = value ? CodeVariable.LOCAL
424: | (variablesModifier & CodeVariable.FINAL)
425: | CodeVariable.EXPLICIT_DECLARATION
426: : CodeVariable.FIELD | variablesModifier;
427:
428: if (value) {
429: variablesModifier &= CodeVariable.FINAL;
430: setVariablesModifier(variablesModifier);
431: }
432: }
433:
434: /**
435: * Getter for the variablesModifier option.
436: *
437: * @return variables modifier.
438: */
439: public int getVariablesModifier() {
440: return getPreferences().getInt(PROP_VARIABLES_MODIFIER,
441: java.lang.reflect.Modifier.PRIVATE);
442: }
443:
444: /**
445: * Setter for the variablesModifier option.
446: *
447: * @param value variables modifier.
448: */
449: public void setVariablesModifier(int value) {
450: getPreferences().putInt(PROP_VARIABLES_MODIFIER, value);
451:
452: int varType;
453: if (getVariablesLocal()) {
454: varType = CodeVariable.LOCAL | value;
455: if ((value & CodeVariable.FINAL) == 0)
456: varType |= CodeVariable.EXPLICIT_DECLARATION;
457: } else
458: varType = CodeVariable.FIELD | value;
459: }
460:
461: public int getAutoSetComponentName() {
462: return getPreferences().getInt(PROP_AUTO_SET_COMPONENT_NAME,
463: AUTO_NAMING_DEFAULT);
464: }
465:
466: public void setAutoSetComponentName(int value) {
467: getPreferences().putInt(PROP_AUTO_SET_COMPONENT_NAME, value);
468: }
469:
470: /**
471: * Getter for the generateMnemonicsCode option.
472: *
473: * @return determines whether to generate <code>Mnemonics</code> code.
474: */
475: public boolean getGenerateMnemonicsCode() {
476: return getPreferences().getBoolean(PROP_GENERATE_MNEMONICS,
477: false);
478: }
479:
480: /**
481: * Setter for the generateMnemonicsCode option.
482: *
483: * @param value determines whether to generate <code>Mnemonics</code> code.
484: */
485: public void setGenerateMnemonicsCode(boolean value) {
486: getPreferences().putBoolean(PROP_GENERATE_MNEMONICS, value);
487: }
488:
489: public boolean getDisplayWritableOnly() {
490: return getPreferences().getBoolean(PROP_DISPLAY_WRITABLE_ONLY,
491: true);
492: }
493:
494: public void setDisplayWritableOnly(boolean value) {
495: getPreferences().putBoolean(PROP_DISPLAY_WRITABLE_ONLY, value);
496: }
497:
498: /**
499: * Getter for the editorSearchPath option.
500: *
501: * @return property editor search path.
502: */
503: public String[] getEditorSearchPath() {
504: if (editorSearchPath == null) {
505: editorSearchPath = translatedEditorSearchPath(toArray(getPreferences()
506: .get(PROP_EDITOR_SEARCH_PATH,
507: "org.netbeans.modules.form.editors2 , org.netbeans.modules.swingapp"))); // NOI18N
508: }
509: return editorSearchPath;
510: }
511:
512: /**
513: * Setter for the editorSearchPath option.
514: *
515: * @param value property editor search path.
516: */
517: public void setEditorSearchPath(String[] value) {
518: editorSearchPath = value;
519: getPreferences().put(PROP_EDITOR_SEARCH_PATH,
520: fromArray(editorSearchPath));//NOI18N
521: }
522:
523: public boolean isPaletteInToolBar() {
524: return getPreferences().getBoolean(PROP_PALETTE_IN_TOOLBAR,
525: false);
526: }
527:
528: public void setPaletteInToolBar(boolean value) {
529: getPreferences().putBoolean(PROP_PALETTE_IN_TOOLBAR, value);
530: }
531:
532: /**
533: * Getter for the formDesignerBackgroundColor option.
534: *
535: * @return background color of the designer.
536: */
537: public java.awt.Color getFormDesignerBackgroundColor() {
538: int rgb = getPreferences().getInt(
539: PROP_FORMDESIGNER_BACKGROUND_COLOR,
540: Color.white.getRGB());
541: return new Color(rgb);
542:
543: }
544:
545: /**
546: * Setter for the formDesignerBackgroundColor option.
547: *
548: * @param value background color of the designer.
549: */
550: public void setFormDesignerBackgroundColor(java.awt.Color value) {
551: if (value == null)
552: return;
553: getPreferences().putInt(PROP_FORMDESIGNER_BACKGROUND_COLOR,
554: value.getRGB());
555: }
556:
557: /**
558: * Getter for the formDesignerBorderColor option.
559: *
560: * @return color of the border of the designer.
561: */
562: public java.awt.Color getFormDesignerBorderColor() {
563: int rgb = getPreferences().getInt(
564: PROP_FORMDESIGNER_BORDER_COLOR,
565: new Color(224, 224, 255).getRGB());
566: return new Color(rgb);
567:
568: }
569:
570: /**
571: * Setter for the formDesignerBorderColor option.
572: *
573: * @param value color of the border of the designer.
574: */
575: public void setFormDesignerBorderColor(java.awt.Color value) {
576: if (value == null)
577: return;
578: getPreferences().putInt(PROP_FORMDESIGNER_BORDER_COLOR,
579: value.getRGB());
580: }
581:
582: /**
583: * Getter for the foldGeneratedCode option
584: *
585: * @return <code>true</code> if the code should be folded,
586: * returns <code>false</code> otherwise.
587: */
588: public boolean getFoldGeneratedCode() {
589: return getPreferences().getBoolean(PROP_FOLD_GENERATED_CODE,
590: true);
591: }
592:
593: /**
594: * Setter for the foldGeneratedCode option.
595: *
596: * @param value determines whether the code should be folded.
597: */
598: public void setFoldGeneratedCode(boolean value) {
599: getPreferences().putBoolean(PROP_FOLD_GENERATED_CODE, value);
600: }
601:
602: /**
603: * Getter for the assistantShown option.
604: *
605: * @return <code>true</code> if the assistant should be shown,
606: * return <code>false</code> otherwise.
607: */
608: public boolean getAssistantShown() {
609: return getPreferences().getBoolean(PROP_ASSISTANT_SHOWN, true);
610: }
611:
612: /**
613: * Setter for the foldGeneratedCode option.
614: *
615: * @param value determines whether the assistant should be shown.
616: */
617: public void setAssistantShown(boolean value) {
618: getPreferences().putBoolean(PROP_ASSISTANT_SHOWN, value);
619: }
620:
621: public int getLayoutCodeTarget() {
622: return getPreferences().getInt(PROP_LAYOUT_CODE_TARGET, 0);
623: }
624:
625: public void setLayoutCodeTarget(int target) {
626: getPreferences().putInt(PROP_LAYOUT_CODE_TARGET, target);
627: }
628:
629: public int getI18nAutoMode() {
630: return getPreferences().getInt(PROP_AUTO_RESOURCING, 0);
631: }
632:
633: public void setI18nAutoMode(int mode) {
634: getPreferences().putInt(PROP_AUTO_RESOURCING, mode);
635: }
636:
637: private static String[] toArray(String esp) {
638: return esp.split(" , ");//NOI18N
639: }
640:
641: private static String fromArray(String[] items) {
642: StringBuffer sb = new StringBuffer();
643: for (int i = 0; i < items.length; i++) {
644: sb.append(items[i]);
645: if (i < items.length - 1) {
646: sb.append(" , ");//NOI18N
647: }
648: }
649: return sb.toString();
650: }
651:
652: // XXX(-tdt) Hmm, backward compatibility with com.netbeans package name
653: // again. The property editor search path is stored in user settings, we
654: // must translate
655: private static String[] translatedEditorSearchPath(
656: String[] eSearchPath) {
657: String[] retval = new String[eSearchPath.length];
658: for (int i = 0; i < eSearchPath.length; i++) {
659: String path = eSearchPath[i];
660: path = org.openide.util.Utilities.translate(path
661: + ".BogusClass"); // NOI18N
662: path = path.substring(0, path.length()
663: - ".BogusClass".length()); // NOI18N
664: retval[i] = path;
665: }
666: return retval;
667: }
668:
669: /** This method must be overriden. It returns display name of this options.
670: *
671: * @return display name.
672: */
673: public String displayName() {
674: return FormUtils.getBundleString("CTL_FormSettings"); // NOI18N
675: }
676:
677: public HelpCtx getHelpCtx() {
678: return new HelpCtx("gui.configuring"); // NOI18N
679: }
680:
681: private static BeanNode createViewNode()
682: throws java.beans.IntrospectionException {
683: return new BeanNode<FormLoaderSettings>(FormLoaderSettings
684: .getInstance());
685: }
686: }
|