update roadmap
[fanfix.git] / src / jexer / bits / ColorTheme.java
CommitLineData
624ce48e
KL
1/**
2 * Jexer - Java Text User Interface
3 *
4 * Version: $Id$
5 *
6 * Author: Kevin Lamonte, <a href="mailto:kevin.lamonte@gmail.com">kevin.lamonte@gmail.com</a>
7 *
8 * License: LGPLv3 or later
9 *
10 * Copyright: This module is licensed under the GNU Lesser General
11 * Public License Version 3. Please see the file "COPYING" in this
12 * directory for more information about the GNU Lesser General Public
13 * License Version 3.
14 *
15 * Copyright (C) 2015 Kevin Lamonte
16 *
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public License
19 * as published by the Free Software Foundation; either version 3 of
20 * the License, or (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful, but
23 * WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 * General Public License for more details.
26 *
27 * You should have received a copy of the GNU Lesser General Public
28 * License along with this program; if not, see
29 * http://www.gnu.org/licenses/, or write to the Free Software
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
31 * 02110-1301 USA
32 */
33package jexer.bits;
34
2420f903
KL
35import java.io.BufferedReader;
36import java.io.FileReader;
37import java.io.FileWriter;
38import java.io.IOException;
39import java.util.SortedMap;
40import java.util.StringTokenizer;
41import java.util.TreeMap;
624ce48e
KL
42
43/**
44 * ColorTheme is a collection of colors keyed by string.
45 */
46public class ColorTheme {
47
48 /**
49 * The current theme colors
50 */
2420f903
KL
51 private SortedMap<String, CellAttributes> colors;
52
53 /**
54 * Public constructor.
55 */
56 public ColorTheme() {
57 colors = new TreeMap<String, CellAttributes>();
58 setDefaultTheme();
59 }
624ce48e
KL
60
61 /**
62 * Retrieve the CellAttributes by name.
63 *
64 * @param name hash key
65 * @return color associated with hash key
66 */
67 public CellAttributes getColor(String name) {
68 CellAttributes attr = (CellAttributes)colors.get(name);
69 return attr;
70 }
71
72 /**
73 * Save the colors to an ASCII file
74 *
75 * @param filename file to write to
76 */
2420f903
KL
77 public void save(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));
624ce48e 82 }
2420f903 83 file.close();
624ce48e
KL
84 }
85
86 /**
87 * Read colors from an ASCII file
88 *
89 * @param filename file to read from
90 */
2420f903
KL
91 public void load(String filename) throws IOException {
92 BufferedReader reader = new BufferedReader(new FileReader(filename));
93 String line = reader.readLine();
94 for (; line != null; line = reader.readLine()) {
95 String key;
96 String bold;
97 String foreColor;
98 String backColor;
99
100 // Look for lines that resemble:
101 // "key = blah on blah"
102 // "key = bold blah on blah"
103 StringTokenizer tokenizer = new StringTokenizer(line);
104 key = tokenizer.nextToken();
105 if (!tokenizer.nextToken().equals("=")) {
106 // Skip this line
107 continue;
108 }
109 bold = tokenizer.nextToken();
110 if (!bold.toLowerCase().equals("bold")) {
624ce48e
KL
111 // "key = blah on blah"
112 foreColor = bold;
624ce48e 113 } else {
2420f903
KL
114 // "key = bold blah on blah"
115 foreColor = tokenizer.nextToken().toLowerCase();
116 }
117 if (!tokenizer.nextToken().toLowerCase().equals("on")) {
118 // Skip this line
624ce48e
KL
119 continue;
120 }
2420f903
KL
121 backColor = tokenizer.nextToken().toLowerCase();
122
624ce48e 123 CellAttributes color = new CellAttributes();
2420f903 124 if (bold.equals("bold")) {
624ce48e
KL
125 color.bold = true;
126 }
127 color.foreColor = CellAttributes.colorFromString(foreColor);
128 color.backColor = CellAttributes.colorFromString(backColor);
2420f903 129 colors.put(key, color);
624ce48e 130 }
624ce48e
KL
131 }
132
2420f903
KL
133 /**
134 * Sets to defaults that resemble the Borland IDE colors.
135 */
624ce48e
KL
136 public void setDefaultTheme() {
137 CellAttributes color;
138
139 // TWindow border
140 color = new CellAttributes();
141 color.foreColor = Color.WHITE;
142 color.backColor = Color.BLUE;
143 color.bold = true;
144 colors.put("twindow.border", color);
145
146 // TWindow background
147 color = new CellAttributes();
148 color.foreColor = Color.YELLOW;
149 color.backColor = Color.BLUE;
150 color.bold = true;
151 colors.put("twindow.background", color);
152
153 // TWindow border - inactive
154 color = new CellAttributes();
155 color.foreColor = Color.BLACK;
156 color.backColor = Color.BLUE;
157 color.bold = true;
158 colors.put("twindow.border.inactive", color);
159
160 // TWindow background - inactive
161 color = new CellAttributes();
162 color.foreColor = Color.YELLOW;
163 color.backColor = Color.BLUE;
164 color.bold = true;
165 colors.put("twindow.background.inactive", color);
166
167 // TWindow border - modal
168 color = new CellAttributes();
169 color.foreColor = Color.WHITE;
170 color.backColor = Color.WHITE;
171 color.bold = true;
172 colors.put("twindow.border.modal", color);
173
174 // TWindow background - modal
175 color = new CellAttributes();
176 color.foreColor = Color.BLACK;
177 color.backColor = Color.WHITE;
178 color.bold = false;
179 colors.put("twindow.background.modal", color);
180
181 // TWindow border - modal + inactive
182 color = new CellAttributes();
183 color.foreColor = Color.BLACK;
184 color.backColor = Color.WHITE;
185 color.bold = true;
186 colors.put("twindow.border.modal.inactive", color);
187
188 // TWindow background - modal + inactive
189 color = new CellAttributes();
190 color.foreColor = Color.BLACK;
191 color.backColor = Color.WHITE;
192 color.bold = false;
193 colors.put("twindow.background.modal.inactive", color);
194
195 // TWindow border - during window movement - modal
196 color = new CellAttributes();
197 color.foreColor = Color.GREEN;
198 color.backColor = Color.WHITE;
199 color.bold = true;
200 colors.put("twindow.border.modal.windowmove", color);
201
202 // TWindow border - during window movement
203 color = new CellAttributes();
204 color.foreColor = Color.GREEN;
205 color.backColor = Color.BLUE;
206 color.bold = true;
207 colors.put("twindow.border.windowmove", color);
208
209 // TWindow background - during window movement
210 color = new CellAttributes();
211 color.foreColor = Color.YELLOW;
212 color.backColor = Color.BLUE;
213 color.bold = false;
214 colors.put("twindow.background.windowmove", color);
215
216 // TApplication background
217 color = new CellAttributes();
218 color.foreColor = Color.BLUE;
219 color.backColor = Color.WHITE;
220 color.bold = false;
221 colors.put("tapplication.background", color);
222
223 // TButton text
224 color = new CellAttributes();
225 color.foreColor = Color.BLACK;
226 color.backColor = Color.GREEN;
227 color.bold = false;
228 colors.put("tbutton.inactive", color);
229 color = new CellAttributes();
230 color.foreColor = Color.WHITE;
231 color.backColor = Color.GREEN;
232 color.bold = true;
233 colors.put("tbutton.active", color);
234 color = new CellAttributes();
235 color.foreColor = Color.BLACK;
236 color.backColor = Color.WHITE;
237 color.bold = true;
238 colors.put("tbutton.disabled", color);
239 color = new CellAttributes();
240 color.foreColor = Color.YELLOW;
241 color.backColor = Color.GREEN;
242 color.bold = true;
243 colors.put("tbutton.mnemonic", color);
244 color = new CellAttributes();
245 color.foreColor = Color.YELLOW;
246 color.backColor = Color.GREEN;
247 color.bold = true;
248 colors.put("tbutton.mnemonic.highlighted", color);
249
250 // TLabel text
251 color = new CellAttributes();
252 color.foreColor = Color.WHITE;
253 color.backColor = Color.BLUE;
254 color.bold = true;
255 colors.put("tlabel", color);
256
257 // TText text
258 color = new CellAttributes();
259 color.foreColor = Color.WHITE;
260 color.backColor = Color.BLACK;
261 color.bold = false;
262 colors.put("ttext", color);
263
264 // TField text
265 color = new CellAttributes();
266 color.foreColor = Color.WHITE;
267 color.backColor = Color.BLUE;
268 color.bold = false;
269 colors.put("tfield.inactive", color);
270 color = new CellAttributes();
271 color.foreColor = Color.YELLOW;
272 color.backColor = Color.BLACK;
273 color.bold = true;
274 colors.put("tfield.active", color);
275
276 // TCheckbox
277 color = new CellAttributes();
278 color.foreColor = Color.WHITE;
279 color.backColor = Color.BLUE;
280 color.bold = false;
281 colors.put("tcheckbox.inactive", color);
282 color = new CellAttributes();
283 color.foreColor = Color.YELLOW;
284 color.backColor = Color.BLACK;
285 color.bold = true;
286 colors.put("tcheckbox.active", color);
287
288
289 // TRadioButton
290 color = new CellAttributes();
291 color.foreColor = Color.WHITE;
292 color.backColor = Color.BLUE;
293 color.bold = false;
294 colors.put("tradiobutton.inactive", color);
295 color = new CellAttributes();
296 color.foreColor = Color.YELLOW;
297 color.backColor = Color.BLACK;
298 color.bold = true;
299 colors.put("tradiobutton.active", color);
300
301 // TRadioGroup
302 color = new CellAttributes();
303 color.foreColor = Color.WHITE;
304 color.backColor = Color.BLUE;
305 color.bold = false;
306 colors.put("tradiogroup.inactive", color);
307 color = new CellAttributes();
308 color.foreColor = Color.YELLOW;
309 color.backColor = Color.BLUE;
310 color.bold = true;
311 colors.put("tradiogroup.active", color);
312
313 // TMenu
314 color = new CellAttributes();
315 color.foreColor = Color.BLACK;
316 color.backColor = Color.WHITE;
317 color.bold = false;
318 colors.put("tmenu", color);
319 color = new CellAttributes();
320 color.foreColor = Color.BLACK;
321 color.backColor = Color.GREEN;
322 color.bold = false;
323 colors.put("tmenu.highlighted", color);
324 color = new CellAttributes();
325 color.foreColor = Color.RED;
326 color.backColor = Color.WHITE;
327 color.bold = false;
328 colors.put("tmenu.mnemonic", color);
329 color = new CellAttributes();
330 color.foreColor = Color.RED;
331 color.backColor = Color.GREEN;
332 color.bold = false;
333 colors.put("tmenu.mnemonic.highlighted", color);
334 color = new CellAttributes();
335 color.foreColor = Color.BLACK;
336 color.backColor = Color.WHITE;
337 color.bold = true;
338 colors.put("tmenu.disabled", color);
339
340 // TProgressBar
341 color = new CellAttributes();
342 color.foreColor = Color.BLUE;
343 color.backColor = Color.BLUE;
344 color.bold = true;
345 colors.put("tprogressbar.complete", color);
346 color = new CellAttributes();
347 color.foreColor = Color.WHITE;
348 color.backColor = Color.BLUE;
349 color.bold = false;
350 colors.put("tprogressbar.incomplete", color);
351
352 // THScroller / TVScroller
353 color = new CellAttributes();
354 color.foreColor = Color.CYAN;
355 color.backColor = Color.BLUE;
356 color.bold = false;
357 colors.put("tscroller.bar", color);
358 color = new CellAttributes();
359 color.foreColor = Color.BLUE;
360 color.backColor = Color.CYAN;
361 color.bold = false;
362 colors.put("tscroller.arrows", color);
363
364 // TTreeView
365 color = new CellAttributes();
366 color.foreColor = Color.WHITE;
367 color.backColor = Color.BLUE;
368 color.bold = false;
369 colors.put("ttreeview", color);
370 color = new CellAttributes();
371 color.foreColor = Color.GREEN;
372 color.backColor = Color.BLUE;
373 color.bold = true;
374 colors.put("ttreeview.expandbutton", color);
375 color = new CellAttributes();
376 color.foreColor = Color.BLACK;
377 color.backColor = Color.CYAN;
378 color.bold = false;
379 colors.put("ttreeview.selected", color);
380 color = new CellAttributes();
381 color.foreColor = Color.RED;
382 color.backColor = Color.BLUE;
383 color.bold = false;
384 colors.put("ttreeview.unreadable", color);
385 color = new CellAttributes();
386 color.foreColor = Color.BLACK;
387 color.backColor = Color.BLUE;
388 color.bold = true;
389 colors.put("ttreeview.inactive", color);
390
391 // TText text
392 color = new CellAttributes();
393 color.foreColor = Color.WHITE;
394 color.backColor = Color.BLUE;
395 color.bold = false;
396 colors.put("tdirectorylist", color);
397 color = new CellAttributes();
398 color.foreColor = Color.BLACK;
399 color.backColor = Color.CYAN;
400 color.bold = false;
401 colors.put("tdirectorylist.selected", color);
402 color = new CellAttributes();
403 color.foreColor = Color.BLACK;
404 color.backColor = Color.CYAN;
405 color.bold = false;
406 colors.put("tdirectorylist.unreadable", color);
407 color = new CellAttributes();
408 color.foreColor = Color.BLACK;
409 color.backColor = Color.BLUE;
410 color.bold = true;
411 colors.put("tdirectorylist.inactive", color);
412
413 // TEditor
414 color = new CellAttributes();
415 color.foreColor = Color.WHITE;
416 color.backColor = Color.BLACK;
417 color.bold = false;
418 colors.put("teditor", color);
419
624ce48e
KL
420 }
421
624ce48e 422}