001: /*
002: * Sun Public License Notice
003: *
004: * The contents of this file are subject to the Sun Public License
005: * Version 1.0 (the "License"). You may not use this file except in
006: * compliance with the License. A copy of the License is available at
007: * http://www.sun.com/
008: *
009: * The Original Code is NetBeans. The Initial Developer of the Original
010: * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
011: * Microsystems, Inc. All Rights Reserved.
012: */
013:
014: package org.netbeans.editor.ext.java;
015:
016: import java.awt.Color;
017: import java.awt.Font;
018: import java.awt.event.InputEvent;
019: import java.awt.event.KeyEvent;
020: import java.util.HashMap;
021: import java.util.Map;
022: import java.util.TreeMap;
023:
024: import javax.swing.KeyStroke;
025:
026: import org.netbeans.editor.Acceptor;
027: import org.netbeans.editor.AcceptorFactory;
028: import org.netbeans.editor.Coloring;
029: import org.netbeans.editor.MultiKeyBinding;
030: import org.netbeans.editor.Settings;
031: import org.netbeans.editor.SettingsDefaults;
032: import org.netbeans.editor.SettingsUtil;
033: import org.netbeans.editor.TokenCategory;
034: import org.netbeans.editor.TokenContextPath;
035: import org.netbeans.editor.ext.ExtKit;
036: import org.netbeans.editor.ext.ExtSettingsDefaults;
037:
038: /**
039: * Default settings values for Java.
040: *
041: * @author Miloslav Metelka
042: * @version 1.00
043: */
044:
045: public class JavaSettingsDefaults extends ExtSettingsDefaults {
046:
047: public static final Boolean defaultCaretSimpleMatchBrace = Boolean.FALSE;
048: public static final Boolean defaultHighlightMatchingBracket = Boolean.TRUE;
049:
050: public static final Acceptor defaultIdentifierAcceptor = AcceptorFactory.JAVA_IDENTIFIER;
051: public static final Acceptor defaultAbbrevResetAcceptor = AcceptorFactory.NON_JAVA_IDENTIFIER;
052: public static final Boolean defaultWordMatchMatchCase = Boolean.TRUE;
053:
054: // Formatting
055: public static final Boolean defaultJavaFormatSpaceBeforeParenthesis = Boolean.FALSE;
056: public static final Boolean defaultJavaFormatSpaceAfterComma = Boolean.TRUE;
057: public static final Boolean defaultJavaFormatNewlineBeforeBrace = Boolean.FALSE;
058: public static final Boolean defaultJavaFormatLeadingSpaceInComment = Boolean.FALSE;
059: public static final Boolean defaultJavaFormatLeadingStarInComment = Boolean.TRUE;
060:
061: /** @deprecated */
062: public static final Boolean defaultFormatSpaceBeforeParenthesis = defaultJavaFormatSpaceBeforeParenthesis;
063: /** @deprecated */
064: public static final Boolean defaultFormatSpaceAfterComma = defaultJavaFormatSpaceAfterComma;
065: /** @deprecated */
066: public static final Boolean defaultFormatNewlineBeforeBrace = defaultJavaFormatNewlineBeforeBrace;
067: /** @deprecated */
068: public static final Boolean defaultFormatLeadingSpaceInComment = defaultJavaFormatLeadingSpaceInComment;
069:
070: public static final Acceptor defaultIndentHotCharsAcceptor = new Acceptor() {
071: public boolean accept(char ch) {
072: switch (ch) {
073: case '{':
074: case '}':
075: return true;
076: }
077:
078: return false;
079: }
080: };
081:
082: public static final String defaultWordMatchStaticWords = "Exception IntrospectionException FileNotFoundException IOException" // NOI18N
083: + " ArrayIndexOutOfBoundsException ClassCastException ClassNotFoundException" // NOI18N
084: + " CloneNotSupportedException NullPointerException NumberFormatException" // NOI18N
085: + " SQLException IllegalAccessException IllegalArgumentException"; // NOI18N
086:
087: public static Map getJavaAbbrevMap() {
088: Map javaAbbrevMap = new TreeMap();
089: javaAbbrevMap.put("sout", "System.out.println(\"|\");"); // NOI18N
090: javaAbbrevMap.put("serr", "System.err.println(\"|\");"); // NOI18N
091:
092: javaAbbrevMap.put("impa", "import java.awt."); // NOI18N
093: javaAbbrevMap.put("impb", "import java.beans."); // NOI18N
094: javaAbbrevMap.put("impd", "import org.netbeans."); // NOI18N
095: javaAbbrevMap.put("impj", "import java."); // NOI18N
096: javaAbbrevMap.put("imps", "import javax.swing."); // NOI18N
097: javaAbbrevMap.put("impS", "import com.sun.java.swing."); // NOI18N
098: javaAbbrevMap.put("impq", "import javax.sql."); // NOI18N
099:
100: javaAbbrevMap.put("psf", "private static final "); // NOI18N
101: javaAbbrevMap.put("psfi", "private static final int "); // NOI18N
102: javaAbbrevMap.put("psfs", "private static final String "); // NOI18N
103: javaAbbrevMap.put("psfb", "private static final boolean "); // NOI18N
104: javaAbbrevMap.put("Psf", "public static final "); // NOI18N
105: javaAbbrevMap.put("Psfi", "public static final int "); // NOI18N
106: javaAbbrevMap.put("Psfs", "public static final String "); // NOI18N
107: javaAbbrevMap.put("Psfb", "public static final boolean "); // NOI18N
108:
109: javaAbbrevMap.put("ab", "abstract "); // NOI18N
110: javaAbbrevMap.put("bo", "boolean "); // NOI18N
111: javaAbbrevMap.put("br", "break"); // NOI18N
112: javaAbbrevMap.put("ca", "catch ("); // NOI18N
113: javaAbbrevMap.put("cl", "class "); // NOI18N
114: javaAbbrevMap.put("cn", "continue"); // NOI18N
115: javaAbbrevMap.put("df", "default:"); // NOI18N
116: javaAbbrevMap.put("ex", "extends "); // NOI18N
117: javaAbbrevMap.put("fa", "false"); // NOI18N
118: javaAbbrevMap.put("fi", "final "); // NOI18N
119: javaAbbrevMap.put("fl", "float "); // NOI18N
120: javaAbbrevMap.put("fy", "finally "); // NOI18N
121: javaAbbrevMap.put("im", "implements "); // NOI18N
122: javaAbbrevMap.put("ir", "import "); // NOI18N
123: javaAbbrevMap.put("iof", "instanceof "); // NOI18N
124: javaAbbrevMap.put("ie", "interface "); // NOI18N
125: javaAbbrevMap.put("pr", "private "); // NOI18N
126: javaAbbrevMap.put("pe", "protected "); // NOI18N
127: javaAbbrevMap.put("pu", "public "); // NOI18N
128: javaAbbrevMap.put("re", "return "); // NOI18N
129: javaAbbrevMap.put("sh", "short "); // NOI18N
130: javaAbbrevMap.put("st", "static "); // NOI18N
131: javaAbbrevMap.put("sw", "switch ("); // NOI18N
132: javaAbbrevMap.put("sy", "synchronized "); // NOI18N
133: javaAbbrevMap.put("tr", "transient "); // NOI18N
134: javaAbbrevMap.put("th", "throws "); // NOI18N
135: javaAbbrevMap.put("tw", "throw "); // NOI18N
136: javaAbbrevMap.put("twn", "throw new "); // NOI18N
137: javaAbbrevMap.put("twni", "throw new InternalError();"); // NOI18N
138: javaAbbrevMap.put("twne", "throw new Error();"); // NOI18N
139: javaAbbrevMap.put("wh", "while ("); // NOI18N
140:
141: javaAbbrevMap.put("eq", "equals"); // NOI18N
142: javaAbbrevMap.put("le", "length"); // NOI18N
143:
144: javaAbbrevMap.put("En", "Enumeration"); // NOI18N
145: javaAbbrevMap.put("Ex", "Exception"); // NOI18N
146: javaAbbrevMap.put("Gr", "Graphics"); // NOI18N
147: javaAbbrevMap.put("Ob", "Object"); // NOI18N
148: javaAbbrevMap.put("Re", "Rectangle"); // NOI18N
149: javaAbbrevMap.put("St", "String"); // NOI18N
150: javaAbbrevMap.put("Ve", "Vector"); // NOI18N
151:
152: javaAbbrevMap.put("pst", "printStackTrace();"); // NOI18N
153: javaAbbrevMap.put("tds", "Thread.dumpStack();"); // NOI18N
154:
155: return javaAbbrevMap;
156: }
157:
158: public static MultiKeyBinding[] getJavaKeyBindings() {
159: return new MultiKeyBinding[] {
160: new MultiKeyBinding(new KeyStroke[] {
161: KeyStroke.getKeyStroke(KeyEvent.VK_J,
162: InputEvent.CTRL_MASK),
163: KeyStroke.getKeyStroke(KeyEvent.VK_D, 0) },
164: "macro-debug-var"),
165: new MultiKeyBinding(KeyStroke.getKeyStroke(
166: KeyEvent.VK_T, InputEvent.CTRL_MASK
167: | InputEvent.SHIFT_MASK),
168: ExtKit.commentAction),
169: new MultiKeyBinding(KeyStroke.getKeyStroke(
170: KeyEvent.VK_D, InputEvent.CTRL_MASK
171: | InputEvent.SHIFT_MASK),
172: ExtKit.uncommentAction) };
173: }
174:
175: public static Map getJavaMacroMap() {
176: Map javaMacroMap = new HashMap();
177: javaMacroMap
178: .put(
179: "debug-var",
180: "select-identifier copy-to-clipboard "
181: + "caret-up caret-end-line insert-break \"System.err.println(\\\"\""
182: + "paste-from-clipboard \" = \\\" + \" paste-from-clipboard \" );");
183:
184: return javaMacroMap;
185: }
186:
187: static class JavaTokenColoringInitializer extends
188: SettingsUtil.TokenColoringInitializer {
189:
190: Font boldFont = SettingsDefaults.defaultFont
191: .deriveFont(Font.BOLD);
192: Font italicFont = SettingsDefaults.defaultFont
193: .deriveFont(Font.ITALIC);
194: Settings.Evaluator boldSubst = new SettingsUtil.FontStylePrintColoringEvaluator(
195: Font.BOLD);
196: Settings.Evaluator italicSubst = new SettingsUtil.FontStylePrintColoringEvaluator(
197: Font.ITALIC);
198: Settings.Evaluator lightGraySubst = new SettingsUtil.ForeColorPrintColoringEvaluator(
199: Color.lightGray);
200:
201: Coloring commentColoring = new Coloring(italicFont,
202: Coloring.FONT_MODE_APPLY_STYLE, new Color(0, 92, 0),
203: null);
204:
205: Coloring numbersColoring = new Coloring(null, new Color(120, 0,
206: 0), null);
207:
208: public JavaTokenColoringInitializer() {
209: super (JavaTokenContext.context);
210: }
211:
212: public Object getTokenColoring(
213: TokenContextPath tokenContextPath,
214: TokenCategory tokenIDOrCategory, boolean printingSet) {
215: if (!printingSet) {
216: switch (tokenIDOrCategory.getNumericID()) {
217: case JavaTokenContext.WHITESPACE_ID:
218: case JavaTokenContext.IDENTIFIER_ID:
219: case JavaTokenContext.OPERATORS_ID:
220: return SettingsDefaults.emptyColoring;
221:
222: case JavaTokenContext.ERRORS_ID:
223: return new Coloring(null, Color.white, Color.red);
224:
225: case JavaTokenContext.KEYWORDS_ID:
226: return new Coloring(boldFont,
227: Coloring.FONT_MODE_APPLY_STYLE, new Color(
228: 0, 0, 153), null);
229:
230: case JavaTokenContext.LINE_COMMENT_ID:
231: case JavaTokenContext.BLOCK_COMMENT_ID:
232: return commentColoring;
233:
234: case JavaTokenContext.CHAR_LITERAL_ID:
235: return new Coloring(null, new Color(0, 111, 0),
236: null);
237:
238: case JavaTokenContext.STRING_LITERAL_ID:
239: return new Coloring(null, Color.blue, null);
240:
241: case JavaTokenContext.NUMERIC_LITERALS_ID:
242: return numbersColoring;
243:
244: }
245:
246: } else { // printing set
247: switch (tokenIDOrCategory.getNumericID()) {
248: case JavaTokenContext.LINE_COMMENT_ID:
249: case JavaTokenContext.BLOCK_COMMENT_ID:
250: return lightGraySubst; // print fore color will be gray
251:
252: default:
253: return SettingsUtil.defaultPrintColoringEvaluator;
254: }
255:
256: }
257:
258: return null;
259:
260: }
261:
262: }
263:
264: static class JavaLayerTokenColoringInitializer extends
265: SettingsUtil.TokenColoringInitializer {
266:
267: Font boldFont = SettingsDefaults.defaultFont
268: .deriveFont(Font.BOLD);
269: Settings.Evaluator italicSubst = new SettingsUtil.FontStylePrintColoringEvaluator(
270: Font.ITALIC);
271:
272: public JavaLayerTokenColoringInitializer() {
273: super (JavaLayerTokenContext.context);
274: }
275:
276: public Object getTokenColoring(
277: TokenContextPath tokenContextPath,
278: TokenCategory tokenIDOrCategory, boolean printingSet) {
279: if (!printingSet) {
280: switch (tokenIDOrCategory.getNumericID()) {
281: case JavaLayerTokenContext.METHOD_ID:
282: return new Coloring(boldFont,
283: Coloring.FONT_MODE_APPLY_STYLE, null, null);
284:
285: }
286:
287: } else { // printing set
288: switch (tokenIDOrCategory.getNumericID()) {
289: case JavaLayerTokenContext.METHOD_ID:
290: return italicSubst;
291:
292: default:
293: return SettingsUtil.defaultPrintColoringEvaluator;
294: }
295:
296: }
297:
298: return null;
299: }
300:
301: }
302:
303: }
|