2 * Jexer - Java Text User Interface
4 * License: LGPLv3 or later
6 * This module is licensed under the GNU Lesser General Public License
7 * Version 3. Please see the file "COPYING" in this directory for more
8 * information about the GNU Lesser General Public License Version 3.
10 * Copyright (C) 2015 Kevin Lamonte
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 3 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this program; if not, see
24 * http://www.gnu.org/licenses/, or write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
28 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
33 import java
.io
.BufferedReader
;
34 import java
.io
.FileReader
;
35 import java
.io
.FileWriter
;
36 import java
.io
.IOException
;
37 import java
.util
.SortedMap
;
38 import java
.util
.StringTokenizer
;
39 import java
.util
.TreeMap
;
42 * ColorTheme is a collection of colors keyed by string. A default theme is
43 * also provided that matches the blue-and-white theme used by Turbo Vision.
45 public final class ColorTheme
{
48 * The current theme colors.
50 private SortedMap
<String
, CellAttributes
> colors
;
53 * Public constructor sets the theme to the default.
56 colors
= new TreeMap
<String
, CellAttributes
>();
61 * Retrieve the CellAttributes for a named theme color.
63 * @param name theme color name, e.g. "twindow.border"
64 * @return color associated with name, e.g. bold yellow on blue
66 public CellAttributes
getColor(final String name
) {
67 CellAttributes attr
= (CellAttributes
) colors
.get(name
);
72 * Set the color for a named theme color.
74 * @param name theme color name, e.g. "twindow.border"
75 * @param color the new color to associate with name, e.g. bold yellow on
78 public void setColor(final String name
, final CellAttributes color
) {
79 colors
.put(name
, color
);
83 * Save the color theme mappings to an ASCII file.
85 * @param filename file to write to
86 * @throws IOException if the I/O fails
88 public void save(final String filename
) throws IOException
{
89 FileWriter file
= new FileWriter(filename
);
90 for (String key
: colors
.keySet()) {
91 CellAttributes color
= getColor(key
);
92 file
.write(String
.format("%s = %s\n", key
, color
));
98 * Read color theme mappings from an ASCII file.
100 * @param filename file to read from
101 * @throws IOException if the I/O fails
103 public void load(final String filename
) throws IOException
{
104 BufferedReader reader
= new BufferedReader(new FileReader(filename
));
105 String line
= reader
.readLine();
106 for (; line
!= null; line
= reader
.readLine()) {
112 // Look for lines that resemble:
113 // "key = blah on blah"
114 // "key = bold blah on blah"
115 StringTokenizer tokenizer
= new StringTokenizer(line
);
116 key
= tokenizer
.nextToken();
117 if (!tokenizer
.nextToken().equals("=")) {
121 bold
= tokenizer
.nextToken();
122 if (!bold
.toLowerCase().equals("bold")) {
123 // "key = blah on blah"
126 // "key = bold blah on blah"
127 foreColor
= tokenizer
.nextToken().toLowerCase();
129 if (!tokenizer
.nextToken().toLowerCase().equals("on")) {
133 backColor
= tokenizer
.nextToken().toLowerCase();
135 CellAttributes color
= new CellAttributes();
136 if (bold
.equals("bold")) {
139 color
.setForeColor(Color
.getColor(foreColor
));
140 color
.setBackColor(Color
.getColor(backColor
));
141 colors
.put(key
, color
);
148 * Sets to defaults that resemble the Borland IDE colors.
150 public void setDefaultTheme() {
151 CellAttributes color
;
154 color
= new CellAttributes();
155 color
.setForeColor(Color
.WHITE
);
156 color
.setBackColor(Color
.BLUE
);
158 colors
.put("twindow.border", color
);
160 // TWindow background
161 color
= new CellAttributes();
162 color
.setForeColor(Color
.YELLOW
);
163 color
.setBackColor(Color
.BLUE
);
165 colors
.put("twindow.background", color
);
167 // TWindow border - inactive
168 color
= new CellAttributes();
169 color
.setForeColor(Color
.BLACK
);
170 color
.setBackColor(Color
.BLUE
);
172 colors
.put("twindow.border.inactive", color
);
174 // TWindow background - inactive
175 color
= new CellAttributes();
176 color
.setForeColor(Color
.YELLOW
);
177 color
.setBackColor(Color
.BLUE
);
179 colors
.put("twindow.background.inactive", color
);
181 // TWindow border - modal
182 color
= new CellAttributes();
183 color
.setForeColor(Color
.WHITE
);
184 color
.setBackColor(Color
.WHITE
);
186 colors
.put("twindow.border.modal", color
);
188 // TWindow background - modal
189 color
= new CellAttributes();
190 color
.setForeColor(Color
.BLACK
);
191 color
.setBackColor(Color
.WHITE
);
192 color
.setBold(false);
193 colors
.put("twindow.background.modal", color
);
195 // TWindow border - modal + inactive
196 color
= new CellAttributes();
197 color
.setForeColor(Color
.BLACK
);
198 color
.setBackColor(Color
.WHITE
);
200 colors
.put("twindow.border.modal.inactive", color
);
202 // TWindow background - modal + inactive
203 color
= new CellAttributes();
204 color
.setForeColor(Color
.BLACK
);
205 color
.setBackColor(Color
.WHITE
);
206 color
.setBold(false);
207 colors
.put("twindow.background.modal.inactive", color
);
209 // TWindow border - during window movement - modal
210 color
= new CellAttributes();
211 color
.setForeColor(Color
.GREEN
);
212 color
.setBackColor(Color
.WHITE
);
214 colors
.put("twindow.border.modal.windowmove", color
);
216 // TWindow border - during window movement
217 color
= new CellAttributes();
218 color
.setForeColor(Color
.GREEN
);
219 color
.setBackColor(Color
.BLUE
);
221 colors
.put("twindow.border.windowmove", color
);
223 // TWindow background - during window movement
224 color
= new CellAttributes();
225 color
.setForeColor(Color
.YELLOW
);
226 color
.setBackColor(Color
.BLUE
);
227 color
.setBold(false);
228 colors
.put("twindow.background.windowmove", color
);
230 // TApplication background
231 color
= new CellAttributes();
232 color
.setForeColor(Color
.BLUE
);
233 color
.setBackColor(Color
.WHITE
);
234 color
.setBold(false);
235 colors
.put("tapplication.background", color
);
238 color
= new CellAttributes();
239 color
.setForeColor(Color
.BLACK
);
240 color
.setBackColor(Color
.GREEN
);
241 color
.setBold(false);
242 colors
.put("tbutton.inactive", color
);
243 color
= new CellAttributes();
244 color
.setForeColor(Color
.WHITE
);
245 color
.setBackColor(Color
.GREEN
);
247 colors
.put("tbutton.active", color
);
248 color
= new CellAttributes();
249 color
.setForeColor(Color
.BLACK
);
250 color
.setBackColor(Color
.WHITE
);
252 colors
.put("tbutton.disabled", color
);
253 color
= new CellAttributes();
254 color
.setForeColor(Color
.YELLOW
);
255 color
.setBackColor(Color
.GREEN
);
257 colors
.put("tbutton.mnemonic", color
);
258 color
= new CellAttributes();
259 color
.setForeColor(Color
.YELLOW
);
260 color
.setBackColor(Color
.GREEN
);
262 colors
.put("tbutton.mnemonic.highlighted", color
);
265 color
= new CellAttributes();
266 color
.setForeColor(Color
.WHITE
);
267 color
.setBackColor(Color
.BLUE
);
269 colors
.put("tlabel", color
);
272 color
= new CellAttributes();
273 color
.setForeColor(Color
.WHITE
);
274 color
.setBackColor(Color
.BLACK
);
275 color
.setBold(false);
276 colors
.put("ttext", color
);
279 color
= new CellAttributes();
280 color
.setForeColor(Color
.WHITE
);
281 color
.setBackColor(Color
.BLUE
);
282 color
.setBold(false);
283 colors
.put("tfield.inactive", color
);
284 color
= new CellAttributes();
285 color
.setForeColor(Color
.YELLOW
);
286 color
.setBackColor(Color
.BLACK
);
288 colors
.put("tfield.active", color
);
291 color
= new CellAttributes();
292 color
.setForeColor(Color
.WHITE
);
293 color
.setBackColor(Color
.BLUE
);
294 color
.setBold(false);
295 colors
.put("tcheckbox.inactive", color
);
296 color
= new CellAttributes();
297 color
.setForeColor(Color
.YELLOW
);
298 color
.setBackColor(Color
.BLACK
);
300 colors
.put("tcheckbox.active", color
);
304 color
= new CellAttributes();
305 color
.setForeColor(Color
.WHITE
);
306 color
.setBackColor(Color
.BLUE
);
307 color
.setBold(false);
308 colors
.put("tradiobutton.inactive", color
);
309 color
= new CellAttributes();
310 color
.setForeColor(Color
.YELLOW
);
311 color
.setBackColor(Color
.BLACK
);
313 colors
.put("tradiobutton.active", color
);
316 color
= new CellAttributes();
317 color
.setForeColor(Color
.WHITE
);
318 color
.setBackColor(Color
.BLUE
);
319 color
.setBold(false);
320 colors
.put("tradiogroup.inactive", color
);
321 color
= new CellAttributes();
322 color
.setForeColor(Color
.YELLOW
);
323 color
.setBackColor(Color
.BLUE
);
325 colors
.put("tradiogroup.active", color
);
328 color
= new CellAttributes();
329 color
.setForeColor(Color
.BLACK
);
330 color
.setBackColor(Color
.WHITE
);
331 color
.setBold(false);
332 colors
.put("tmenu", color
);
333 color
= new CellAttributes();
334 color
.setForeColor(Color
.BLACK
);
335 color
.setBackColor(Color
.GREEN
);
336 color
.setBold(false);
337 colors
.put("tmenu.highlighted", color
);
338 color
= new CellAttributes();
339 color
.setForeColor(Color
.RED
);
340 color
.setBackColor(Color
.WHITE
);
341 color
.setBold(false);
342 colors
.put("tmenu.mnemonic", color
);
343 color
= new CellAttributes();
344 color
.setForeColor(Color
.RED
);
345 color
.setBackColor(Color
.GREEN
);
346 color
.setBold(false);
347 colors
.put("tmenu.mnemonic.highlighted", color
);
348 color
= new CellAttributes();
349 color
.setForeColor(Color
.BLACK
);
350 color
.setBackColor(Color
.WHITE
);
352 colors
.put("tmenu.disabled", color
);
355 color
= new CellAttributes();
356 color
.setForeColor(Color
.BLUE
);
357 color
.setBackColor(Color
.BLUE
);
359 colors
.put("tprogressbar.complete", color
);
360 color
= new CellAttributes();
361 color
.setForeColor(Color
.WHITE
);
362 color
.setBackColor(Color
.BLUE
);
363 color
.setBold(false);
364 colors
.put("tprogressbar.incomplete", color
);
366 // THScroller / TVScroller
367 color
= new CellAttributes();
368 color
.setForeColor(Color
.CYAN
);
369 color
.setBackColor(Color
.BLUE
);
370 color
.setBold(false);
371 colors
.put("tscroller.bar", color
);
372 color
= new CellAttributes();
373 color
.setForeColor(Color
.BLUE
);
374 color
.setBackColor(Color
.CYAN
);
375 color
.setBold(false);
376 colors
.put("tscroller.arrows", color
);
379 color
= new CellAttributes();
380 color
.setForeColor(Color
.WHITE
);
381 color
.setBackColor(Color
.BLUE
);
382 color
.setBold(false);
383 colors
.put("ttreeview", color
);
384 color
= new CellAttributes();
385 color
.setForeColor(Color
.GREEN
);
386 color
.setBackColor(Color
.BLUE
);
388 colors
.put("ttreeview.expandbutton", color
);
389 color
= new CellAttributes();
390 color
.setForeColor(Color
.BLACK
);
391 color
.setBackColor(Color
.CYAN
);
392 color
.setBold(false);
393 colors
.put("ttreeview.selected", color
);
394 color
= new CellAttributes();
395 color
.setForeColor(Color
.RED
);
396 color
.setBackColor(Color
.BLUE
);
397 color
.setBold(false);
398 colors
.put("ttreeview.unreadable", color
);
399 color
= new CellAttributes();
400 color
.setForeColor(Color
.BLACK
);
401 color
.setBackColor(Color
.BLUE
);
403 colors
.put("ttreeview.inactive", color
);
406 color
= new CellAttributes();
407 color
.setForeColor(Color
.WHITE
);
408 color
.setBackColor(Color
.BLUE
);
409 color
.setBold(false);
410 colors
.put("tdirectorylist", color
);
411 color
= new CellAttributes();
412 color
.setForeColor(Color
.BLACK
);
413 color
.setBackColor(Color
.CYAN
);
414 color
.setBold(false);
415 colors
.put("tdirectorylist.selected", color
);
416 color
= new CellAttributes();
417 color
.setForeColor(Color
.BLACK
);
418 color
.setBackColor(Color
.CYAN
);
419 color
.setBold(false);
420 colors
.put("tdirectorylist.unreadable", color
);
421 color
= new CellAttributes();
422 color
.setForeColor(Color
.BLACK
);
423 color
.setBackColor(Color
.BLUE
);
425 colors
.put("tdirectorylist.inactive", color
);
428 color
= new CellAttributes();
429 color
.setForeColor(Color
.WHITE
);
430 color
.setBackColor(Color
.BLACK
);
431 color
.setBold(false);
432 colors
.put("teditor", color
);