X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjexer%2Fbits%2FColorTheme.java;h=e55398a8235f38b4677f2dc9cd81edf514cdf735;hb=6f8ff91a29056209f9fd5f40e2dcf1ae285e0210;hp=626a6c8979bd81a451fdbf2c7ea5466cd0d42fdd;hpb=e16dda65585466c8987bd1efd718431450a96605;p=fanfix.git diff --git a/src/jexer/bits/ColorTheme.java b/src/jexer/bits/ColorTheme.java index 626a6c8..e55398a 100644 --- a/src/jexer/bits/ColorTheme.java +++ b/src/jexer/bits/ColorTheme.java @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (C) 2016 Kevin Lamonte + * Copyright (C) 2017 Kevin Lamonte * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -32,6 +32,7 @@ import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; +import java.io.Reader; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -114,31 +115,54 @@ public final class ColorTheme { * @throws IOException if the I/O fails */ public void load(final String filename) throws IOException { - BufferedReader reader = new BufferedReader(new FileReader(filename)); - String line = reader.readLine(); - for (; line != null; line = reader.readLine()) { + load(new FileReader(filename)); + } + + /** + * Read color theme mappings from a Reader. The reader is closed at the + * end. + * + * @param reader the reader to read from + * @throws IOException if the I/O fails + */ + public void load(final Reader reader) throws IOException { + BufferedReader bufferedReader = new BufferedReader(reader); + String line = bufferedReader.readLine(); + for (; line != null; line = bufferedReader.readLine()) { String key; - String bold; + boolean bold = false; + boolean blink = false; String foreColor; String backColor; + String token; // Look for lines that resemble: // "key = blah on blah" // "key = bold blah on blah" + // "key = blink bold blah on blah" + // "key = bold blink blah on blah" + // "key = blink blah on blah" StringTokenizer tokenizer = new StringTokenizer(line); key = tokenizer.nextToken(); if (!tokenizer.nextToken().equals("=")) { // Skip this 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(); + 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" or "blah" + foreColor = token.toLowerCase(); + if (!tokenizer.nextToken().toLowerCase().equals("on")) { // Skip this line continue; @@ -146,15 +170,18 @@ public final class ColorTheme { backColor = tokenizer.nextToken().toLowerCase(); CellAttributes color = new CellAttributes(); - if (bold.equals("bold")) { + if (bold) { color.setBold(true); } + if (blink) { + color.setBlink(true); + } color.setForeColor(Color.getColor(foreColor)); color.setBackColor(Color.getColor(backColor)); colors.put(key, color); } // All done. - reader.close(); + bufferedReader.close(); } /** @@ -240,12 +267,12 @@ public final class ColorTheme { color.setBold(false); colors.put("twindow.background.windowmove", color); - // TApplication background + // TDesktop background color = new CellAttributes(); color.setForeColor(Color.BLUE); color.setBackColor(Color.WHITE); color.setBold(false); - colors.put("tapplication.background", color); + colors.put("tdesktop.background", color); // TButton text color = new CellAttributes(); @@ -284,7 +311,7 @@ public final class ColorTheme { // TText text color = new CellAttributes(); color.setForeColor(Color.WHITE); - color.setBackColor(Color.BLACK); + color.setBackColor(Color.BLUE); color.setBold(false); colors.put("ttext", color); @@ -437,10 +464,27 @@ public final class ColorTheme { color.setBold(true); colors.put("tlist.inactive", color); + // TStatusBar + color = new CellAttributes(); + color.setForeColor(Color.BLACK); + color.setBackColor(Color.WHITE); + color.setBold(false); + colors.put("tstatusbar.text", color); + color = new CellAttributes(); + color.setForeColor(Color.RED); + color.setBackColor(Color.WHITE); + color.setBold(false); + colors.put("tstatusbar.button", color); + color = new CellAttributes(); + color.setForeColor(Color.WHITE); + color.setBackColor(Color.BLUE); + color.setBold(false); + colors.put("tstatusbar.selected", color); + // TEditor color = new CellAttributes(); color.setForeColor(Color.WHITE); - color.setBackColor(Color.BLACK); + color.setBackColor(Color.BLUE); color.setBold(false); colors.put("teditor", color);