KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > form > FormLoaderSettings


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.form;
21
22 import java.awt.Color JavaDoc;
23 import java.lang.String JavaDoc;
24 import java.lang.String JavaDoc;
25 import java.lang.String JavaDoc;
26 import java.util.*;
27 import java.util.prefs.Preferences JavaDoc;
28 import org.openide.util.HelpCtx;
29 import org.netbeans.modules.form.codestructure.*;
30 import org.openide.nodes.BeanNode;
31 import org.openide.util.NbPreferences;
32
33 /**
34  * Settings for the form editor.
35  */

36
37 public class FormLoaderSettings {
38     private static final FormLoaderSettings INSTANCE = new FormLoaderSettings();
39     public static final String JavaDoc PROP_USE_INDENT_ENGINE = "useIndentEngine"; // NOI18N
40

41     /** Property name of the eventVariableName property */
42     public static final String JavaDoc PROP_EVENT_VARIABLE_NAME = "eventVariableName"; // NOI18N
43

44     /** Property name of the event listener code generation style option. */
45     public static final String JavaDoc PROP_LISTENER_GENERATION_STYLE = "listenerGenerationStyle"; // NOI18N
46

47     /** Property name of the selectionBorderSize property */
48     public static final String JavaDoc PROP_SELECTION_BORDER_SIZE = "selectionBorderSize"; // NOI18N
49
/** Property name of the selectionBorderColor property */
50     public static final String JavaDoc PROP_SELECTION_BORDER_COLOR = "selectionBorderColor"; // NOI18N
51
/** Property name of the connectionBorderColor property */
52     public static final String JavaDoc PROP_CONNECTION_BORDER_COLOR = "connectionBorderColor"; // NOI18N
53
/** Property name of the dragBorderColor property */
54     public static final String JavaDoc PROP_DRAG_BORDER_COLOR = "dragBorderColor"; // NOI18N
55
/** Property name of the guidingLineColor property */
56     public static final String JavaDoc PROP_GUIDING_LINE_COLOR = "guidingLineColor"; // NOI18N
57
/** Property name of the formDesignerBackgroundColor property */
58     public static final String JavaDoc PROP_FORMDESIGNER_BACKGROUND_COLOR =
59         "formDesignerBackgroundColor"; // NOI18N
60
/** Property name of the formDesignerBorderColor property */
61     public static final String JavaDoc PROP_FORMDESIGNER_BORDER_COLOR =
62         "formDesignerBorderColor"; // NOI18N
63

64     /** Property name of the gridX property */
65     public static final String JavaDoc PROP_GRID_X = "gridX"; // NOI18N
66
/** Property name of the gridY property */
67     public static final String JavaDoc PROP_GRID_Y = "gridY"; // NOI18N
68
/** Property name of the applyGridToPosition property */
69     public static final String JavaDoc PROP_APPLY_GRID_TO_POSITION = "applyGridToPosition"; // NOI18N
70
/** Property name of the applyGridToSize property */
71     public static final String JavaDoc PROP_APPLY_GRID_TO_SIZE = "applyGridToSize"; // NOI18N
72

73     /** Property name of the variablesModifier property */
74     public static final String JavaDoc PROP_VARIABLES_MODIFIER = "variablesModifier"; // NOI18N
75
/** Property name of the variablesLocal property */
76     public static final String JavaDoc PROP_VARIABLES_LOCAL = "variablesLocal"; // NOI18N
77

78     /** Property name of the generateMnemonicsCode property */
79     public static final String JavaDoc PROP_GENERATE_MNEMONICS = "generateMnemonicsCode"; // NOI18N
80
/** Property name of the showMnemonicsDialog property */
81     public static final String JavaDoc PROP_SHOW_MNEMONICS_DIALOG = "showMnemonicsDialog"; // NOI18N
82

83     /** Property name of the displayWritableOnly property */
84     public static final String JavaDoc PROP_DISPLAY_WRITABLE_ONLY = "displayWritableOnly"; // NOI18N
85

86     /** Property name of the editorSearchPath property */
87     public static final String JavaDoc PROP_EDITOR_SEARCH_PATH = "editorSearchPath"; // NOI18N
88
/** Property name of the registeredEditors property */
89     public static final String JavaDoc PROP_REGISTERED_EDITORS = "registeredEditors"; // NOI18N
90

91     /** Property name of the toolBarPalette property */
92     public static final String JavaDoc PROP_PALETTE_IN_TOOLBAR = "toolBarPalette"; // NOI18N
93
/** Property name of the foldGeneratedCode property. */
94     public static final String JavaDoc PROP_FOLD_GENERATED_CODE = "foldGeneratedCode"; // NOI18N
95
/** Property name of the assistantShown property. */
96     public static final String JavaDoc PROP_ASSISTANT_SHOWN = "assistantShown"; // NOI18N
97
/** Property name of the designerLAF property. */
98     public static final String JavaDoc PROP_DESIGNER_LAF = "designerLAF"; // NOI18N
99

100     /** Property name of the layout code target property. */
101     public static final String JavaDoc PROP_LAYOUT_CODE_TARGET = "layoutCodeTarget"; // NOI18N
102

103     /** Name of the automatic i18n property. */
104     public static final String JavaDoc PROP_AUTO_I18N = "i18nAutoMode"; // NOI18N
105
static final int AUTO_I18N_DEFAULT = 0;
106     static final int AUTO_I18N_ON = 1;
107     static final int AUTO_I18N_OFF = 2;
108 // public static final String PROP_CONTAINER_BEANS = "containerBeans"; // NOI18N
109

110     // ------------------------------------------
111
/** The color of the drag border on selection border */
112     private static java.awt.Color JavaDoc dragBorderColor = java.awt.Color.gray;
113     /** Indicates whether to display automatically hint dialog advertising the
114      * Mnemonics generation feature. */

115     private static boolean showMnemonicsDialog = true;
116     /** Array of package names to search for property editors used in Form Editor */
117     private static String JavaDoc[] editorSearchPath = null;
118     /** Array of items [Class Name, Editor1, Editor2, ...] */
119     private static String JavaDoc [][] registeredEditors;
120     private static final int MIN_SELECTION_BORDER_SIZE = 1;
121     private static final int MAX_SELECTION_BORDER_SIZE = 15;
122
123     private static final int MIN_GRID_X = 2;
124     private static final int MIN_GRID_Y = 2;
125
126 // private static Map containerBeans;
127

128     // --------
129

130     public static final Preferences JavaDoc getPreferences() {
131         return NbPreferences.forModule(FormLoaderSettings.class);
132     }
133     
134     public static FormLoaderSettings getInstance() {
135         return INSTANCE;
136     }
137
138     // ------------------------------------------
139
// property access methods
140

141     public boolean getUseIndentEngine() {
142         return getPreferences().getBoolean(PROP_USE_INDENT_ENGINE, false);
143     }
144
145     public void setUseIndentEngine(boolean value) {
146         getPreferences().putBoolean(PROP_USE_INDENT_ENGINE, value);
147     }
148     
149     /** Getter for the sortEventSets option */
150     public String JavaDoc getEventVariableName() {
151         return getPreferences().get(PROP_EVENT_VARIABLE_NAME, "evt");
152     }
153
154     /** Setter for the sortEventSets option */
155     public void setEventVariableName(String JavaDoc value) {
156         getPreferences().put(PROP_EVENT_VARIABLE_NAME, value);
157     }
158
159     /** Getter for the event listener code generation style option. */
160     public int getListenerGenerationStyle() {
161         return getPreferences().getInt(PROP_LISTENER_GENERATION_STYLE, 0);
162     }
163
164     /** Setter for the event listener code generation style option. */
165     public void setListenerGenerationStyle(int style) {
166         getPreferences().putInt(PROP_LISTENER_GENERATION_STYLE, style);
167     }
168
169     /** Getter for the selectionBorderSize option */
170     public int getSelectionBorderSize() {
171         return getPreferences().getInt(PROP_SELECTION_BORDER_SIZE, 1);
172     }
173
174     /** Setter for the selectionBorderSize option */
175     public void setSelectionBorderSize(int value) {
176         if (value < MIN_SELECTION_BORDER_SIZE)
177             value = MIN_SELECTION_BORDER_SIZE;
178         else if (value > MAX_SELECTION_BORDER_SIZE)
179             value = MAX_SELECTION_BORDER_SIZE;
180
181         
182         getPreferences().putInt(PROP_SELECTION_BORDER_SIZE, value);
183     }
184
185     /** Getter for the selectionBorderColor option */
186     public java.awt.Color JavaDoc getSelectionBorderColor() {
187         int rgb = getPreferences().getInt(PROP_SELECTION_BORDER_COLOR, new Color JavaDoc(255, 164, 0).getRGB());
188         return new Color JavaDoc(rgb);
189     }
190
191     /** Setter for the selectionBorderColor option */
192     public void setSelectionBorderColor(java.awt.Color JavaDoc value) {
193         if (value == null) {
194             return;
195         }
196         getPreferences().putInt(PROP_SELECTION_BORDER_COLOR, value.getRGB());
197     }
198
199     /** Getter for the connectionBorderColor option */
200     public java.awt.Color JavaDoc getConnectionBorderColor() {
201         int rgb = getPreferences().getInt(PROP_CONNECTION_BORDER_COLOR, Color.red.getRGB());
202         return new Color JavaDoc(rgb);
203     }
204
205     /** Setter for the connectionBorderColor option */
206     public void setConnectionBorderColor(java.awt.Color JavaDoc value) {
207         if (value == null) {
208             return;
209         }
210         getPreferences().putInt(PROP_CONNECTION_BORDER_COLOR, value.getRGB());
211     }
212
213     /** Getter for the dragBorderColor option */
214     public java.awt.Color JavaDoc getDragBorderColor() {
215         int rgb = getPreferences().getInt(PROP_DRAG_BORDER_COLOR, Color.gray.getRGB());
216         return new Color JavaDoc(rgb);
217     }
218
219     /** Setter for the dragBorderColor option */
220     public void setDragBorderColor(java.awt.Color JavaDoc value) {
221         if (value == null) {
222             return;
223         }
224         getPreferences().putInt(PROP_DRAG_BORDER_COLOR, value.getRGB());
225     }
226     
227     /** Getter for the guidingLineColor option */
228     public java.awt.Color JavaDoc getGuidingLineColor() {
229         int rgb = getPreferences().getInt(PROP_GUIDING_LINE_COLOR, new Color JavaDoc(143, 171, 196).getRGB());
230         return new Color JavaDoc(rgb);
231         
232     }
233
234     /** Setter for the dragBorderColor option */
235     public void setGuidingLineColor(java.awt.Color JavaDoc value) {
236         if (value == null) {
237             return;
238         }
239         getPreferences().putInt(PROP_GUIDING_LINE_COLOR, value.getRGB());
240     }
241
242     /** Getter for the gridX option */
243     public int getGridX() {
244         return getPreferences().getInt(PROP_GRID_X, 10);
245     }
246
247     /** Setter for the gridX option */
248     public void setGridX(int value) {
249         if (value < MIN_GRID_X) value = MIN_GRID_X;
250         getPreferences().putInt(PROP_GRID_X, value);
251     }
252
253     /** Getter for the gridY option */
254     public int getGridY() {
255         return getPreferences().getInt(PROP_GRID_Y, 10);
256     }
257
258     /** Setter for the gridY option */
259     public void setGridY(int value) {
260         if (value < MIN_GRID_Y) value = MIN_GRID_Y;
261         getPreferences().putInt(PROP_GRID_Y, value);
262     }
263
264     /** Getter for the applyGridToPosition option */
265     public boolean getApplyGridToPosition() {
266         return getPreferences().getBoolean(PROP_APPLY_GRID_TO_POSITION, true);
267     }
268
269     /** Setter for the applyGridToPosition option */
270     public void setApplyGridToPosition(boolean value) {
271         getPreferences().putBoolean(PROP_APPLY_GRID_TO_POSITION, value);
272     }
273
274     /** Getter for the applyGridToSize option */
275     public boolean getApplyGridToSize() {
276         return getPreferences().getBoolean(PROP_APPLY_GRID_TO_SIZE, true);
277         
278     }
279
280     /** Setter for the applyGridToSize option */
281     public void setApplyGridToSize(boolean value) {
282         getPreferences().putBoolean(PROP_APPLY_GRID_TO_SIZE, value);
283     }
284
285     /** Getter for the variablesLocal option. */
286     public boolean getVariablesLocal() {
287         return getPreferences().getBoolean(PROP_VARIABLES_LOCAL, false);
288     }
289
290     /** Setter for the variablesLocal option. */
291     public void setVariablesLocal(boolean value) {
292         getPreferences().putBoolean(PROP_VARIABLES_LOCAL, value);
293         int variablesModifier = getVariablesModifier();
294         int varType = value ?
295             CodeVariable.LOCAL | (variablesModifier & CodeVariable.FINAL)
296                                | CodeVariable.EXPLICIT_DECLARATION
297             :
298             CodeVariable.FIELD | variablesModifier;
299         CodeStructure.setGlobalDefaultVariableType(varType);
300
301         if (value) {
302             variablesModifier &= CodeVariable.FINAL;
303             setVariablesModifier(variablesModifier);
304         }
305             
306
307     }
308
309     /** Getter for the variablesModifier option */
310     public int getVariablesModifier() {
311         return getPreferences().getInt(PROP_VARIABLES_MODIFIER, java.lang.reflect.Modifier.PRIVATE);
312     }
313
314     /** Setter for the variablesModifier option */
315     public void setVariablesModifier(int value) {
316         int variablesModifier = value;
317
318         int varType;
319         if (getVariablesLocal()) {
320             varType = CodeVariable.LOCAL | variablesModifier;
321             if ((variablesModifier & CodeVariable.FINAL) == 0)
322                 varType |= CodeVariable.EXPLICIT_DECLARATION;
323         }
324         else varType = CodeVariable.FIELD | variablesModifier;
325         CodeStructure.setGlobalDefaultVariableType(varType);
326     }
327
328     /** Getter for the generateMnemonicsCode option */
329     public boolean getGenerateMnemonicsCode() {
330         return getPreferences().getBoolean(PROP_GENERATE_MNEMONICS, false);
331     }
332
333     /** Setter for the generateMnemonicsCode option */
334     public void setGenerateMnemonicsCode(boolean value) {
335         getPreferences().putBoolean(PROP_GENERATE_MNEMONICS, value);
336     }
337
338     /** Getter for the displayWritableOnly option */
339     public boolean getDisplayWritableOnly() {
340         return getPreferences().getBoolean(PROP_DISPLAY_WRITABLE_ONLY, true);
341     }
342
343     /** Setter for the displayWritableOnly option */
344     public void setDisplayWritableOnly(boolean value) {
345         getPreferences().putBoolean(PROP_DISPLAY_WRITABLE_ONLY, value);
346     }
347
348     /** Getter for the editorSearchPath option */
349     public String JavaDoc[] getEditorSearchPath() {
350         if (editorSearchPath == null) {
351             editorSearchPath = translatedEditorSearchPath(
352                     toArray(getPreferences().get(PROP_EDITOR_SEARCH_PATH, "org.netbeans.modules.form.editors2")));
353         }
354         return editorSearchPath;
355     }
356
357     /** Setter for the editorSearchPath option */
358     public void setEditorSearchPath(String JavaDoc[] value) {
359         editorSearchPath = value;
360         getPreferences().put(PROP_EDITOR_SEARCH_PATH, fromArray(editorSearchPath));//NOI18N
361
}
362
363     /** Getter for the registeredEditors option */
364     public String JavaDoc[][] getRegisteredEditors() {
365         if (registeredEditors == null) {
366             registeredEditors = toArray2(getPreferences().get(PROP_REGISTERED_EDITORS, ""));
367         }
368         
369         return registeredEditors;
370     }
371
372     /** Setter for the registeredEditors option */
373     public void setRegisteredEditors(String JavaDoc[][] value) {
374         registeredEditors = value;
375         getPreferences().put(PROP_REGISTERED_EDITORS, fromArray2(registeredEditors));//NOI18N
376
}
377
378     public String JavaDoc[] getRegisteredEditor(int index) {
379         return getRegisteredEditors()[index];
380     }
381
382     public void setRegisteredEditor(int index, String JavaDoc[] value) {
383         registeredEditors[index] = value;
384         FormPropertyEditorManager.clearEditorsCache(); // clear the editors cache so that the new editors can be used
385
setRegisteredEditors(registeredEditors);
386     }
387
388     public boolean isPaletteInToolBar() {
389         return getPreferences().getBoolean(PROP_PALETTE_IN_TOOLBAR, false);
390     }
391
392     public void setPaletteInToolBar(boolean value) {
393         getPreferences().putBoolean(PROP_PALETTE_IN_TOOLBAR, value);
394     }
395
396     /** Getter for the formDesignerBackgroundColor option */
397     public java.awt.Color JavaDoc getFormDesignerBackgroundColor() {
398         int rgb = getPreferences().getInt(PROP_FORMDESIGNER_BACKGROUND_COLOR , Color.white.getRGB());
399         return new Color JavaDoc(rgb);
400         
401     }
402
403     /** Setter for the formDesignerBackgroundColor option */
404     public void setFormDesignerBackgroundColor(java.awt.Color JavaDoc value) {
405         if (value == null)
406             return;
407         getPreferences().putInt(PROP_FORMDESIGNER_BACKGROUND_COLOR , value.getRGB());
408     }
409
410     /** Getter for the formDesignerBorderColor option */
411     public java.awt.Color JavaDoc getFormDesignerBorderColor() {
412         int rgb = getPreferences().getInt(PROP_FORMDESIGNER_BORDER_COLOR , new Color JavaDoc(224, 224, 255).getRGB());
413         return new Color JavaDoc(rgb);
414         
415     }
416
417     /** Setter for the formDesignerBorderColor option */
418     public void setFormDesignerBorderColor(java.awt.Color JavaDoc value) {
419         if (value == null)
420             return;
421         getPreferences().putInt(PROP_FORMDESIGNER_BORDER_COLOR , value.getRGB());
422     }
423     
424     /** Getter for the foldGeneratedCode option */
425     public boolean getFoldGeneratedCode() {
426         return getPreferences().getBoolean(PROP_FOLD_GENERATED_CODE, true);
427     }
428
429     /** Setter for the foldGeneratedCode option */
430     public void setFoldGeneratedCode(boolean value) {
431         getPreferences().putBoolean(PROP_FOLD_GENERATED_CODE, value);
432     }
433
434     /** Getter for the assistantShown option */
435     public boolean getAssistantShown() {
436         return getPreferences().getBoolean(PROP_ASSISTANT_SHOWN, true);
437     }
438
439     /** Setter for the foldGeneratedCode option */
440     public void setAssistantShown(boolean value) {
441         getPreferences().putBoolean(PROP_ASSISTANT_SHOWN, value);
442     }
443
444     public int getLayoutCodeTarget() {
445         return getPreferences().getInt(PROP_LAYOUT_CODE_TARGET, 0);
446     }
447
448     public void setLayoutCodeTarget(int target) {
449         getPreferences().putInt(PROP_LAYOUT_CODE_TARGET, target);
450     }
451
452     public int getI18nAutoMode() {
453         return getPreferences().getInt(PROP_AUTO_I18N, 0);
454     }
455
456     public void setI18nAutoMode(int mode) {
457         getPreferences().putInt(PROP_AUTO_I18N, mode);
458     }
459
460     private static String JavaDoc[][] toArray2(String JavaDoc esp) {
461         List<String JavaDoc[]> retval = new ArrayList<String JavaDoc[]> ();//NOI18N
462
String JavaDoc[] items = esp.split(" | ");//NOI18N
463
for (int i = 0; i < items.length; i++) {
464             String JavaDoc s = items[i];
465             retval.add(toArray(s));
466         }
467         return retval.toArray(new String JavaDoc [][] {{}});
468     }
469     
470     private static String JavaDoc fromArray2(String JavaDoc[][] items) {
471         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
472         for (int i = 0; i < items.length; i++) {
473             sb.append(fromArray(items[i]));
474             if (i < items.length-1) {
475                 sb.append(" | ");//NOI18N
476
}
477         }
478         return sb.toString();
479     }
480         
481     private static String JavaDoc[] toArray(String JavaDoc esp) {
482         return esp.split(" , ");//NOI18N
483
}
484     
485     private static String JavaDoc fromArray(String JavaDoc[] items) {
486         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
487         for (int i = 0; i < items.length; i++) {
488             sb.append(items[i]);
489             if (i < items.length-1) {
490                 sb.append(" , ");//NOI18N
491
}
492         }
493         return sb.toString();
494     }
495     
496     // XXX(-tdt) Hmm, backward compatibility with com.netbeans package name
497
// again. The property editor search path is stored in user settings, we
498
// must translate
499
private static String JavaDoc[] translatedEditorSearchPath(String JavaDoc[] eSearchPath) {
500         String JavaDoc[] retval = new String JavaDoc[eSearchPath.length];
501         for (int i = 0; i < eSearchPath.length; i++) {
502             String JavaDoc path = eSearchPath[i];
503             path = org.openide.util.Utilities.translate(path + ".BogusClass"); // NOI18N
504
path = path.substring(0, path.length() - ".BogusClass".length()); // NOI18N
505
retval[i] = path;
506         }
507         return retval;
508     }
509
510     /** This method must be overriden. It returns display name of this options.
511      */

512     public String JavaDoc displayName() {
513         return FormUtils.getBundleString("CTL_FormSettings"); // NOI18N
514
}
515
516     public HelpCtx getHelpCtx() {
517         return new HelpCtx("gui.configuring"); // NOI18N
518
}
519     
520     private static BeanNode createViewNode() throws java.beans.IntrospectionException JavaDoc {
521         return new BeanNode(FormLoaderSettings.getInstance());
522     }
523 }
524
Popular Tags