2 * Jexer - Java Text User Interface
6 * Author: Kevin Lamonte, <a href="mailto:kevin.lamonte@gmail.com">kevin.lamonte@gmail.com</a>
8 * License: LGPLv3 or later
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
15 * Copyright (C) 2015 Kevin Lamonte
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.
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.
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
35 import java
.util
.HashMap
;
40 * ColorTheme is a collection of colors keyed by string.
42 public class ColorTheme
{
45 * The current theme colors
47 private Map
<String
, CellAttributes
> colors
;
50 * Retrieve the CellAttributes by name.
52 * @param name hash key
53 * @return color associated with hash key
55 public CellAttributes
getColor(String name
) {
56 CellAttributes attr
= (CellAttributes
)colors
.get(name
);
61 * Save the colors to an ASCII file
63 * @param filename file to write to
65 public void save(String filename
) {
67 auto file = File(filename, "wt");
68 foreach (string key; colors.keys.sort) {
69 CellAttributes color = colors[key];
70 file.writefln("%s = %s", key, color);
76 * Read colors from an ASCII file
78 * @param filename file to read from
80 public void load(String filename
) {
82 string text = std.file.readText!(string)(filename);
83 foreach (line; std.string.splitLines!(string)(text)) {
89 auto tokenCount = formattedRead(line, "%s = %s %s %s %s",
90 &key, &bold, &foreColor, &on, &backColor);
91 if (tokenCount == 4) {
92 std.stdio.stderr.writefln("1 %s = %s %s %s %s",
93 key, bold, foreColor, on, backColor);
95 // "key = blah on blah"
99 } else if (tokenCount == 5) {
100 // "key = bold blah on blah"
101 std.stdio.stderr.writefln("2 %s = %s %s %s %s",
102 key, bold, foreColor, on, backColor);
104 // Unknown line, skip this one
107 CellAttributes color = new CellAttributes();
108 if (bold == "bold") {
111 color.foreColor = CellAttributes.colorFromString(foreColor);
112 color.backColor = CellAttributes.colorFromString(backColor);
118 /// Sets to defaults that resemble the Borland IDE colors.
119 public void setDefaultTheme() {
120 CellAttributes color
;
123 color
= new CellAttributes();
124 color
.foreColor
= Color
.WHITE
;
125 color
.backColor
= Color
.BLUE
;
127 colors
.put("twindow.border", color
);
129 // TWindow background
130 color
= new CellAttributes();
131 color
.foreColor
= Color
.YELLOW
;
132 color
.backColor
= Color
.BLUE
;
134 colors
.put("twindow.background", color
);
136 // TWindow border - inactive
137 color
= new CellAttributes();
138 color
.foreColor
= Color
.BLACK
;
139 color
.backColor
= Color
.BLUE
;
141 colors
.put("twindow.border.inactive", color
);
143 // TWindow background - inactive
144 color
= new CellAttributes();
145 color
.foreColor
= Color
.YELLOW
;
146 color
.backColor
= Color
.BLUE
;
148 colors
.put("twindow.background.inactive", color
);
150 // TWindow border - modal
151 color
= new CellAttributes();
152 color
.foreColor
= Color
.WHITE
;
153 color
.backColor
= Color
.WHITE
;
155 colors
.put("twindow.border.modal", color
);
157 // TWindow background - modal
158 color
= new CellAttributes();
159 color
.foreColor
= Color
.BLACK
;
160 color
.backColor
= Color
.WHITE
;
162 colors
.put("twindow.background.modal", color
);
164 // TWindow border - modal + inactive
165 color
= new CellAttributes();
166 color
.foreColor
= Color
.BLACK
;
167 color
.backColor
= Color
.WHITE
;
169 colors
.put("twindow.border.modal.inactive", color
);
171 // TWindow background - modal + inactive
172 color
= new CellAttributes();
173 color
.foreColor
= Color
.BLACK
;
174 color
.backColor
= Color
.WHITE
;
176 colors
.put("twindow.background.modal.inactive", color
);
178 // TWindow border - during window movement - modal
179 color
= new CellAttributes();
180 color
.foreColor
= Color
.GREEN
;
181 color
.backColor
= Color
.WHITE
;
183 colors
.put("twindow.border.modal.windowmove", color
);
185 // TWindow border - during window movement
186 color
= new CellAttributes();
187 color
.foreColor
= Color
.GREEN
;
188 color
.backColor
= Color
.BLUE
;
190 colors
.put("twindow.border.windowmove", color
);
192 // TWindow background - during window movement
193 color
= new CellAttributes();
194 color
.foreColor
= Color
.YELLOW
;
195 color
.backColor
= Color
.BLUE
;
197 colors
.put("twindow.background.windowmove", color
);
199 // TApplication background
200 color
= new CellAttributes();
201 color
.foreColor
= Color
.BLUE
;
202 color
.backColor
= Color
.WHITE
;
204 colors
.put("tapplication.background", color
);
207 color
= new CellAttributes();
208 color
.foreColor
= Color
.BLACK
;
209 color
.backColor
= Color
.GREEN
;
211 colors
.put("tbutton.inactive", color
);
212 color
= new CellAttributes();
213 color
.foreColor
= Color
.WHITE
;
214 color
.backColor
= Color
.GREEN
;
216 colors
.put("tbutton.active", color
);
217 color
= new CellAttributes();
218 color
.foreColor
= Color
.BLACK
;
219 color
.backColor
= Color
.WHITE
;
221 colors
.put("tbutton.disabled", color
);
222 color
= new CellAttributes();
223 color
.foreColor
= Color
.YELLOW
;
224 color
.backColor
= Color
.GREEN
;
226 colors
.put("tbutton.mnemonic", color
);
227 color
= new CellAttributes();
228 color
.foreColor
= Color
.YELLOW
;
229 color
.backColor
= Color
.GREEN
;
231 colors
.put("tbutton.mnemonic.highlighted", color
);
234 color
= new CellAttributes();
235 color
.foreColor
= Color
.WHITE
;
236 color
.backColor
= Color
.BLUE
;
238 colors
.put("tlabel", color
);
241 color
= new CellAttributes();
242 color
.foreColor
= Color
.WHITE
;
243 color
.backColor
= Color
.BLACK
;
245 colors
.put("ttext", color
);
248 color
= new CellAttributes();
249 color
.foreColor
= Color
.WHITE
;
250 color
.backColor
= Color
.BLUE
;
252 colors
.put("tfield.inactive", color
);
253 color
= new CellAttributes();
254 color
.foreColor
= Color
.YELLOW
;
255 color
.backColor
= Color
.BLACK
;
257 colors
.put("tfield.active", color
);
260 color
= new CellAttributes();
261 color
.foreColor
= Color
.WHITE
;
262 color
.backColor
= Color
.BLUE
;
264 colors
.put("tcheckbox.inactive", color
);
265 color
= new CellAttributes();
266 color
.foreColor
= Color
.YELLOW
;
267 color
.backColor
= Color
.BLACK
;
269 colors
.put("tcheckbox.active", color
);
273 color
= new CellAttributes();
274 color
.foreColor
= Color
.WHITE
;
275 color
.backColor
= Color
.BLUE
;
277 colors
.put("tradiobutton.inactive", color
);
278 color
= new CellAttributes();
279 color
.foreColor
= Color
.YELLOW
;
280 color
.backColor
= Color
.BLACK
;
282 colors
.put("tradiobutton.active", color
);
285 color
= new CellAttributes();
286 color
.foreColor
= Color
.WHITE
;
287 color
.backColor
= Color
.BLUE
;
289 colors
.put("tradiogroup.inactive", color
);
290 color
= new CellAttributes();
291 color
.foreColor
= Color
.YELLOW
;
292 color
.backColor
= Color
.BLUE
;
294 colors
.put("tradiogroup.active", color
);
297 color
= new CellAttributes();
298 color
.foreColor
= Color
.BLACK
;
299 color
.backColor
= Color
.WHITE
;
301 colors
.put("tmenu", color
);
302 color
= new CellAttributes();
303 color
.foreColor
= Color
.BLACK
;
304 color
.backColor
= Color
.GREEN
;
306 colors
.put("tmenu.highlighted", color
);
307 color
= new CellAttributes();
308 color
.foreColor
= Color
.RED
;
309 color
.backColor
= Color
.WHITE
;
311 colors
.put("tmenu.mnemonic", color
);
312 color
= new CellAttributes();
313 color
.foreColor
= Color
.RED
;
314 color
.backColor
= Color
.GREEN
;
316 colors
.put("tmenu.mnemonic.highlighted", color
);
317 color
= new CellAttributes();
318 color
.foreColor
= Color
.BLACK
;
319 color
.backColor
= Color
.WHITE
;
321 colors
.put("tmenu.disabled", color
);
324 color
= new CellAttributes();
325 color
.foreColor
= Color
.BLUE
;
326 color
.backColor
= Color
.BLUE
;
328 colors
.put("tprogressbar.complete", color
);
329 color
= new CellAttributes();
330 color
.foreColor
= Color
.WHITE
;
331 color
.backColor
= Color
.BLUE
;
333 colors
.put("tprogressbar.incomplete", color
);
335 // THScroller / TVScroller
336 color
= new CellAttributes();
337 color
.foreColor
= Color
.CYAN
;
338 color
.backColor
= Color
.BLUE
;
340 colors
.put("tscroller.bar", color
);
341 color
= new CellAttributes();
342 color
.foreColor
= Color
.BLUE
;
343 color
.backColor
= Color
.CYAN
;
345 colors
.put("tscroller.arrows", color
);
348 color
= new CellAttributes();
349 color
.foreColor
= Color
.WHITE
;
350 color
.backColor
= Color
.BLUE
;
352 colors
.put("ttreeview", color
);
353 color
= new CellAttributes();
354 color
.foreColor
= Color
.GREEN
;
355 color
.backColor
= Color
.BLUE
;
357 colors
.put("ttreeview.expandbutton", color
);
358 color
= new CellAttributes();
359 color
.foreColor
= Color
.BLACK
;
360 color
.backColor
= Color
.CYAN
;
362 colors
.put("ttreeview.selected", color
);
363 color
= new CellAttributes();
364 color
.foreColor
= Color
.RED
;
365 color
.backColor
= Color
.BLUE
;
367 colors
.put("ttreeview.unreadable", color
);
368 color
= new CellAttributes();
369 color
.foreColor
= Color
.BLACK
;
370 color
.backColor
= Color
.BLUE
;
372 colors
.put("ttreeview.inactive", color
);
375 color
= new CellAttributes();
376 color
.foreColor
= Color
.WHITE
;
377 color
.backColor
= Color
.BLUE
;
379 colors
.put("tdirectorylist", color
);
380 color
= new CellAttributes();
381 color
.foreColor
= Color
.BLACK
;
382 color
.backColor
= Color
.CYAN
;
384 colors
.put("tdirectorylist.selected", color
);
385 color
= new CellAttributes();
386 color
.foreColor
= Color
.BLACK
;
387 color
.backColor
= Color
.CYAN
;
389 colors
.put("tdirectorylist.unreadable", color
);
390 color
= new CellAttributes();
391 color
.foreColor
= Color
.BLACK
;
392 color
.backColor
= Color
.BLUE
;
394 colors
.put("tdirectorylist.inactive", color
);
397 color
= new CellAttributes();
398 color
.foreColor
= Color
.WHITE
;
399 color
.backColor
= Color
.BLACK
;
401 colors
.put("teditor", color
);
407 * Public constructor.
409 public ColorTheme() {