Merge branch 'master' of https://github.com/klamonte/jexer
[fanfix.git] / src / jexer / TEditColorThemeWindow.java
1 /*
2 * Jexer - Java Text User Interface
3 *
4 * The MIT License (MIT)
5 *
6 * Copyright (C) 2017 Kevin Lamonte
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
25 *
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
27 * @version 1
28 */
29 package jexer;
30
31 import java.util.List;
32 import java.util.ResourceBundle;
33
34 import jexer.bits.Color;
35 import jexer.bits.ColorTheme;
36 import jexer.bits.CellAttributes;
37 import jexer.bits.GraphicsChars;
38 import jexer.event.TKeypressEvent;
39 import jexer.event.TMouseEvent;
40 import static jexer.TKeypress.*;
41
42 /**
43 * TEditColorThemeWindow provides an easy UI for users to alter the running
44 * color theme.
45 *
46 */
47 public class TEditColorThemeWindow extends TWindow {
48
49 /**
50 * Translated strings.
51 */
52 private static final ResourceBundle i18n = ResourceBundle.getBundle(TEditColorThemeWindow.class.getName());
53
54 // ------------------------------------------------------------------------
55 // Variables --------------------------------------------------------------
56 // ------------------------------------------------------------------------
57
58 /**
59 * The current editing theme.
60 */
61 private ColorTheme editTheme;
62
63 /**
64 * The left-side list of colors pane.
65 */
66 private TList colorNames;
67
68 /**
69 * The foreground color.
70 */
71 private ForegroundPicker foreground;
72
73 /**
74 * The background color.
75 */
76 private BackgroundPicker background;
77
78 /**
79 * The foreground color picker.
80 */
81 class ForegroundPicker extends TWidget {
82
83 /**
84 * The selected color.
85 */
86 Color color;
87
88 /**
89 * The bold flag.
90 */
91 boolean bold;
92
93 /**
94 * Public constructor.
95 *
96 * @param parent parent widget
97 * @param x column relative to parent
98 * @param y row relative to parent
99 * @param width width of text area
100 * @param height height of text area
101 */
102 public ForegroundPicker(final TWidget parent, final int x,
103 final int y, final int width, final int height) {
104
105 super(parent, x, y, width, height);
106 }
107
108 /**
109 * Get the X grid coordinate for this color.
110 *
111 * @param color the Color value
112 * @return the X coordinate
113 */
114 private int getXColorPosition(final Color color) {
115 if (color.equals(Color.BLACK)) {
116 return 2;
117 } else if (color.equals(Color.BLUE)) {
118 return 5;
119 } else if (color.equals(Color.GREEN)) {
120 return 8;
121 } else if (color.equals(Color.CYAN)) {
122 return 11;
123 } else if (color.equals(Color.RED)) {
124 return 2;
125 } else if (color.equals(Color.MAGENTA)) {
126 return 5;
127 } else if (color.equals(Color.YELLOW)) {
128 return 8;
129 } else if (color.equals(Color.WHITE)) {
130 return 11;
131 }
132 throw new IllegalArgumentException("Invalid color: " + color);
133 }
134
135 /**
136 * Get the Y grid coordinate for this color.
137 *
138 * @param color the Color value
139 * @param bold if true use bold color
140 * @return the Y coordinate
141 */
142 private int getYColorPosition(final Color color, final boolean bold) {
143 int dotY = 1;
144 if (color.equals(Color.RED)) {
145 dotY = 2;
146 } else if (color.equals(Color.MAGENTA)) {
147 dotY = 2;
148 } else if (color.equals(Color.YELLOW)) {
149 dotY = 2;
150 } else if (color.equals(Color.WHITE)) {
151 dotY = 2;
152 }
153 if (bold) {
154 dotY += 2;
155 }
156 return dotY;
157 }
158
159 /**
160 * Get the bold value based on Y grid coordinate.
161 *
162 * @param dotY the Y coordinate
163 * @return the bold value
164 */
165 private boolean getBoldFromPosition(final int dotY) {
166 if (dotY > 2) {
167 return true;
168 }
169 return false;
170 }
171
172 /**
173 * Get the color based on (X, Y) grid coordinate.
174 *
175 * @param dotX the X coordinate
176 * @param dotY the Y coordinate
177 * @return the Color value
178 */
179 private Color getColorFromPosition(final int dotX, final int dotY) {
180 int y = dotY;
181 if (y > 2) {
182 y -= 2;
183 }
184 if ((1 <= dotX) && (dotX <= 3) && (y == 1)) {
185 return Color.BLACK;
186 }
187 if ((4 <= dotX) && (dotX <= 6) && (y == 1)) {
188 return Color.BLUE;
189 }
190 if ((7 <= dotX) && (dotX <= 9) && (y == 1)) {
191 return Color.GREEN;
192 }
193 if ((10 <= dotX) && (dotX <= 12) && (y == 1)) {
194 return Color.CYAN;
195 }
196 if ((1 <= dotX) && (dotX <= 3) && (y == 2)) {
197 return Color.RED;
198 }
199 if ((4 <= dotX) && (dotX <= 6) && (y == 2)) {
200 return Color.MAGENTA;
201 }
202 if ((7 <= dotX) && (dotX <= 9) && (y == 2)) {
203 return Color.YELLOW;
204 }
205 if ((10 <= dotX) && (dotX <= 12) && (y == 2)) {
206 return Color.WHITE;
207 }
208
209 throw new IllegalArgumentException("Invalid coordinates: "
210 + dotX + ", " + dotY);
211 }
212
213 /**
214 * Draw the foreground colors grid.
215 */
216 @Override
217 public void draw() {
218 CellAttributes border = getWindow().getBorder();
219 CellAttributes background = getWindow().getBackground();
220 CellAttributes attr = new CellAttributes();
221
222 getScreen().drawBox(0, 0, getWidth(), getHeight(), border,
223 background, 1, false);
224
225 attr.setTo(getTheme().getColor("twindow.background.modal"));
226 if (isActive()) {
227 attr.setForeColor(getTheme().getColor("tlabel").getForeColor());
228 attr.setBold(getTheme().getColor("tlabel").isBold());
229 }
230 getScreen().putStringXY(1, 0, i18n.getString("foregroundLabel"),
231 attr);
232
233 // Have to draw the colors manually because the int value matches
234 // SGR, not CGA.
235 attr.reset();
236 attr.setForeColor(Color.BLACK);
237 putStringXY(1, 1, "\u2588\u2588\u2588", attr);
238 attr.setForeColor(Color.BLUE);
239 putStringXY(4, 1, "\u2588\u2588\u2588", attr);
240 attr.setForeColor(Color.GREEN);
241 putStringXY(7, 1, "\u2588\u2588\u2588", attr);
242 attr.setForeColor(Color.CYAN);
243 putStringXY(10, 1, "\u2588\u2588\u2588", attr);
244 attr.setForeColor(Color.RED);
245 putStringXY(1, 2, "\u2588\u2588\u2588", attr);
246 attr.setForeColor(Color.MAGENTA);
247 putStringXY(4, 2, "\u2588\u2588\u2588", attr);
248 attr.setForeColor(Color.YELLOW);
249 putStringXY(7, 2, "\u2588\u2588\u2588", attr);
250 attr.setForeColor(Color.WHITE);
251 putStringXY(10, 2, "\u2588\u2588\u2588", attr);
252
253 attr.setBold(true);
254 attr.setForeColor(Color.BLACK);
255 putStringXY(1, 3, "\u2588\u2588\u2588", attr);
256 attr.setForeColor(Color.BLUE);
257 putStringXY(4, 3, "\u2588\u2588\u2588", attr);
258 attr.setForeColor(Color.GREEN);
259 putStringXY(7, 3, "\u2588\u2588\u2588", attr);
260 attr.setForeColor(Color.CYAN);
261 putStringXY(10, 3, "\u2588\u2588\u2588", attr);
262 attr.setForeColor(Color.RED);
263 putStringXY(1, 4, "\u2588\u2588\u2588", attr);
264 attr.setForeColor(Color.MAGENTA);
265 putStringXY(4, 4, "\u2588\u2588\u2588", attr);
266 attr.setForeColor(Color.YELLOW);
267 putStringXY(7, 4, "\u2588\u2588\u2588", attr);
268 attr.setForeColor(Color.WHITE);
269 putStringXY(10, 4, "\u2588\u2588\u2588", attr);
270
271 // Draw the dot
272 int dotX = getXColorPosition(color);
273 int dotY = getYColorPosition(color, bold);
274 if (color.equals(Color.BLACK) && !bold) {
275 // Use white-on-black for black. All other colors use
276 // black-on-whatever.
277 attr.reset();
278 getScreen().putCharXY(dotX, dotY, GraphicsChars.CP437[0x07],
279 attr);
280 } else {
281 attr.setForeColor(color);
282 attr.setBold(bold);
283 getScreen().putCharXY(dotX, dotY, '\u25D8', attr);
284 }
285 }
286
287 /**
288 * Handle keystrokes.
289 *
290 * @param keypress keystroke event
291 */
292 @Override
293 public void onKeypress(final TKeypressEvent keypress) {
294 if (keypress.equals(kbRight)) {
295 int dotX = getXColorPosition(color);
296 int dotY = getYColorPosition(color, bold);
297 if (dotX < 10) {
298 dotX += 3;
299 }
300 color = getColorFromPosition(dotX, dotY);
301 } else if (keypress.equals(kbLeft)) {
302 int dotX = getXColorPosition(color);
303 int dotY = getYColorPosition(color, bold);
304 if (dotX > 3) {
305 dotX -= 3;
306 }
307 color = getColorFromPosition(dotX, dotY);
308 } else if (keypress.equals(kbUp)) {
309 int dotX = getXColorPosition(color);
310 int dotY = getYColorPosition(color, bold);
311 if (dotY > 1) {
312 dotY--;
313 }
314 color = getColorFromPosition(dotX, dotY);
315 bold = getBoldFromPosition(dotY);
316 } else if (keypress.equals(kbDown)) {
317 int dotX = getXColorPosition(color);
318 int dotY = getYColorPosition(color, bold);
319 if (dotY < 4) {
320 dotY++;
321 }
322 color = getColorFromPosition(dotX, dotY);
323 bold = getBoldFromPosition(dotY);
324 } else {
325 // Pass to my parent
326 super.onKeypress(keypress);
327 return;
328 }
329
330 // Save this update to the local theme.
331 ((TEditColorThemeWindow) getWindow()).saveToEditTheme();
332 }
333
334 /**
335 * Handle mouse press events.
336 *
337 * @param mouse mouse button press event
338 */
339 @Override
340 public void onMouseDown(final TMouseEvent mouse) {
341 if (mouse.isMouseWheelUp()) {
342 // Do this like kbUp
343 int dotX = getXColorPosition(color);
344 int dotY = getYColorPosition(color, bold);
345 if (dotY > 1) {
346 dotY--;
347 }
348 color = getColorFromPosition(dotX, dotY);
349 bold = getBoldFromPosition(dotY);
350 } else if (mouse.isMouseWheelDown()) {
351 // Do this like kbDown
352 int dotX = getXColorPosition(color);
353 int dotY = getYColorPosition(color, bold);
354 if (dotY < 4) {
355 dotY++;
356 }
357 color = getColorFromPosition(dotX, dotY);
358 bold = getBoldFromPosition(dotY);
359 } else if ((mouse.getX() > 0)
360 && (mouse.getX() < getWidth() - 1)
361 && (mouse.getY() > 0)
362 && (mouse.getY() < getHeight() - 1)
363 ) {
364 color = getColorFromPosition(mouse.getX(), mouse.getY());
365 bold = getBoldFromPosition(mouse.getY());
366 } else {
367 // Let parent class handle it.
368 super.onMouseDown(mouse);
369 return;
370 }
371
372 // Save this update to the local theme.
373 ((TEditColorThemeWindow) getWindow()).saveToEditTheme();
374 }
375
376 }
377
378 /**
379 * The background color picker.
380 */
381 class BackgroundPicker extends TWidget {
382
383 /**
384 * The selected color.
385 */
386 Color color;
387
388 /**
389 * Public constructor.
390 *
391 * @param parent parent widget
392 * @param x column relative to parent
393 * @param y row relative to parent
394 * @param width width of text area
395 * @param height height of text area
396 */
397 public BackgroundPicker(final TWidget parent, final int x,
398 final int y, final int width, final int height) {
399
400 super(parent, x, y, width, height);
401 }
402
403 /**
404 * Get the X grid coordinate for this color.
405 *
406 * @param color the Color value
407 * @return the X coordinate
408 */
409 private int getXColorPosition(final Color color) {
410 if (color.equals(Color.BLACK)) {
411 return 2;
412 } else if (color.equals(Color.BLUE)) {
413 return 5;
414 } else if (color.equals(Color.GREEN)) {
415 return 8;
416 } else if (color.equals(Color.CYAN)) {
417 return 11;
418 } else if (color.equals(Color.RED)) {
419 return 2;
420 } else if (color.equals(Color.MAGENTA)) {
421 return 5;
422 } else if (color.equals(Color.YELLOW)) {
423 return 8;
424 } else if (color.equals(Color.WHITE)) {
425 return 11;
426 }
427 throw new IllegalArgumentException("Invalid color: " + color);
428 }
429
430 /**
431 * Get the Y grid coordinate for this color.
432 *
433 * @param color the Color value
434 * @return the Y coordinate
435 */
436 private int getYColorPosition(final Color color) {
437 int dotY = 1;
438 if (color.equals(Color.RED)) {
439 dotY = 2;
440 } else if (color.equals(Color.MAGENTA)) {
441 dotY = 2;
442 } else if (color.equals(Color.YELLOW)) {
443 dotY = 2;
444 } else if (color.equals(Color.WHITE)) {
445 dotY = 2;
446 }
447 return dotY;
448 }
449
450 /**
451 * Get the color based on (X, Y) grid coordinate.
452 *
453 * @param dotX the X coordinate
454 * @param dotY the Y coordinate
455 * @return the Color value
456 */
457 private Color getColorFromPosition(final int dotX, final int dotY) {
458 if ((1 <= dotX) && (dotX <= 3) && (dotY == 1)) {
459 return Color.BLACK;
460 }
461 if ((4 <= dotX) && (dotX <= 6) && (dotY == 1)) {
462 return Color.BLUE;
463 }
464 if ((7 <= dotX) && (dotX <= 9) && (dotY == 1)) {
465 return Color.GREEN;
466 }
467 if ((10 <= dotX) && (dotX <= 12) && (dotY == 1)) {
468 return Color.CYAN;
469 }
470 if ((1 <= dotX) && (dotX <= 3) && (dotY == 2)) {
471 return Color.RED;
472 }
473 if ((4 <= dotX) && (dotX <= 6) && (dotY == 2)) {
474 return Color.MAGENTA;
475 }
476 if ((7 <= dotX) && (dotX <= 9) && (dotY == 2)) {
477 return Color.YELLOW;
478 }
479 if ((10 <= dotX) && (dotX <= 12) && (dotY == 2)) {
480 return Color.WHITE;
481 }
482
483 throw new IllegalArgumentException("Invalid coordinates: "
484 + dotX + ", " + dotY);
485 }
486
487 /**
488 * Draw the background colors grid.
489 */
490 @Override
491 public void draw() {
492 CellAttributes border = getWindow().getBorder();
493 CellAttributes background = getWindow().getBackground();
494 CellAttributes attr = new CellAttributes();
495
496 getScreen().drawBox(0, 0, getWidth(), getHeight(), border,
497 background, 1, false);
498
499 attr.setTo(getTheme().getColor("twindow.background.modal"));
500 if (isActive()) {
501 attr.setForeColor(getTheme().getColor("tlabel").getForeColor());
502 attr.setBold(getTheme().getColor("tlabel").isBold());
503 }
504 getScreen().putStringXY(1, 0, i18n.getString("backgroundLabel"),
505 attr);
506
507 // Have to draw the colors manually because the int value matches
508 // SGR, not CGA.
509 attr.reset();
510 attr.setForeColor(Color.BLACK);
511 putStringXY(1, 1, "\u2588\u2588\u2588", attr);
512 attr.setForeColor(Color.BLUE);
513 putStringXY(4, 1, "\u2588\u2588\u2588", attr);
514 attr.setForeColor(Color.GREEN);
515 putStringXY(7, 1, "\u2588\u2588\u2588", attr);
516 attr.setForeColor(Color.CYAN);
517 putStringXY(10, 1, "\u2588\u2588\u2588", attr);
518 attr.setForeColor(Color.RED);
519 putStringXY(1, 2, "\u2588\u2588\u2588", attr);
520 attr.setForeColor(Color.MAGENTA);
521 putStringXY(4, 2, "\u2588\u2588\u2588", attr);
522 attr.setForeColor(Color.YELLOW);
523 putStringXY(7, 2, "\u2588\u2588\u2588", attr);
524 attr.setForeColor(Color.WHITE);
525 putStringXY(10, 2, "\u2588\u2588\u2588", attr);
526
527 // Draw the dot
528 int dotX = getXColorPosition(color);
529 int dotY = getYColorPosition(color);
530 if (color.equals(Color.BLACK)) {
531 // Use white-on-black for black. All other colors use
532 // black-on-whatever.
533 attr.reset();
534 getScreen().putCharXY(dotX, dotY, GraphicsChars.CP437[0x07],
535 attr);
536 } else {
537 attr.setForeColor(color);
538 getScreen().putCharXY(dotX, dotY, '\u25D8', attr);
539 }
540
541 }
542
543 /**
544 * Handle keystrokes.
545 *
546 * @param keypress keystroke event
547 */
548 @Override
549 public void onKeypress(final TKeypressEvent keypress) {
550 if (keypress.equals(kbRight)) {
551 int dotX = getXColorPosition(color);
552 int dotY = getYColorPosition(color);
553 if (dotX < 10) {
554 dotX += 3;
555 }
556 color = getColorFromPosition(dotX, dotY);
557 } else if (keypress.equals(kbLeft)) {
558 int dotX = getXColorPosition(color);
559 int dotY = getYColorPosition(color);
560 if (dotX > 3) {
561 dotX -= 3;
562 }
563 color = getColorFromPosition(dotX, dotY);
564 } else if (keypress.equals(kbUp)) {
565 int dotX = getXColorPosition(color);
566 int dotY = getYColorPosition(color);
567 if (dotY == 2) {
568 dotY--;
569 }
570 color = getColorFromPosition(dotX, dotY);
571 } else if (keypress.equals(kbDown)) {
572 int dotX = getXColorPosition(color);
573 int dotY = getYColorPosition(color);
574 if (dotY == 1) {
575 dotY++;
576 }
577 color = getColorFromPosition(dotX, dotY);
578 } else {
579 // Pass to my parent
580 super.onKeypress(keypress);
581 }
582
583 // Save this update to the local theme.
584 ((TEditColorThemeWindow) getWindow()).saveToEditTheme();
585 }
586
587 /**
588 * Handle mouse press events.
589 *
590 * @param mouse mouse button press event
591 */
592 @Override
593 public void onMouseDown(final TMouseEvent mouse) {
594 if (mouse.isMouseWheelUp()) {
595 // Do this like kbUp
596 int dotX = getXColorPosition(color);
597 int dotY = getYColorPosition(color);
598 if (dotY == 2) {
599 dotY--;
600 }
601 color = getColorFromPosition(dotX, dotY);
602 } else if (mouse.isMouseWheelDown()) {
603 // Do this like kbDown
604 int dotX = getXColorPosition(color);
605 int dotY = getYColorPosition(color);
606 if (dotY == 1) {
607 dotY++;
608 }
609 color = getColorFromPosition(dotX, dotY);
610 return;
611 } else if ((mouse.getX() > 0)
612 && (mouse.getX() < getWidth() - 1)
613 && (mouse.getY() > 0)
614 && (mouse.getY() < getHeight() - 1)
615 ) {
616 color = getColorFromPosition(mouse.getX(), mouse.getY());
617 } else {
618 // Let parent class handle it.
619 super.onMouseDown(mouse);
620 return;
621 }
622
623 // Save this update to the local theme.
624 ((TEditColorThemeWindow) getWindow()).saveToEditTheme();
625 }
626
627 }
628
629 // ------------------------------------------------------------------------
630 // Constructors -----------------------------------------------------------
631 // ------------------------------------------------------------------------
632
633 /**
634 * Public constructor. The file open box will be centered on screen.
635 *
636 * @param application the TApplication that manages this window
637 */
638 public TEditColorThemeWindow(final TApplication application) {
639
640 // Register with the TApplication
641 super(application, i18n.getString("windowTitle"), 0, 0, 60, 18, MODAL);
642
643 // Initialize with the first color
644 List<String> colors = getTheme().getColorNames();
645 assert (colors.size() > 0);
646 editTheme = new ColorTheme();
647 for (String key: colors) {
648 CellAttributes attr = new CellAttributes();
649 attr.setTo(getTheme().getColor(key));
650 editTheme.setColor(key, attr);
651 }
652
653 colorNames = addList(colors, 2, 2, 38, getHeight() - 7,
654 new TAction() {
655 // When the user presses Enter
656 public void DO() {
657 refreshFromTheme(colorNames.getSelected());
658 }
659 },
660 new TAction() {
661 // When the user navigates with keyboard
662 public void DO() {
663 refreshFromTheme(colorNames.getSelected());
664 }
665 }
666 );
667 foreground = new ForegroundPicker(this, 42, 1, 14, 6);
668 background = new BackgroundPicker(this, 42, 7, 14, 4);
669 refreshFromTheme(colors.get(0));
670 colorNames.setSelectedIndex(0);
671
672 addButton(i18n.getString("okButton"), getWidth() - 37, getHeight() - 4,
673 new TAction() {
674 public void DO() {
675 ColorTheme global = getTheme();
676 List<String> colors = editTheme.getColorNames();
677 for (String key: colors) {
678 CellAttributes attr = new CellAttributes();
679 attr.setTo(editTheme.getColor(key));
680 global.setColor(key, attr);
681 }
682 getApplication().closeWindow(TEditColorThemeWindow.this);
683 }
684 }
685 );
686
687 addButton(i18n.getString("cancelButton"), getWidth() - 25,
688 getHeight() - 4,
689 new TAction() {
690 public void DO() {
691 getApplication().closeWindow(TEditColorThemeWindow.this);
692 }
693 }
694 );
695
696 // Default to the color list
697 activate(colorNames);
698
699 // Add shortcut text
700 newStatusBar(i18n.getString("statusBar"));
701 }
702
703 // ------------------------------------------------------------------------
704 // Event handlers ---------------------------------------------------------
705 // ------------------------------------------------------------------------
706
707 /**
708 * Handle keystrokes.
709 *
710 * @param keypress keystroke event
711 */
712 @Override
713 public void onKeypress(final TKeypressEvent keypress) {
714 // Escape - behave like cancel
715 if (keypress.equals(kbEsc)) {
716 getApplication().closeWindow(this);
717 return;
718 }
719
720 // Pass to my parent
721 super.onKeypress(keypress);
722 }
723
724 // ------------------------------------------------------------------------
725 // TWindow ----------------------------------------------------------------
726 // ------------------------------------------------------------------------
727
728 /**
729 * Draw me on screen.
730 */
731 @Override
732 public void draw() {
733 super.draw();
734 CellAttributes attr = new CellAttributes();
735
736 // Draw the label on colorNames
737 attr.setTo(getTheme().getColor("twindow.background.modal"));
738 if (colorNames.isActive()) {
739 attr.setForeColor(getTheme().getColor("tlabel").getForeColor());
740 attr.setBold(getTheme().getColor("tlabel").isBold());
741 }
742 getScreen().putStringXY(3, 2, i18n.getString("colorName"), attr);
743
744 // Draw the sample text box
745 attr.reset();
746 attr.setForeColor(foreground.color);
747 attr.setBold(foreground.bold);
748 attr.setBackColor(background.color);
749 getScreen().putStringXY(getWidth() - 17, getHeight() - 6,
750 i18n.getString("textTextText"), attr);
751 getScreen().putStringXY(getWidth() - 17, getHeight() - 5,
752 i18n.getString("textTextText"), attr);
753 }
754
755 // ------------------------------------------------------------------------
756 // TEditColorThemeWindow --------------------------------------------------
757 // ------------------------------------------------------------------------
758
759 /**
760 * Set various widgets/values to the editing theme color.
761 *
762 * @param colorName name of color from theme
763 */
764 private void refreshFromTheme(final String colorName) {
765 CellAttributes attr = editTheme.getColor(colorName);
766 foreground.color = attr.getForeColor();
767 foreground.bold = attr.isBold();
768 background.color = attr.getBackColor();
769 }
770
771 /**
772 * Examines foreground, background, and colorNames and sets the color in
773 * editTheme.
774 */
775 private void saveToEditTheme() {
776 String colorName = colorNames.getSelected();
777 if (colorName == null) {
778 return;
779 }
780 CellAttributes attr = editTheme.getColor(colorName);
781 attr.setForeColor(foreground.color);
782 attr.setBold(foreground.bold);
783 attr.setBackColor(background.color);
784 editTheme.setColor(colorName, attr);
785 }
786
787 }