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
);
135 * Sets to defaults that resemble the Borland IDE colors.
137 public void setDefaultTheme() {
138 CellAttributes color
;
141 color
= new CellAttributes();
142 color
.setForeColor(Color
.WHITE
);
143 color
.setBackColor(Color
.BLUE
);
145 colors
.put("twindow.border", color
);
147 // TWindow background
148 color
= new CellAttributes();
149 color
.setForeColor(Color
.YELLOW
);
150 color
.setBackColor(Color
.BLUE
);
152 colors
.put("twindow.background", color
);
154 // TWindow border - inactive
155 color
= new CellAttributes();
156 color
.setForeColor(Color
.BLACK
);
157 color
.setBackColor(Color
.BLUE
);
159 colors
.put("twindow.border.inactive", color
);
161 // TWindow background - inactive
162 color
= new CellAttributes();
163 color
.setForeColor(Color
.YELLOW
);
164 color
.setBackColor(Color
.BLUE
);
166 colors
.put("twindow.background.inactive", color
);
168 // TWindow border - modal
169 color
= new CellAttributes();
170 color
.setForeColor(Color
.WHITE
);
171 color
.setBackColor(Color
.WHITE
);
173 colors
.put("twindow.border.modal", color
);
175 // TWindow background - modal
176 color
= new CellAttributes();
177 color
.setForeColor(Color
.BLACK
);
178 color
.setBackColor(Color
.WHITE
);
179 color
.setBold(false);
180 colors
.put("twindow.background.modal", color
);
182 // TWindow border - modal + inactive
183 color
= new CellAttributes();
184 color
.setForeColor(Color
.BLACK
);
185 color
.setBackColor(Color
.WHITE
);
187 colors
.put("twindow.border.modal.inactive", color
);
189 // TWindow background - modal + inactive
190 color
= new CellAttributes();
191 color
.setForeColor(Color
.BLACK
);
192 color
.setBackColor(Color
.WHITE
);
193 color
.setBold(false);
194 colors
.put("twindow.background.modal.inactive", color
);
196 // TWindow border - during window movement - modal
197 color
= new CellAttributes();
198 color
.setForeColor(Color
.GREEN
);
199 color
.setBackColor(Color
.WHITE
);
201 colors
.put("twindow.border.modal.windowmove", color
);
203 // TWindow border - during window movement
204 color
= new CellAttributes();
205 color
.setForeColor(Color
.GREEN
);
206 color
.setBackColor(Color
.BLUE
);
208 colors
.put("twindow.border.windowmove", color
);
210 // TWindow background - during window movement
211 color
= new CellAttributes();
212 color
.setForeColor(Color
.YELLOW
);
213 color
.setBackColor(Color
.BLUE
);
214 color
.setBold(false);
215 colors
.put("twindow.background.windowmove", color
);
217 // TApplication background
218 color
= new CellAttributes();
219 color
.setForeColor(Color
.BLUE
);
220 color
.setBackColor(Color
.WHITE
);
221 color
.setBold(false);
222 colors
.put("tapplication.background", color
);
225 color
= new CellAttributes();
226 color
.setForeColor(Color
.BLACK
);
227 color
.setBackColor(Color
.GREEN
);
228 color
.setBold(false);
229 colors
.put("tbutton.inactive", color
);
230 color
= new CellAttributes();
231 color
.setForeColor(Color
.WHITE
);
232 color
.setBackColor(Color
.GREEN
);
234 colors
.put("tbutton.active", color
);
235 color
= new CellAttributes();
236 color
.setForeColor(Color
.BLACK
);
237 color
.setBackColor(Color
.WHITE
);
239 colors
.put("tbutton.disabled", color
);
240 color
= new CellAttributes();
241 color
.setForeColor(Color
.YELLOW
);
242 color
.setBackColor(Color
.GREEN
);
244 colors
.put("tbutton.mnemonic", color
);
245 color
= new CellAttributes();
246 color
.setForeColor(Color
.YELLOW
);
247 color
.setBackColor(Color
.GREEN
);
249 colors
.put("tbutton.mnemonic.highlighted", color
);
252 color
= new CellAttributes();
253 color
.setForeColor(Color
.WHITE
);
254 color
.setBackColor(Color
.BLUE
);
256 colors
.put("tlabel", color
);
259 color
= new CellAttributes();
260 color
.setForeColor(Color
.WHITE
);
261 color
.setBackColor(Color
.BLACK
);
262 color
.setBold(false);
263 colors
.put("ttext", color
);
266 color
= new CellAttributes();
267 color
.setForeColor(Color
.WHITE
);
268 color
.setBackColor(Color
.BLUE
);
269 color
.setBold(false);
270 colors
.put("tfield.inactive", color
);
271 color
= new CellAttributes();
272 color
.setForeColor(Color
.YELLOW
);
273 color
.setBackColor(Color
.BLACK
);
275 colors
.put("tfield.active", color
);
278 color
= new CellAttributes();
279 color
.setForeColor(Color
.WHITE
);
280 color
.setBackColor(Color
.BLUE
);
281 color
.setBold(false);
282 colors
.put("tcheckbox.inactive", color
);
283 color
= new CellAttributes();
284 color
.setForeColor(Color
.YELLOW
);
285 color
.setBackColor(Color
.BLACK
);
287 colors
.put("tcheckbox.active", color
);
291 color
= new CellAttributes();
292 color
.setForeColor(Color
.WHITE
);
293 color
.setBackColor(Color
.BLUE
);
294 color
.setBold(false);
295 colors
.put("tradiobutton.inactive", color
);
296 color
= new CellAttributes();
297 color
.setForeColor(Color
.YELLOW
);
298 color
.setBackColor(Color
.BLACK
);
300 colors
.put("tradiobutton.active", color
);
303 color
= new CellAttributes();
304 color
.setForeColor(Color
.WHITE
);
305 color
.setBackColor(Color
.BLUE
);
306 color
.setBold(false);
307 colors
.put("tradiogroup.inactive", color
);
308 color
= new CellAttributes();
309 color
.setForeColor(Color
.YELLOW
);
310 color
.setBackColor(Color
.BLUE
);
312 colors
.put("tradiogroup.active", color
);
315 color
= new CellAttributes();
316 color
.setForeColor(Color
.BLACK
);
317 color
.setBackColor(Color
.WHITE
);
318 color
.setBold(false);
319 colors
.put("tmenu", color
);
320 color
= new CellAttributes();
321 color
.setForeColor(Color
.BLACK
);
322 color
.setBackColor(Color
.GREEN
);
323 color
.setBold(false);
324 colors
.put("tmenu.highlighted", color
);
325 color
= new CellAttributes();
326 color
.setForeColor(Color
.RED
);
327 color
.setBackColor(Color
.WHITE
);
328 color
.setBold(false);
329 colors
.put("tmenu.mnemonic", color
);
330 color
= new CellAttributes();
331 color
.setForeColor(Color
.RED
);
332 color
.setBackColor(Color
.GREEN
);
333 color
.setBold(false);
334 colors
.put("tmenu.mnemonic.highlighted", color
);
335 color
= new CellAttributes();
336 color
.setForeColor(Color
.BLACK
);
337 color
.setBackColor(Color
.WHITE
);
339 colors
.put("tmenu.disabled", color
);
342 color
= new CellAttributes();
343 color
.setForeColor(Color
.BLUE
);
344 color
.setBackColor(Color
.BLUE
);
346 colors
.put("tprogressbar.complete", color
);
347 color
= new CellAttributes();
348 color
.setForeColor(Color
.WHITE
);
349 color
.setBackColor(Color
.BLUE
);
350 color
.setBold(false);
351 colors
.put("tprogressbar.incomplete", color
);
353 // THScroller / TVScroller
354 color
= new CellAttributes();
355 color
.setForeColor(Color
.CYAN
);
356 color
.setBackColor(Color
.BLUE
);
357 color
.setBold(false);
358 colors
.put("tscroller.bar", color
);
359 color
= new CellAttributes();
360 color
.setForeColor(Color
.BLUE
);
361 color
.setBackColor(Color
.CYAN
);
362 color
.setBold(false);
363 colors
.put("tscroller.arrows", color
);
366 color
= new CellAttributes();
367 color
.setForeColor(Color
.WHITE
);
368 color
.setBackColor(Color
.BLUE
);
369 color
.setBold(false);
370 colors
.put("ttreeview", color
);
371 color
= new CellAttributes();
372 color
.setForeColor(Color
.GREEN
);
373 color
.setBackColor(Color
.BLUE
);
375 colors
.put("ttreeview.expandbutton", color
);
376 color
= new CellAttributes();
377 color
.setForeColor(Color
.BLACK
);
378 color
.setBackColor(Color
.CYAN
);
379 color
.setBold(false);
380 colors
.put("ttreeview.selected", color
);
381 color
= new CellAttributes();
382 color
.setForeColor(Color
.RED
);
383 color
.setBackColor(Color
.BLUE
);
384 color
.setBold(false);
385 colors
.put("ttreeview.unreadable", color
);
386 color
= new CellAttributes();
387 color
.setForeColor(Color
.BLACK
);
388 color
.setBackColor(Color
.BLUE
);
390 colors
.put("ttreeview.inactive", color
);
393 color
= new CellAttributes();
394 color
.setForeColor(Color
.WHITE
);
395 color
.setBackColor(Color
.BLUE
);
396 color
.setBold(false);
397 colors
.put("tdirectorylist", color
);
398 color
= new CellAttributes();
399 color
.setForeColor(Color
.BLACK
);
400 color
.setBackColor(Color
.CYAN
);
401 color
.setBold(false);
402 colors
.put("tdirectorylist.selected", color
);
403 color
= new CellAttributes();
404 color
.setForeColor(Color
.BLACK
);
405 color
.setBackColor(Color
.CYAN
);
406 color
.setBold(false);
407 colors
.put("tdirectorylist.unreadable", color
);
408 color
= new CellAttributes();
409 color
.setForeColor(Color
.BLACK
);
410 color
.setBackColor(Color
.BLUE
);
412 colors
.put("tdirectorylist.inactive", color
);
415 color
= new CellAttributes();
416 color
.setForeColor(Color
.WHITE
);
417 color
.setBackColor(Color
.BLACK
);
418 color
.setBold(false);
419 colors
.put("teditor", color
);