1 19 20 package org.netbeans.editor.ext.java; 21 22 import java.awt.event.KeyEvent ; 23 import java.awt.event.InputEvent ; 24 import java.awt.Font ; 25 import java.awt.Color ; 26 import javax.swing.KeyStroke ; 27 import java.util.Map ; 28 import java.util.HashMap ; 29 import java.util.TreeMap ; 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 48 49 public class JavaSettingsDefaults extends ExtSettingsDefaults { 50 51 public static final Boolean defaultCaretSimpleMatchBrace = Boolean.FALSE; 52 public static final Boolean 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 defaultWordMatchMatchCase = Boolean.TRUE; 57 58 public static final Boolean defaultJavaFormatSpaceBeforeParenthesis = Boolean.FALSE; 60 public static final Boolean defaultJavaFormatSpaceAfterComma = Boolean.TRUE; 61 public static final Boolean defaultJavaFormatNewlineBeforeBrace = Boolean.FALSE; 62 public static final Boolean defaultJavaFormatLeadingSpaceInComment = Boolean.FALSE; 63 public static final Boolean defaultJavaFormatLeadingStarInComment = Boolean.TRUE; 64 public static final Integer defaultJavaFormatStatementContinuationIndent = new Integer (8); 65 66 public static final Boolean defaultPairCharactersCompletion = Boolean.TRUE; 67 68 69 public static final Boolean defaultFormatSpaceBeforeParenthesis = defaultJavaFormatSpaceBeforeParenthesis; 70 71 public static final Boolean defaultFormatSpaceAfterComma = defaultJavaFormatSpaceAfterComma; 72 73 public static final Boolean defaultFormatNewlineBeforeBrace = defaultJavaFormatNewlineBeforeBrace; 74 75 public static final Boolean defaultFormatLeadingSpaceInComment = defaultJavaFormatLeadingSpaceInComment; 76 77 public static final Boolean defaultCodeFoldingEnable = Boolean.TRUE; 78 public static final Boolean defaultCodeFoldingCollapseMethod = Boolean.FALSE; 79 public static final Boolean defaultCodeFoldingCollapseInnerClass = Boolean.FALSE; 80 public static final Boolean defaultCodeFoldingCollapseImport = Boolean.FALSE; 81 public static final Boolean defaultCodeFoldingCollapseJavadoc = Boolean.FALSE; 82 public static final Boolean defaultCodeFoldingCollapseInitialComment = Boolean.FALSE; 83 84 public static final Boolean defaultGotoClassCaseSensitive = Boolean.FALSE; 85 public static final Boolean defaultGotoClassShowInnerClasses = Boolean.FALSE; 86 public static final Boolean 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 defaultWordMatchStaticWords 104 = "Exception IntrospectionException FileNotFoundException IOException" + " ArrayIndexOutOfBoundsException ClassCastException ClassNotFoundException" + " CloneNotSupportedException NullPointerException NumberFormatException" + " SQLException IllegalAccessException IllegalArgumentException"; 109 public static Map getJavaAbbrevMap() { 110 Map javaAbbrevMap = new TreeMap (); 111 javaAbbrevMap.put("sout", "System.out.println(\"|\");"); javaAbbrevMap.put("serr", "System.err.println(\"|\");"); 114 javaAbbrevMap.put("psf", "private static final "); javaAbbrevMap.put("psfi", "private static final int "); javaAbbrevMap.put("psfs", "private static final String "); javaAbbrevMap.put("psfb", "private static final boolean "); javaAbbrevMap.put("Psf", "public static final "); javaAbbrevMap.put("Psfi", "public static final int "); javaAbbrevMap.put("Psfs", "public static final String "); javaAbbrevMap.put("Psfb", "public static final boolean "); 123 124 javaAbbrevMap.put("ab", "abstract "); javaAbbrevMap.put("bo", "boolean "); javaAbbrevMap.put("br", "break"); javaAbbrevMap.put("ca", "catch ("); javaAbbrevMap.put("cl", "class "); javaAbbrevMap.put("cn", "continue"); javaAbbrevMap.put("df", "default:"); javaAbbrevMap.put("ex", "extends "); javaAbbrevMap.put("fa", "false"); javaAbbrevMap.put("fi", "final "); javaAbbrevMap.put("fl", "float "); javaAbbrevMap.put("fy", "finally "); javaAbbrevMap.put("im", "implements "); javaAbbrevMap.put("ir", "import "); javaAbbrevMap.put("iof", "instanceof "); javaAbbrevMap.put("ie", "interface "); javaAbbrevMap.put("pr", "private "); javaAbbrevMap.put("pe", "protected "); javaAbbrevMap.put("pu", "public "); javaAbbrevMap.put("re", "return "); javaAbbrevMap.put("st", "static "); javaAbbrevMap.put("sw", "switch ("); javaAbbrevMap.put("sy", "synchronized "); javaAbbrevMap.put("th", "throws "); javaAbbrevMap.put("tw", "throw "); javaAbbrevMap.put("twn", "throw new "); javaAbbrevMap.put("wh", "while ("); 152 javaAbbrevMap.put("eq", "equals"); javaAbbrevMap.put("le", "length"); 155 javaAbbrevMap.put("En", "Enumeration"); javaAbbrevMap.put("Ex", "Exception"); javaAbbrevMap.put("Ob", "Object"); javaAbbrevMap.put("St", "String"); 160 javaAbbrevMap.put("pst", "printStackTrace();"); javaAbbrevMap.put("tds", "Thread.dumpStack();"); 163 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", "while (${EXP instanceof=\"java.lang.Boolean\" default=\"exp\"}) {\n" + "${selection line}${cursor}\n" + "}\n" 234 ); 235 javaAbbrevMap.put("dowhile", "do {\n" + "${selection line}${cursor}\n" + "} while (${EXP instanceof=\"java.lang.Boolean\" default=\"exp\"});\n" ); 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", "$TYPE default=\"Object\"} ${OBJ newVarName default=\"obj\"} = new ${TYPE}(${cursor});" ); 256 javaAbbrevMap.put("psvm", "public static void main(String[] args) {\n" + "${cursor}\n" + "}\n" ); 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 [] { 270 KeyStroke.getKeyStroke(KeyEvent.VK_J, MENU_MASK), 271 KeyStroke.getKeyStroke(KeyEvent.VK_D, 0) 272 }, 273 "macro-debug-var" ), 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 [] { 285 KeyStroke.getKeyStroke(KeyEvent.VK_R, MENU_MASK), 286 }, 287 "in-place-refactoring" 288 ), 289 }; 290 } 291 292 public static Map getJavaMacroMap() { 293 Map javaMacroMap = new HashMap (); 294 javaMacroMap.put( "debug-var", "select-identifier copy-to-clipboard " + "caret-up caret-end-line insert-break \"System.err.println(\\\"\"" + 296 "paste-from-clipboard \" = \\\" + \" paste-from-clipboard \" );" ); 298 return javaMacroMap; 299 } 300 301 static class JavaTokenColoringInitializer 302 extends SettingsUtil.TokenColoringInitializer { 303 304 Font boldFont = SettingsDefaults.defaultFont.deriveFont(Font.BOLD); 305 Font 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 (120, 120, 120)); 309 310 Coloring commentColoring = new Coloring(null, new Color (115, 115, 115), null); 311 312 Coloring numbersColoring = new Coloring(null, new Color (120, 0, 0), null); 313 314 public JavaTokenColoringInitializer() { 315 super(JavaTokenContext.context); 316 } 317 318 public Object 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 (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 (0, 111, 0), null); 341 342 case JavaTokenContext.STRING_LITERAL_ID: 343 return new Coloring(null, new Color (153, 0, 107), null); 344 345 case JavaTokenContext.NUMERIC_LITERALS_ID: 346 return numbersColoring; 347 348 case JavaTokenContext.ANNOTATION_ID: return new Coloring(null, new Color (0, 111, 0), null); 350 351 } 352 353 } else { switch (tokenIDOrCategory.getNumericID()) { 355 case JavaTokenContext.LINE_COMMENT_ID: 356 case JavaTokenContext.BLOCK_COMMENT_ID: 357 return lightGraySubst; 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 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 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 { 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 |