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 * Save the color theme mappings to an ASCII file.
74 * @param filename file to write to
75 * @throws IOException if the I/O fails
77 public void save(final String filename
) throws IOException
{
78 FileWriter file
= new FileWriter(filename
);
79 for (String key
: colors
.keySet()) {
80 CellAttributes color
= getColor(key
);
81 file
.write(String
.format("%s = %s\n", key
, color
));
87 * Read color theme mappings from an ASCII file.
89 * @param filename file to read from
90 * @throws IOException if the I/O fails
92 public void load(final String filename
) throws IOException
{
93 BufferedReader reader
= new BufferedReader(new FileReader(filename
));
94 String line
= reader
.readLine();
95 for (; line
!= null; line
= reader
.readLine()) {
101 // Look for lines that resemble:
102 // "key = blah on blah"
103 // "key = bold blah on blah"
104 StringTokenizer tokenizer
= new StringTokenizer(line
);
105 key
= tokenizer
.nextToken();
106 if (!tokenizer
.nextToken().equals("=")) {
110 bold
= tokenizer
.nextToken();
111 if (!bold
.toLowerCase().equals("bold")) {
112 // "key = blah on blah"
115 // "key = bold blah on blah"
116 foreColor
= tokenizer
.nextToken().toLowerCase();
118 if (!tokenizer
.nextToken().toLowerCase().equals("on")) {
122 backColor
= tokenizer
.nextToken().toLowerCase();
124 CellAttributes color
= new CellAttributes();
125 if (bold
.equals("bold")) {
128 color
.setForeColor(Color
.getColor(foreColor
));
129 color
.setBackColor(Color
.getColor(backColor
));
130 colors
.put(key
, color
);
137 * Sets to defaults that resemble the Borland IDE colors.
139 public void setDefaultTheme() {
140 CellAttributes color
;
143 color
= new CellAttributes();
144 color
.setForeColor(Color
.WHITE
);
145 color
.setBackColor(Color
.BLUE
);
147 colors
.put("twindow.border", color
);
149 // TWindow background
150 color
= new CellAttributes();
151 color
.setForeColor(Color
.YELLOW
);
152 color
.setBackColor(Color
.BLUE
);
154 colors
.put("twindow.background", color
);
156 // TWindow border - inactive
157 color
= new CellAttributes();
158 color
.setForeColor(Color
.BLACK
);
159 color
.setBackColor(Color
.BLUE
);
161 colors
.put("twindow.border.inactive", color
);
163 // TWindow background - inactive
164 color
= new CellAttributes();
165 color
.setForeColor(Color
.YELLOW
);
166 color
.setBackColor(Color
.BLUE
);
168 colors
.put("twindow.background.inactive", color
);
170 // TWindow border - modal
171 color
= new CellAttributes();
172 color
.setForeColor(Color
.WHITE
);
173 color
.setBackColor(Color
.WHITE
);
175 colors
.put("twindow.border.modal", color
);
177 // TWindow background - modal
178 color
= new CellAttributes();
179 color
.setForeColor(Color
.BLACK
);
180 color
.setBackColor(Color
.WHITE
);
181 color
.setBold(false);
182 colors
.put("twindow.background.modal", color
);
184 // TWindow border - modal + inactive
185 color
= new CellAttributes();
186 color
.setForeColor(Color
.BLACK
);
187 color
.setBackColor(Color
.WHITE
);
189 colors
.put("twindow.border.modal.inactive", color
);
191 // TWindow background - modal + inactive
192 color
= new CellAttributes();
193 color
.setForeColor(Color
.BLACK
);
194 color
.setBackColor(Color
.WHITE
);
195 color
.setBold(false);
196 colors
.put("twindow.background.modal.inactive", color
);
198 // TWindow border - during window movement - modal
199 color
= new CellAttributes();
200 color
.setForeColor(Color
.GREEN
);
201 color
.setBackColor(Color
.WHITE
);
203 colors
.put("twindow.border.modal.windowmove", color
);
205 // TWindow border - during window movement
206 color
= new CellAttributes();
207 color
.setForeColor(Color
.GREEN
);
208 color
.setBackColor(Color
.BLUE
);
210 colors
.put("twindow.border.windowmove", color
);
212 // TWindow background - during window movement
213 color
= new CellAttributes();
214 color
.setForeColor(Color
.YELLOW
);
215 color
.setBackColor(Color
.BLUE
);
216 color
.setBold(false);
217 colors
.put("twindow.background.windowmove", color
);
219 // TApplication background
220 color
= new CellAttributes();
221 color
.setForeColor(Color
.BLUE
);
222 color
.setBackColor(Color
.WHITE
);
223 color
.setBold(false);
224 colors
.put("tapplication.background", color
);
227 color
= new CellAttributes();
228 color
.setForeColor(Color
.BLACK
);
229 color
.setBackColor(Color
.GREEN
);
230 color
.setBold(false);
231 colors
.put("tbutton.inactive", color
);
232 color
= new CellAttributes();
233 color
.setForeColor(Color
.WHITE
);
234 color
.setBackColor(Color
.GREEN
);
236 colors
.put("tbutton.active", color
);
237 color
= new CellAttributes();
238 color
.setForeColor(Color
.BLACK
);
239 color
.setBackColor(Color
.WHITE
);
241 colors
.put("tbutton.disabled", color
);
242 color
= new CellAttributes();
243 color
.setForeColor(Color
.YELLOW
);
244 color
.setBackColor(Color
.GREEN
);
246 colors
.put("tbutton.mnemonic", color
);
247 color
= new CellAttributes();
248 color
.setForeColor(Color
.YELLOW
);
249 color
.setBackColor(Color
.GREEN
);
251 colors
.put("tbutton.mnemonic.highlighted", color
);
254 color
= new CellAttributes();
255 color
.setForeColor(Color
.WHITE
);
256 color
.setBackColor(Color
.BLUE
);
258 colors
.put("tlabel", color
);
261 color
= new CellAttributes();
262 color
.setForeColor(Color
.WHITE
);
263 color
.setBackColor(Color
.BLACK
);
264 color
.setBold(false);
265 colors
.put("ttext", color
);
268 color
= new CellAttributes();
269 color
.setForeColor(Color
.WHITE
);
270 color
.setBackColor(Color
.BLUE
);
271 color
.setBold(false);
272 colors
.put("tfield.inactive", color
);
273 color
= new CellAttributes();
274 color
.setForeColor(Color
.YELLOW
);
275 color
.setBackColor(Color
.BLACK
);
277 colors
.put("tfield.active", color
);
280 color
= new CellAttributes();
281 color
.setForeColor(Color
.WHITE
);
282 color
.setBackColor(Color
.BLUE
);
283 color
.setBold(false);
284 colors
.put("tcheckbox.inactive", color
);
285 color
= new CellAttributes();
286 color
.setForeColor(Color
.YELLOW
);
287 color
.setBackColor(Color
.BLACK
);
289 colors
.put("tcheckbox.active", color
);
293 color
= new CellAttributes();
294 color
.setForeColor(Color
.WHITE
);
295 color
.setBackColor(Color
.BLUE
);
296 color
.setBold(false);
297 colors
.put("tradiobutton.inactive", color
);
298 color
= new CellAttributes();
299 color
.setForeColor(Color
.YELLOW
);
300 color
.setBackColor(Color
.BLACK
);
302 colors
.put("tradiobutton.active", color
);
305 color
= new CellAttributes();
306 color
.setForeColor(Color
.WHITE
);
307 color
.setBackColor(Color
.BLUE
);
308 color
.setBold(false);
309 colors
.put("tradiogroup.inactive", color
);
310 color
= new CellAttributes();
311 color
.setForeColor(Color
.YELLOW
);
312 color
.setBackColor(Color
.BLUE
);
314 colors
.put("tradiogroup.active", color
);
317 color
= new CellAttributes();
318 color
.setForeColor(Color
.BLACK
);
319 color
.setBackColor(Color
.WHITE
);
320 color
.setBold(false);
321 colors
.put("tmenu", color
);
322 color
= new CellAttributes();
323 color
.setForeColor(Color
.BLACK
);
324 color
.setBackColor(Color
.GREEN
);
325 color
.setBold(false);
326 colors
.put("tmenu.highlighted", color
);
327 color
= new CellAttributes();
328 color
.setForeColor(Color
.RED
);
329 color
.setBackColor(Color
.WHITE
);
330 color
.setBold(false);
331 colors
.put("tmenu.mnemonic", color
);
332 color
= new CellAttributes();
333 color
.setForeColor(Color
.RED
);
334 color
.setBackColor(Color
.GREEN
);
335 color
.setBold(false);
336 colors
.put("tmenu.mnemonic.highlighted", color
);
337 color
= new CellAttributes();
338 color
.setForeColor(Color
.BLACK
);
339 color
.setBackColor(Color
.WHITE
);
341 colors
.put("tmenu.disabled", color
);
344 color
= new CellAttributes();
345 color
.setForeColor(Color
.BLUE
);
346 color
.setBackColor(Color
.BLUE
);
348 colors
.put("tprogressbar.complete", color
);
349 color
= new CellAttributes();
350 color
.setForeColor(Color
.WHITE
);
351 color
.setBackColor(Color
.BLUE
);
352 color
.setBold(false);
353 colors
.put("tprogressbar.incomplete", color
);
355 // THScroller / TVScroller
356 color
= new CellAttributes();
357 color
.setForeColor(Color
.CYAN
);
358 color
.setBackColor(Color
.BLUE
);
359 color
.setBold(false);
360 colors
.put("tscroller.bar", color
);
361 color
= new CellAttributes();
362 color
.setForeColor(Color
.BLUE
);
363 color
.setBackColor(Color
.CYAN
);
364 color
.setBold(false);
365 colors
.put("tscroller.arrows", color
);
368 color
= new CellAttributes();
369 color
.setForeColor(Color
.WHITE
);
370 color
.setBackColor(Color
.BLUE
);
371 color
.setBold(false);
372 colors
.put("ttreeview", color
);
373 color
= new CellAttributes();
374 color
.setForeColor(Color
.GREEN
);
375 color
.setBackColor(Color
.BLUE
);
377 colors
.put("ttreeview.expandbutton", color
);
378 color
= new CellAttributes();
379 color
.setForeColor(Color
.BLACK
);
380 color
.setBackColor(Color
.CYAN
);
381 color
.setBold(false);
382 colors
.put("ttreeview.selected", color
);
383 color
= new CellAttributes();
384 color
.setForeColor(Color
.RED
);
385 color
.setBackColor(Color
.BLUE
);
386 color
.setBold(false);
387 colors
.put("ttreeview.unreadable", color
);
388 color
= new CellAttributes();
389 color
.setForeColor(Color
.BLACK
);
390 color
.setBackColor(Color
.BLUE
);
392 colors
.put("ttreeview.inactive", color
);
395 color
= new CellAttributes();
396 color
.setForeColor(Color
.WHITE
);
397 color
.setBackColor(Color
.BLUE
);
398 color
.setBold(false);
399 colors
.put("tdirectorylist", color
);
400 color
= new CellAttributes();
401 color
.setForeColor(Color
.BLACK
);
402 color
.setBackColor(Color
.CYAN
);
403 color
.setBold(false);
404 colors
.put("tdirectorylist.selected", color
);
405 color
= new CellAttributes();
406 color
.setForeColor(Color
.BLACK
);
407 color
.setBackColor(Color
.CYAN
);
408 color
.setBold(false);
409 colors
.put("tdirectorylist.unreadable", color
);
410 color
= new CellAttributes();
411 color
.setForeColor(Color
.BLACK
);
412 color
.setBackColor(Color
.BLUE
);
414 colors
.put("tdirectorylist.inactive", color
);
417 color
= new CellAttributes();
418 color
.setForeColor(Color
.WHITE
);
419 color
.setBackColor(Color
.BLACK
);
420 color
.setBold(false);
421 colors
.put("teditor", color
);