X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Fbits%2FColorTheme.java;h=0c6f6e4a1ea35eccb6c1906948fa41ef6be75640;hb=d36057dfab8def933a64be042b039d76708ac5ba;hp=1c7c62092c4f7ab7d20048fbad027e380066c4d4;hpb=68c5cd6bec3dc425ef5b55fec399d4bdc9afa7cb;p=fanfix.git diff --git a/src/jexer/bits/ColorTheme.java b/src/jexer/bits/ColorTheme.java index 1c7c620..0c6f6e4 100644 --- a/src/jexer/bits/ColorTheme.java +++ b/src/jexer/bits/ColorTheme.java @@ -46,11 +46,19 @@ import java.util.TreeMap; */ public final class ColorTheme { + // ------------------------------------------------------------------------ + // Variables -------------------------------------------------------------- + // ------------------------------------------------------------------------ + /** * The current theme colors. */ private SortedMap colors; + // ------------------------------------------------------------------------ + // Constructors ----------------------------------------------------------- + // ------------------------------------------------------------------------ + /** * Public constructor sets the theme to the default. */ @@ -59,6 +67,10 @@ public final class ColorTheme { setDefaultTheme(); } + // ------------------------------------------------------------------------ + // ColorTheme ------------------------------------------------------------- + // ------------------------------------------------------------------------ + /** * Retrieve the CellAttributes for a named theme color. * @@ -118,6 +130,54 @@ public final class ColorTheme { load(new FileReader(filename)); } + /** + * Set a color based on a text string. Color text string is of the form: + * [ bold ] [ blink ] { foreground on background } + * + * @param key the color key string + * @param text the text string + */ + public void setColorFromString(final String key, final String text) { + boolean bold = false; + boolean blink = false; + String foreColor; + String backColor; + String token; + + StringTokenizer tokenizer = new StringTokenizer(text); + token = tokenizer.nextToken(); + while (token.equals("bold") || token.equals("blink")) { + if (token.equals("bold")) { + bold = true; + token = tokenizer.nextToken(); + } + if (token.equals("blink")) { + blink = true; + token = tokenizer.nextToken(); + } + } + + // What's left is "blah on blah" + foreColor = token.toLowerCase(); + + if (!tokenizer.nextToken().toLowerCase().equals("on")) { + // Invalid line. + return; + } + backColor = tokenizer.nextToken().toLowerCase(); + + CellAttributes color = new CellAttributes(); + if (bold) { + color.setBold(true); + } + if (blink) { + color.setBlink(true); + } + color.setForeColor(Color.getColor(foreColor)); + color.setBackColor(Color.getColor(backColor)); + colors.put(key, color); + } + /** * Read color theme mappings from a Reader. The reader is closed at the * end. @@ -129,41 +189,19 @@ public final class ColorTheme { BufferedReader bufferedReader = new BufferedReader(reader); String line = bufferedReader.readLine(); for (; line != null; line = bufferedReader.readLine()) { - String key; - String bold; - String foreColor; - String backColor; - // Look for lines that resemble: // "key = blah on blah" // "key = bold blah on blah" - StringTokenizer tokenizer = new StringTokenizer(line); - key = tokenizer.nextToken(); - if (!tokenizer.nextToken().equals("=")) { - // Skip this line + // "key = blink bold blah on blah" + // "key = bold blink blah on blah" + // "key = blink blah on blah" + if (line.indexOf('=') == -1) { + // Invalid line. continue; } - bold = tokenizer.nextToken(); - if (!bold.toLowerCase().equals("bold")) { - // "key = blah on blah" - foreColor = bold; - } else { - // "key = bold blah on blah" - foreColor = tokenizer.nextToken().toLowerCase(); - } - if (!tokenizer.nextToken().toLowerCase().equals("on")) { - // Skip this line - continue; - } - backColor = tokenizer.nextToken().toLowerCase(); - - CellAttributes color = new CellAttributes(); - if (bold.equals("bold")) { - color.setBold(true); - } - color.setForeColor(Color.getColor(foreColor)); - color.setBackColor(Color.getColor(backColor)); - colors.put(key, color); + String key = line.substring(0, line.indexOf(':')).trim(); + String text = line.substring(line.indexOf(':') + 1); + setColorFromString(key, text); } // All done. bufferedReader.close(); @@ -324,7 +362,6 @@ public final class ColorTheme { color.setBold(true); colors.put("tcheckbox.active", color); - // TRadioButton color = new CellAttributes(); color.setForeColor(Color.WHITE); @@ -422,10 +459,18 @@ public final class ColorTheme { color.setBold(false); colors.put("ttreeview.unreadable", color); color = new CellAttributes(); - color.setForeColor(Color.BLACK); + // color.setForeColor(Color.BLACK); + // color.setBackColor(Color.BLUE); + // color.setBold(true); + color.setForeColor(Color.WHITE); color.setBackColor(Color.BLUE); - color.setBold(true); + color.setBold(false); colors.put("ttreeview.inactive", color); + color = new CellAttributes(); + color.setForeColor(Color.BLACK); + color.setBackColor(Color.WHITE); + color.setBold(false); + colors.put("ttreeview.selected.inactive", color); // TList color = new CellAttributes(); @@ -444,10 +489,18 @@ public final class ColorTheme { color.setBold(false); colors.put("tlist.unreadable", color); color = new CellAttributes(); - color.setForeColor(Color.BLACK); + // color.setForeColor(Color.BLACK); + // color.setBackColor(Color.BLUE); + // color.setBold(true); + color.setForeColor(Color.WHITE); color.setBackColor(Color.BLUE); - color.setBold(true); + color.setBold(false); colors.put("tlist.inactive", color); + color = new CellAttributes(); + color.setForeColor(Color.BLACK); + color.setBackColor(Color.WHITE); + color.setBold(false); + colors.put("tlist.selected.inactive", color); // TStatusBar color = new CellAttributes(); @@ -475,4 +528,14 @@ public final class ColorTheme { } + /** + * Make human-readable description of this Cell. + * + * @return displayable String + */ + @Override + public String toString() { + return colors.toString(); + } + }