KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > editor > ext > java > JavaSettingsDefaults


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.editor.ext.java;
21
22 import java.awt.event.KeyEvent JavaDoc;
23 import java.awt.event.InputEvent JavaDoc;
24 import java.awt.Font JavaDoc;
25 import java.awt.Color JavaDoc;
26 import javax.swing.KeyStroke JavaDoc;
27 import java.util.Map JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import java.util.TreeMap JavaDoc;
30 import org.netbeans.editor.Acceptor;
31 import org.netbeans.editor.AcceptorFactory;
32 import org.netbeans.editor.Coloring;
33 import org.netbeans.editor.Settings;
34 import org.netbeans.editor.SettingsDefaults;
35 import org.netbeans.editor.SettingsUtil;
36 import org.netbeans.editor.TokenCategory;
37 import org.netbeans.editor.TokenContextPath;
38 import org.netbeans.editor.MultiKeyBinding;
39 import org.netbeans.editor.ext.ExtSettingsDefaults;
40 import org.netbeans.editor.ext.ExtKit;
41
42 /**
43 * Default settings values for Java.
44 *
45 * @author Miloslav Metelka
46 * @version 1.00
47 */

48
49 public class JavaSettingsDefaults extends ExtSettingsDefaults {
50
51     public static final Boolean JavaDoc defaultCaretSimpleMatchBrace = Boolean.FALSE;
52     public static final Boolean JavaDoc defaultHighlightMatchingBracket = Boolean.TRUE;
53
54     public static final Acceptor defaultIdentifierAcceptor = AcceptorFactory.JAVA_IDENTIFIER;
55     public static final Acceptor defaultAbbrevResetAcceptor = AcceptorFactory.NON_JAVA_IDENTIFIER;
56     public static final Boolean JavaDoc defaultWordMatchMatchCase = Boolean.TRUE;
57
58     // Formatting
59
public static final Boolean JavaDoc defaultJavaFormatSpaceBeforeParenthesis = Boolean.FALSE;
60     public static final Boolean JavaDoc defaultJavaFormatSpaceAfterComma = Boolean.TRUE;
61     public static final Boolean JavaDoc defaultJavaFormatNewlineBeforeBrace = Boolean.FALSE;
62     public static final Boolean JavaDoc defaultJavaFormatLeadingSpaceInComment = Boolean.FALSE;
63     public static final Boolean JavaDoc defaultJavaFormatLeadingStarInComment = Boolean.TRUE;
64     public static final Integer JavaDoc defaultJavaFormatStatementContinuationIndent = new Integer JavaDoc(8);
65
66     public static final Boolean JavaDoc defaultPairCharactersCompletion = Boolean.TRUE;
67
68     /** @deprecated */
69     public static final Boolean JavaDoc defaultFormatSpaceBeforeParenthesis = defaultJavaFormatSpaceBeforeParenthesis;
70     /** @deprecated */
71     public static final Boolean JavaDoc defaultFormatSpaceAfterComma = defaultJavaFormatSpaceAfterComma;
72     /** @deprecated */
73     public static final Boolean JavaDoc defaultFormatNewlineBeforeBrace = defaultJavaFormatNewlineBeforeBrace;
74     /** @deprecated */
75     public static final Boolean JavaDoc defaultFormatLeadingSpaceInComment = defaultJavaFormatLeadingSpaceInComment;
76     
77     public static final Boolean JavaDoc defaultCodeFoldingEnable = Boolean.TRUE;
78     public static final Boolean JavaDoc defaultCodeFoldingCollapseMethod = Boolean.FALSE;
79     public static final Boolean JavaDoc defaultCodeFoldingCollapseInnerClass = Boolean.FALSE;
80     public static final Boolean JavaDoc defaultCodeFoldingCollapseImport = Boolean.FALSE;
81     public static final Boolean JavaDoc defaultCodeFoldingCollapseJavadoc = Boolean.FALSE;
82     public static final Boolean JavaDoc defaultCodeFoldingCollapseInitialComment = Boolean.FALSE;
83
84     public static final Boolean JavaDoc defaultGotoClassCaseSensitive = Boolean.FALSE;
85     public static final Boolean JavaDoc defaultGotoClassShowInnerClasses = Boolean.FALSE;
86     public static final Boolean JavaDoc defaultGotoClassShowLibraryClasses = Boolean.TRUE;
87
88
89     public static final Acceptor defaultIndentHotCharsAcceptor
90         = new Acceptor() {
91             public boolean accept(char ch) {
92                 switch (ch) {
93                     case '{':
94                     case '}':
95                         return true;
96                 }
97
98                 return false;
99             }
100         };
101
102
103     public static final String JavaDoc defaultWordMatchStaticWords
104     = "Exception IntrospectionException FileNotFoundException IOException" // NOI18N
105
+ " ArrayIndexOutOfBoundsException ClassCastException ClassNotFoundException" // NOI18N
106
+ " CloneNotSupportedException NullPointerException NumberFormatException" // NOI18N
107
+ " SQLException IllegalAccessException IllegalArgumentException"; // NOI18N
108

109     public static Map JavaDoc getJavaAbbrevMap() {
110         Map JavaDoc javaAbbrevMap = new TreeMap JavaDoc();
111         javaAbbrevMap.put("sout", "System.out.println(\"|\");"); // NOI18N
112
javaAbbrevMap.put("serr", "System.err.println(\"|\");"); // NOI18N
113

114         javaAbbrevMap.put("psf", "private static final "); // NOI18N
115
javaAbbrevMap.put("psfi", "private static final int "); // NOI18N
116
javaAbbrevMap.put("psfs", "private static final String "); // NOI18N
117
javaAbbrevMap.put("psfb", "private static final boolean "); // NOI18N
118
javaAbbrevMap.put("Psf", "public static final "); // NOI18N
119
javaAbbrevMap.put("Psfi", "public static final int "); // NOI18N
120
javaAbbrevMap.put("Psfs", "public static final String "); // NOI18N
121
javaAbbrevMap.put("Psfb", "public static final boolean "); // NOI18N
122

123
124         javaAbbrevMap.put("ab", "abstract "); // NOI18N
125
javaAbbrevMap.put("bo", "boolean "); // NOI18N
126
javaAbbrevMap.put("br", "break"); // NOI18N
127
javaAbbrevMap.put("ca", "catch ("); // NOI18N
128
javaAbbrevMap.put("cl", "class "); // NOI18N
129
javaAbbrevMap.put("cn", "continue"); // NOI18N
130
javaAbbrevMap.put("df", "default:"); // NOI18N
131
javaAbbrevMap.put("ex", "extends "); // NOI18N
132
javaAbbrevMap.put("fa", "false"); // NOI18N
133
javaAbbrevMap.put("fi", "final "); // NOI18N
134
javaAbbrevMap.put("fl", "float "); // NOI18N
135
javaAbbrevMap.put("fy", "finally "); // NOI18N
136
javaAbbrevMap.put("im", "implements "); // NOI18N
137
javaAbbrevMap.put("ir", "import "); // NOI18N
138
javaAbbrevMap.put("iof", "instanceof "); // NOI18N
139
javaAbbrevMap.put("ie", "interface "); // NOI18N
140
javaAbbrevMap.put("pr", "private "); // NOI18N
141
javaAbbrevMap.put("pe", "protected "); // NOI18N
142
javaAbbrevMap.put("pu", "public "); // NOI18N
143
javaAbbrevMap.put("re", "return "); // NOI18N
144
javaAbbrevMap.put("st", "static "); // NOI18N
145
javaAbbrevMap.put("sw", "switch ("); // NOI18N
146
javaAbbrevMap.put("sy", "synchronized "); // NOI18N
147
javaAbbrevMap.put("th", "throws "); // NOI18N
148
javaAbbrevMap.put("tw", "throw "); // NOI18N
149
javaAbbrevMap.put("twn", "throw new "); // NOI18N
150
javaAbbrevMap.put("wh", "while ("); // NOI18N
151

152         javaAbbrevMap.put("eq", "equals"); // NOI18N
153
javaAbbrevMap.put("le", "length"); // NOI18N
154

155         javaAbbrevMap.put("En", "Enumeration"); // NOI18N
156
javaAbbrevMap.put("Ex", "Exception"); // NOI18N
157
javaAbbrevMap.put("Ob", "Object"); // NOI18N
158
javaAbbrevMap.put("St", "String"); // NOI18N
159

160         javaAbbrevMap.put("pst", "printStackTrace();"); // NOI18N
161
javaAbbrevMap.put("tds", "Thread.dumpStack();"); // NOI18N
162

163         //Code templates
164

165         javaAbbrevMap.put("fori",
166                 "for (int ${IDX newVarName default=\"idx\"} = 0; ${IDX} < ${ARR array default=\"arr\"}.length; ${IDX}++) {\n"
167                 + "${TYPE rightSideType default=\"Object\"} ${ELEM newVarName default=\"elem\"} = ${TYPE_CAST cast default=\"\" editable=false}${ARR}[${IDX}];\n"
168                 + "${selection line}${cursor}\n"
169                 + "}\n"
170         );
171         javaAbbrevMap.put("forc",
172                 "for (${IT_TYPE rightSideType type=\"java.util.Iterator\" default=\"Iterator\" editable=false} ${IT newVarName default=\"it\"} = ${COL instanceof=\"java.util.Collection\" default=\"col\"}.iterator(); ${IT}.hasNext();) {\n"
173                 + "${TYPE rightSideType default=\"Object\"} ${ELEM newVarName default=\"elem\"} = ${TYPE_CAST cast default=\"\" editable=false}${IT}.next();\n"
174                 + "${selection line}${cursor}\n"
175                 + "}\n"
176         );
177         javaAbbrevMap.put("forl",
178                 "for (int ${IDX newVarName default=\"idx\"} = 0; ${IDX} < ${LIST instanceof=\"java.util.List\" default=\"lst\"}.size(); ${IDX}++) {\n"
179                 + "${TYPE rightSideType default=\"Object\"} ${ELEM newVarName default=\"elem\"} = ${TYPE_CAST cast default=\"\" editable=false}${LIST}.get(${IDX});\n"
180                 + "${selection line}${cursor}\n"
181                 + "}\n"
182         );
183         javaAbbrevMap.put("forv",
184                 "for (int ${IDX newVarName default=\"idx\"} = 0; ${IDX} < ${VECTOR instanceof=\"java.util.Vector\" default=\"vct\"}.size(); ${IDX}++) {\n"
185                 + "${TYPE rightSideType default=\"Object\"} ${ELEM newVarName default=\"elem\"} = ${TYPE_CAST cast default=\"\" editable=false}${VECTOR}.elementAt(${IDX});\n"
186                 + "${selection line}${cursor}\n"
187                 + "}\n"
188         );
189         javaAbbrevMap.put("fore",
190                 "for (${TYPE iterableElementType default=\"Object\" editable=false} ${ELEM newVarName default=\"elem\"} : ${ITER iterable default=\"col\"}) {\n"
191                 + "${selection line}${cursor}\n"
192                 + "}\n"
193         );
194         javaAbbrevMap.put("forst",
195                 "for (${STR_TOK type=\"java.util.StringTokenizer\" default=\"StringTokenizer\" editable=false} ${TOKENIZER newVarName} = new ${STR_TOK}(${STRING instanceof=\"java.lang.String\"}); ${TOKENIZER}.hasMoreTokens();) {\n"
196                 + "String ${TOKEN default=\"token\"} = ${TOKENIZER}.nextToken();\n"
197                 + "${cursor}\n"
198                 + "}\n"
199         );
200         javaAbbrevMap.put("inst",
201                 "if (${EXP instanceof=\"java.lang.Object\" default=\"exp\"} instanceof ${TYPE default=\"Object\"}) {\n"
202                 + "${TYPE} ${VAR newVarName default=\"obj\"} = (${TYPE})${EXP};\n"
203                 + "${cursor}\n"
204                 + "}\n"
205         );
206         javaAbbrevMap.put("soutv", "System.out.println(\"${EXP instanceof=\"<any>\" default=\"exp\"} = \" + ${EXP});");
207         javaAbbrevMap.put("whilen",
208                 "while(${ENUM instanceof=\"java.util.Enumeration\" default=\"en\"}.hasMoreElements()) {\n"
209                 + "${TYPE rightSideType default=\"Object\"} ${ELEM newVarName default=\"elem\"} = ${TYPE_CAST cast default=\"\" editable=false} ${ENUM}.nextElement();\n"
210                 + "${selection line}${cursor}\n"
211                 + "}\n"
212         );
213         javaAbbrevMap.put("whileit",
214                 "while(${IT instanceof=\"java.util.Iterator\" default=\"it\"}.hasNext()) {\n"
215                 + "${TYPE rightSideType default=\"Object\"} ${ELEM newVarName default=\"elem\"} = ${TYPE_CAST cast default=\"\" editable=false} ${IT}.next();\n"
216                 + "${selection line}${cursor}\n"
217                 + "}\n"
218         );
219         javaAbbrevMap.put("iff",
220                 "if (${EXP instanceof=\"java.lang.Boolean\" default=\"exp\"}) {\n"
221                 + "${selection line}${cursor}\n"
222                 + "}\n"
223         );
224         javaAbbrevMap.put("ifelse",
225                 "if (${EXP instanceof=\"java.lang.Boolean\" default=\"exp\"}) {\n"
226                 + "${selection line}${cursor}\n"
227                 + "} else {\n"
228                 + "}\n"
229         );
230         javaAbbrevMap.put("whilexp", // NOI18N
231
"while (${EXP instanceof=\"java.lang.Boolean\" default=\"exp\"}) {\n" // NOI18N
232
+ "${selection line}${cursor}\n" // NOI18N
233
+ "}\n"
234         );
235         javaAbbrevMap.put("dowhile", // NOI18N
236
"do {\n" // NOI18N
237
+ "${selection line}${cursor}\n" // NOI18N
238
+ "} while (${EXP instanceof=\"java.lang.Boolean\" default=\"exp\"});\n" // NOI18N
239
);
240         javaAbbrevMap.put("runn",
241                 "${RUNN_TYPE type=\"java.lang.Runnable\" default=\"Runnable\" editable=false} ${RUNN newVarName default=\"r\"} = new ${RUNN_TYPE}() {\n"
242                 + "public void run() {\n"
243                 + "${selection line}${cursor}\n"
244                 + "}\n"
245                 + "};\n"
246         );
247         javaAbbrevMap.put("trycatch",
248                 "try {\n"
249                 + "${selection line}${cursor}\n"
250                 + "} catch (${EX_TYPE default=\"Exception\"} ${EX default=\"e\"}) {\n"
251                 + "}\n"
252          );
253         javaAbbrevMap.put("newo", // NOI18N
254
"$TYPE default=\"Object\"} ${OBJ newVarName default=\"obj\"} = new ${TYPE}(${cursor});" // NOI18N
255
);
256         javaAbbrevMap.put("psvm", // NOI18N
257
"public static void main(String[] args) {\n" // NOI18N
258
+ "${cursor}\n" // NOI18N
259
+ "}\n" //NOI18N
260
);
261         return javaAbbrevMap;
262     }
263
264     public static MultiKeyBinding[] getJavaKeyBindings() {
265         int MENU_MASK = java.awt.Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
266         
267         return new MultiKeyBinding[] {
268                    new MultiKeyBinding(
269                        new KeyStroke JavaDoc[] {
270                            KeyStroke.getKeyStroke(KeyEvent.VK_J, MENU_MASK),
271                            KeyStroke.getKeyStroke(KeyEvent.VK_D, 0)
272                        },
273                        "macro-debug-var" // NOI18N
274
),
275                    new MultiKeyBinding(
276                        KeyStroke.getKeyStroke(KeyEvent.VK_T, MENU_MASK | InputEvent.SHIFT_MASK),
277                        ExtKit.commentAction
278                    ),
279                   new MultiKeyBinding(
280                       KeyStroke.getKeyStroke(KeyEvent.VK_D, MENU_MASK | InputEvent.SHIFT_MASK),
281                       ExtKit.uncommentAction
282                   ),
283                   new MultiKeyBinding(
284                       new KeyStroke JavaDoc[] {
285                           KeyStroke.getKeyStroke(KeyEvent.VK_R, MENU_MASK),
286                       },
287                       "in-place-refactoring"
288                   ),
289                };
290     }
291     
292     public static Map JavaDoc getJavaMacroMap() {
293         Map JavaDoc javaMacroMap = new HashMap JavaDoc();
294         javaMacroMap.put( "debug-var", "select-identifier copy-to-clipboard " + // NOI18N
295
"caret-up caret-end-line insert-break \"System.err.println(\\\"\"" +
296                 "paste-from-clipboard \" = \\\" + \" paste-from-clipboard \" );" ); // NOI18N
297

298         return javaMacroMap;
299     }
300
301     static class JavaTokenColoringInitializer
302     extends SettingsUtil.TokenColoringInitializer {
303
304         Font JavaDoc boldFont = SettingsDefaults.defaultFont.deriveFont(Font.BOLD);
305         Font JavaDoc italicFont = SettingsDefaults.defaultFont.deriveFont(Font.ITALIC);
306         Settings.Evaluator boldSubst = new SettingsUtil.FontStylePrintColoringEvaluator(Font.BOLD);
307         Settings.Evaluator italicSubst = new SettingsUtil.FontStylePrintColoringEvaluator(Font.ITALIC);
308         Settings.Evaluator lightGraySubst = new SettingsUtil.ForeColorPrintColoringEvaluator(new Color JavaDoc(120, 120, 120));
309
310         Coloring commentColoring = new Coloring(null, new Color JavaDoc(115, 115, 115), null);
311
312         Coloring numbersColoring = new Coloring(null, new Color JavaDoc(120, 0, 0), null);
313
314         public JavaTokenColoringInitializer() {
315             super(JavaTokenContext.context);
316         }
317
318         public Object JavaDoc getTokenColoring(TokenContextPath tokenContextPath,
319         TokenCategory tokenIDOrCategory, boolean printingSet) {
320             if (!printingSet) {
321                 switch (tokenIDOrCategory.getNumericID()) {
322                     case JavaTokenContext.WHITESPACE_ID:
323                     case JavaTokenContext.IDENTIFIER_ID:
324                     case JavaTokenContext.OPERATORS_ID:
325                         return SettingsDefaults.emptyColoring;
326
327                     case JavaTokenContext.ERRORS_ID:
328                         return new Coloring(null, Color.white, Color.red);
329
330                     case JavaTokenContext.KEYWORDS_ID:
331                         return new Coloring(boldFont, Coloring.FONT_MODE_APPLY_STYLE,
332                             new Color JavaDoc(0, 0, 153), null);
333
334
335                     case JavaTokenContext.LINE_COMMENT_ID:
336                     case JavaTokenContext.BLOCK_COMMENT_ID:
337                         return commentColoring;
338
339                     case JavaTokenContext.CHAR_LITERAL_ID:
340                         return new Coloring(null, new Color JavaDoc(0, 111, 0), null);
341
342                     case JavaTokenContext.STRING_LITERAL_ID:
343                         return new Coloring(null, new Color JavaDoc(153, 0, 107), null);
344
345                     case JavaTokenContext.NUMERIC_LITERALS_ID:
346                         return numbersColoring;
347
348                     case JavaTokenContext.ANNOTATION_ID: // JDK 1.5 annotations
349
return new Coloring(null, new Color JavaDoc(0, 111, 0), null);
350
351                 }
352
353             } else { // printing set
354
switch (tokenIDOrCategory.getNumericID()) {
355                     case JavaTokenContext.LINE_COMMENT_ID:
356                     case JavaTokenContext.BLOCK_COMMENT_ID:
357                          return lightGraySubst; // print fore color will be gray
358

359                     default:
360                          return SettingsUtil.defaultPrintColoringEvaluator;
361                 }
362
363             }
364
365             return null;
366
367         }
368
369     }
370
371     static class JavaLayerTokenColoringInitializer
372     extends SettingsUtil.TokenColoringInitializer {
373
374         Font JavaDoc boldFont = SettingsDefaults.defaultFont.deriveFont(Font.BOLD);
375         Settings.Evaluator italicSubst = new SettingsUtil.FontStylePrintColoringEvaluator(Font.ITALIC);
376
377         public JavaLayerTokenColoringInitializer() {
378             super(JavaLayerTokenContext.context);
379         }
380
381         public Object JavaDoc getTokenColoring(TokenContextPath tokenContextPath,
382         TokenCategory tokenIDOrCategory, boolean printingSet) {
383             if (!printingSet) {
384                 switch (tokenIDOrCategory.getNumericID()) {
385                     case JavaLayerTokenContext.METHOD_ID:
386                         return new Coloring(boldFont, Coloring.FONT_MODE_APPLY_STYLE,
387                             null, null);
388
389                 }
390
391             } else { // printing set
392
switch (tokenIDOrCategory.getNumericID()) {
393                     case JavaLayerTokenContext.METHOD_ID:
394                         return italicSubst;
395
396                     default:
397                          return SettingsUtil.defaultPrintColoringEvaluator;
398                 }
399
400             }
401
402             return null;
403         }
404
405     }
406
407 }
408
Popular Tags