KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.Enumeration JavaDoc;
23 import java.util.List JavaDoc;
24 import org.netbeans.editor.ext.ExtSettingsNames;
25 import org.netbeans.editor.ext.java.JavaSettingsNames;
26 import org.netbeans.modules.editor.java.JavaKit;
27 import org.netbeans.modules.editor.java.JavaIndentEngine;
28 import org.netbeans.modules.editor.options.OptionSupport;
29 import org.openide.ServiceType;
30 import org.openide.util.HelpCtx;
31 import org.netbeans.modules.editor.NbEditorUtilities;
32 import java.awt.Color JavaDoc;
33 import java.awt.Dimension JavaDoc;
34 import java.util.HashMap JavaDoc;
35 import java.util.Map JavaDoc;
36 import java.util.MissingResourceException JavaDoc;
37 import org.netbeans.editor.SettingsNames;
38 import org.netbeans.modules.editor.options.BaseOptions;
39 import org.openide.util.NbBundle;
40
41 /**
42 * Options for the java editor kit
43 *
44 * @author Miloslav Metelka
45 * @version 1.00
46 */

47 public class JavaOptions extends BaseOptions {
48
49     public static final String JavaDoc JAVA = "java"; // NOI18N
50

51     public static final String JavaDoc COMPLETION_AUTO_POPUP_PROP = "completionAutoPopup"; // NOI18N
52

53     public static final String JavaDoc COMPLETION_CASE_SENSITIVE_PROP = "completionCaseSensitive"; // NOI18N
54

55     public static final String JavaDoc COMPLETION_NATURAL_SORT_PROP = "completionNaturalSort"; // NOI18N
56

57     public static final String JavaDoc COMPLETION_AUTO_POPUP_DELAY_PROP = "completionAutoPopupDelay"; // NOI18N
58

59     public static final String JavaDoc FORMAT_SPACE_BEFORE_PARENTHESIS_PROP = "formatSpaceBeforeParenthesis"; // NOI18N
60

61     public static final String JavaDoc FORMAT_COMPOUND_BRACKET_ADD_NL_PROP = "formatCompoundBracketAddNL"; // NOI18N
62

63     public static final String JavaDoc FAST_IMPORT_SELECTION_PROP = "fastImportSelection"; //NOI18N
64

65     private static final String JavaDoc HELP_ID = "editing.editor.java"; // !!! NOI18N
66

67     public static final String JavaDoc JAVADOC_BGCOLOR = "javaDocBGColor"; // NOI18N
68

69     public static final String JavaDoc JAVADOC_AUTO_POPUP_DELAY_PROP = "javaDocAutoPopupDelay"; //NOI18N
70

71     public static final String JavaDoc JAVADOC_PREFERRED_SIZE_PROP = "javaDocPreferredSize"; //NOI18N
72

73     public static final String JavaDoc JAVADOC_AUTO_POPUP_PROP = "javaDocAutoPopup"; //NOI18N
74

75     public static final String JavaDoc SHOW_DEPRECATED_MEMBERS_PROP = "showDeprecatedMembers"; //NOI18N
76

77     public static final String JavaDoc COMPLETION_INSTANT_SUBSTITUTION_PROP = "completionInstantSubstitution"; // NOI18N
78

79     public static final String JavaDoc FAST_IMPORT_PACKAGE_PROP = "fastImportPackage"; // NOI18N
80

81     public static final String JavaDoc GOTO_CLASS_CASE_SENSITIVE_PROP = "gotoClassCaseSensitive"; //NOI18N
82

83     public static final String JavaDoc GOTO_CLASS_SHOW_INNER_CLASSES_PROP = "gotoClassShowInnerClasses"; //NOI18N
84

85     public static final String JavaDoc GOTO_CLASS_SHOW_LIBRARY_CLASSES_PROP = "gotoClassShowLibraryClasses"; //NOI18N
86

87     static final String JavaDoc[] JAVA_PROP_NAMES = OptionSupport.mergeStringArrays(BaseOptions.BASE_PROP_NAMES, new String JavaDoc[] {
88                                                 COMPLETION_AUTO_POPUP_PROP,
89                                                 COMPLETION_CASE_SENSITIVE_PROP,
90                                                 COMPLETION_AUTO_POPUP_DELAY_PROP,
91                                                 FORMAT_SPACE_BEFORE_PARENTHESIS_PROP,
92                                                 FORMAT_COMPOUND_BRACKET_ADD_NL_PROP,
93                                                 JAVADOC_BGCOLOR,
94                                                 //JAVADOC_AUTO_POPUP_DELAY_PROP,
95
JAVADOC_PREFERRED_SIZE_PROP,
96                                                 JAVADOC_AUTO_POPUP_PROP,
97                                                 SHOW_DEPRECATED_MEMBERS_PROP,
98                                                 COMPLETION_INSTANT_SUBSTITUTION_PROP,
99                                                 COMPLETION_NATURAL_SORT_PROP,
100                                                 FAST_IMPORT_PACKAGE_PROP,
101                                                 GOTO_CLASS_CASE_SENSITIVE_PROP,
102                                                 GOTO_CLASS_SHOW_INNER_CLASSES_PROP,
103                                                 GOTO_CLASS_SHOW_LIBRARY_CLASSES_PROP,
104                                                 CODE_FOLDING_PROPS_PROP
105                                             });
106
107     static final long serialVersionUID =-7951549840240159575L;
108
109     public JavaOptions() {
110         this(JavaKit.class, JAVA);
111     }
112
113     public JavaOptions(Class JavaDoc kitClass, String JavaDoc typeName) {
114         super(kitClass, typeName);
115     }
116
117 /* public boolean getFormatSpaceBeforeParenthesis() {
118         return ((Boolean)getSettingValue(JavaSettingsNames.JAVA_FORMAT_SPACE_BEFORE_PARENTHESIS)).booleanValue();
119     }
120     [Mila] Removed because it was moved to JavaIndentEngine; setter must stay here
121 */

122     public void setFormatSpaceBeforeParenthesis(boolean v) {
123         setSettingBoolean(JavaSettingsNames.JAVA_FORMAT_SPACE_BEFORE_PARENTHESIS, v,
124             FORMAT_SPACE_BEFORE_PARENTHESIS_PROP);
125
126         // Need to check whether the service exists and if not, add it
127
// checkJavaIndentEngineRegistered();
128
}
129
130 /* public boolean getFormatCompoundBracketAddNL() {
131         return ((Boolean)getSettingValue(JavaSettingsNames.JAVA_FORMAT_NEWLINE_BEFORE_BRACE)).booleanValue();
132     }
133     [Mila] Removed because it was moved to JavaIndentEngine; setter must stay here
134 */

135     public void setFormatCompoundBracketAddNL(boolean v) {
136         setSettingBoolean(JavaSettingsNames.JAVA_FORMAT_NEWLINE_BEFORE_BRACE, v,
137             FORMAT_COMPOUND_BRACKET_ADD_NL_PROP);
138
139         // Need to check whether the service exists and if not, add it
140
// checkJavaIndentEngineRegistered();
141
}
142
143 /* private void checkJavaIndentEngineRegistered() {
144         ServiceType.Registry sr = TopManager.getDefault().getServices();
145         Enumeration en = sr.services(JavaIndentEngine.class);
146         if (!en.hasMoreElements()) {
147             // Need to add
148             List l = sr.getServiceTypes();
149             l.add(new JavaIndentEngine());
150             sr.setServiceTypes(l);
151         }
152     }
153  */

154
155     public boolean getCompletionAutoPopup() {
156         return getSettingBoolean(ExtSettingsNames.COMPLETION_AUTO_POPUP);
157     }
158     public void setCompletionAutoPopup(boolean v) {
159         setSettingBoolean(ExtSettingsNames.COMPLETION_AUTO_POPUP, v,
160             COMPLETION_AUTO_POPUP_PROP);
161     }
162
163     public boolean getCompletionCaseSensitive() {
164         return getSettingBoolean(ExtSettingsNames.COMPLETION_CASE_SENSITIVE);
165     }
166     public void setCompletionCaseSensitive(boolean v) {
167         setSettingBoolean(ExtSettingsNames.COMPLETION_CASE_SENSITIVE, v,
168             COMPLETION_CASE_SENSITIVE_PROP);
169     }
170     
171     public boolean getCompletionInstantSubstitution() {
172         return getSettingBoolean(ExtSettingsNames.COMPLETION_INSTANT_SUBSTITUTION);
173     }
174     public void setCompletionInstantSubstitution(boolean v) {
175         setSettingBoolean(ExtSettingsNames.COMPLETION_INSTANT_SUBSTITUTION, v,
176             COMPLETION_INSTANT_SUBSTITUTION_PROP);
177     }
178     
179     public int getCompletionAutoPopupDelay() {
180         return getSettingInteger(ExtSettingsNames.COMPLETION_AUTO_POPUP_DELAY);
181     }
182     public void setCompletionAutoPopupDelay(int delay) {
183         if (delay < 0) {
184             NbEditorUtilities.invalidArgument("MSG_NegativeValue"); // NOI18N
185
return;
186         }
187         setSettingInteger(ExtSettingsNames.COMPLETION_AUTO_POPUP_DELAY, delay,
188             COMPLETION_AUTO_POPUP_DELAY_PROP);
189     }
190
191     /*
192     public int getJavaDocAutoPopupDelay() {
193         return getSettingInteger(ExtSettingsNames.JAVADOC_AUTO_POPUP_DELAY);
194     }
195     public void setJavaDocAutoPopupDelay(int delay) {
196         if (delay < 0) {
197             NbEditorUtilities.invalidArgument("MSG_NegativeValue"); // NOI18N
198             return;
199         }
200         setSettingInteger(ExtSettingsNames.JAVADOC_AUTO_POPUP_DELAY, delay,
201             JAVADOC_AUTO_POPUP_DELAY_PROP);
202     }
203      */

204     
205     public boolean getJavaDocAutoPopup() {
206         return getSettingBoolean(ExtSettingsNames.JAVADOC_AUTO_POPUP);
207     }
208     public void setJavaDocAutoPopup(boolean auto) {
209         setSettingBoolean(ExtSettingsNames.JAVADOC_AUTO_POPUP, auto,
210             JAVADOC_AUTO_POPUP_PROP);
211     }
212     
213     public Color JavaDoc getJavaDocBGColor() {
214         return (Color JavaDoc)getSettingValue(ExtSettingsNames.JAVADOC_BG_COLOR);
215     }
216     public void setJavaDocBGColor(Color JavaDoc c) {
217         setSettingValue(ExtSettingsNames.JAVADOC_BG_COLOR, c,
218             JAVADOC_BGCOLOR);
219     }
220     
221     public Dimension JavaDoc getJavaDocPreferredSize() {
222         return (Dimension JavaDoc)getSettingValue(ExtSettingsNames.JAVADOC_PREFERRED_SIZE);
223     }
224     public void setJavaDocPreferredSize(Dimension JavaDoc d) {
225         setSettingValue(ExtSettingsNames.JAVADOC_PREFERRED_SIZE, d,
226             JAVADOC_PREFERRED_SIZE_PROP);
227     }
228     
229     public boolean getShowDeprecatedMembers() {
230         return getSettingBoolean(ExtSettingsNames.SHOW_DEPRECATED_MEMBERS);
231     }
232     public void setShowDeprecatedMembers(boolean v) {
233         setSettingBoolean(ExtSettingsNames.SHOW_DEPRECATED_MEMBERS, v,
234             SHOW_DEPRECATED_MEMBERS_PROP);
235     }
236     
237     public boolean getCompletionNaturalSort() {
238         return getSettingBoolean(ExtSettingsNames.COMPLETION_NATURAL_SORT);
239     }
240     public void setCompletionNaturalSort(boolean v) {
241         setSettingBoolean(ExtSettingsNames.COMPLETION_NATURAL_SORT, v,
242             COMPLETION_NATURAL_SORT_PROP);
243     }
244     
245     public int getFastImportSelection() {
246         return getSettingInteger(ExtSettingsNames.FAST_IMPORT_SELECTION);
247     }
248     public void setFastImportSelection(int sel) {
249         setSettingInteger(ExtSettingsNames.FAST_IMPORT_SELECTION, sel,
250             FAST_IMPORT_SELECTION_PROP);
251     }
252     
253     public boolean getGotoClassCaseSensitive() {
254         return getSettingBoolean(JavaSettingsNames.GOTO_CLASS_CASE_SENSITIVE);
255     }
256     public void setGotoClassCaseSensitive(boolean v) {
257         setSettingBoolean(JavaSettingsNames.GOTO_CLASS_CASE_SENSITIVE, v, GOTO_CLASS_CASE_SENSITIVE_PROP);
258     }
259
260     public boolean getGotoClassShowInnerClasses() {
261         return getSettingBoolean(JavaSettingsNames.GOTO_CLASS_SHOW_INNER_CLASSES);
262     }
263     public void setGotoClassShowInnerClasses(boolean v) {
264         setSettingBoolean(JavaSettingsNames.GOTO_CLASS_SHOW_INNER_CLASSES, v, GOTO_CLASS_SHOW_INNER_CLASSES_PROP);
265     }
266
267     public boolean getGotoClassShowLibraryClasses() {
268         return getSettingBoolean(JavaSettingsNames.GOTO_CLASS_SHOW_LIBRARY_CLASSES);
269     }
270     public void setGotoClassShowLibraryClasses(boolean v) {
271         setSettingBoolean(JavaSettingsNames.GOTO_CLASS_SHOW_LIBRARY_CLASSES, v, GOTO_CLASS_SHOW_LIBRARY_CLASSES_PROP);
272     }
273
274     protected Class JavaDoc getDefaultIndentEngineClass() {
275         return JavaIndentEngine.class;
276     }
277
278     public HelpCtx getHelpCtx () {
279         return new HelpCtx (HELP_ID);
280     }
281
282     public Map JavaDoc getCodeFoldingProps(){
283         Map JavaDoc map = new HashMap JavaDoc(super.getCodeFoldingProps());
284         
285         Boolean JavaDoc val = (Boolean JavaDoc)getSettingValue(JavaSettingsNames.CODE_FOLDING_COLLAPSE_METHOD);
286         map.put(JavaSettingsNames.CODE_FOLDING_COLLAPSE_METHOD, val);
287
288         val = (Boolean JavaDoc)getSettingValue(JavaSettingsNames.CODE_FOLDING_COLLAPSE_INNERCLASS);
289         map.put(JavaSettingsNames.CODE_FOLDING_COLLAPSE_INNERCLASS, val);
290
291         val = (Boolean JavaDoc)getSettingValue(JavaSettingsNames.CODE_FOLDING_COLLAPSE_IMPORT);
292         map.put(JavaSettingsNames.CODE_FOLDING_COLLAPSE_IMPORT, val);
293
294         val = (Boolean JavaDoc)getSettingValue(JavaSettingsNames.CODE_FOLDING_COLLAPSE_JAVADOC);
295         map.put(JavaSettingsNames.CODE_FOLDING_COLLAPSE_JAVADOC, val);
296
297         val = (Boolean JavaDoc)getSettingValue(JavaSettingsNames.CODE_FOLDING_COLLAPSE_INITIAL_COMMENT);
298         map.put(JavaSettingsNames.CODE_FOLDING_COLLAPSE_INITIAL_COMMENT, val);
299         
300         return map;
301     }
302
303     public void setCodeFoldingProps(Map JavaDoc props){
304         String JavaDoc name = SettingsNames.CODE_FOLDING_ENABLE;
305         setSettingValue(name, props.get(name));
306         name = JavaSettingsNames.CODE_FOLDING_COLLAPSE_METHOD;
307         setSettingValue(name, props.get(name));
308         name = JavaSettingsNames.CODE_FOLDING_COLLAPSE_INNERCLASS;
309         setSettingValue(name, props.get(name));
310         name = JavaSettingsNames.CODE_FOLDING_COLLAPSE_IMPORT;
311         setSettingValue(name, props.get(name));
312         name = JavaSettingsNames.CODE_FOLDING_COLLAPSE_JAVADOC;
313         setSettingValue(name, props.get(name));
314         name = JavaSettingsNames.CODE_FOLDING_COLLAPSE_INITIAL_COMMENT;
315         setSettingValue(name, props.get(name));
316     }
317     
318     /**
319      * Get localized string
320      */

321     protected String JavaDoc getString(String JavaDoc key) {
322         try {
323             return NbBundle.getMessage(JavaOptions.class, key);
324         } catch (MissingResourceException JavaDoc e) {
325             return super.getString(key);
326         }
327     }
328
329     
330 }
331
Popular Tags