9576ad1e52b0b9ddd854a5693b64122873228373
2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2017 Kevin Lamonte
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
29 package jexer
.teditor
;
31 import java
.util
.SortedMap
;
32 import java
.util
.TreeMap
;
34 import jexer
.bits
.CellAttributes
;
35 import jexer
.bits
.Color
;
38 * Highlighter provides color choices for certain text strings.
40 public class Highlighter
{
43 * The highlighter colors.
45 private SortedMap
<String
, CellAttributes
> colors
;
48 * Public constructor sets the theme to the default.
50 public Highlighter() {
51 colors
= new TreeMap
<String
, CellAttributes
>();
55 * See if this is a character that should split a word.
57 * @param ch the character
58 * @return true if the word should be split
60 public boolean shouldSplit(final char ch
) {
61 // For now, split on punctuation
62 String punctuation
= "'\"\\<>{}[]!@#$%^&*();:.,-+/*?";
63 if (punctuation
.indexOf(ch
) != -1) {
70 * Retrieve the CellAttributes for a named theme color.
72 * @param name theme color name, e.g. "twindow.border"
73 * @return color associated with name, e.g. bold yellow on blue
75 public CellAttributes
getColor(final String name
) {
76 CellAttributes attr
= (CellAttributes
) colors
.get(name
);
81 * Sets to defaults that resemble the Borland IDE colors.
83 public void setJavaColors() {
86 String
[] keywords
= {
87 "boolean", "byte", "short", "int", "long", "char", "float",
88 "double", "void", "new",
89 "static", "final", "volatile", "synchronized", "abstract",
90 "public", "private", "protected",
91 "class", "interface", "extends", "implements",
92 "if", "else", "do", "while", "for", "break", "continue",
93 "switch", "case", "default",
95 color
= new CellAttributes();
96 color
.setForeColor(Color
.WHITE
);
97 color
.setBackColor(Color
.BLUE
);
99 for (String str
: keywords
) {
100 colors
.put(str
, color
);
103 String
[] operators
= {
104 "[", "]", "(", ")", "{", "}",
105 "*", "-", "+", "/", "=", "%",
106 "^", "&", "!", "<<", ">>", "<<<", ">>>",
108 ">", "<", ">=", "<=", "!=", "==",
109 ",", ";", ".", "?", ":",
111 color
= new CellAttributes();
112 color
.setForeColor(Color
.CYAN
);
113 color
.setBackColor(Color
.BLUE
);
115 for (String str
: operators
) {
116 colors
.put(str
, color
);
119 String
[] packageKeywords
= {
122 color
= new CellAttributes();
123 color
.setForeColor(Color
.GREEN
);
124 color
.setBackColor(Color
.BLUE
);
126 for (String str
: packageKeywords
) {
127 colors
.put(str
, color
);