Commit | Line | Data |
---|---|---|
a3b510ab NR |
1 | package be.nikiroo.jvcard.tui; |
2 | ||
3 | import java.util.HashMap; | |
4 | import java.util.Map; | |
5 | ||
6 | import com.googlecode.lanterna.TextColor; | |
7 | import com.googlecode.lanterna.gui2.Label; | |
8 | ||
9 | /** | |
10 | * All colour information must come from here. | |
11 | * | |
12 | * @author niki | |
13 | * | |
14 | */ | |
15 | public class UiColors { | |
16 | static private Object lock = new Object(); | |
17 | static private UiColors instance = null; | |
18 | ||
19 | private Map<Element, TextColor> mapForegroundColor = null; | |
20 | private Map<Element, TextColor> mapBackgroundColor = null; | |
21 | ||
22 | /** | |
23 | * Get the (unique) instance of this class. | |
24 | * | |
25 | * @return the (unique) instance | |
26 | */ | |
27 | static public UiColors getInstance() { | |
28 | synchronized (lock) { | |
29 | if (instance == null) | |
30 | instance = new UiColors(); | |
31 | } | |
32 | ||
33 | return instance; | |
34 | } | |
35 | ||
36 | public enum Element { | |
9c8baf0c | 37 | DEFAULT, ACTION_KEY, ACTION_DESC, LINE_MESSAGE, LINE_MESSAGE_ERR, LINE_MESSAGE_QUESTION, LINE_MESSAGE_ANS, CONTACT_LINE, CONTACT_LINE_SEPARATOR, CONTACT_LINE_SELECTED, CONTACT_LINE_SEPARATOR_SELECTED; |
a3b510ab NR |
38 | |
39 | /** | |
40 | * Get the foreground colour of this element. | |
41 | * | |
42 | * @return the colour | |
43 | */ | |
44 | public TextColor getForegroundColor() { | |
45 | return UiColors.getInstance().getForegroundColor(this); | |
46 | } | |
47 | ||
48 | /** | |
49 | * Get the background colour of this element. | |
50 | * | |
51 | * @return the colour | |
52 | */ | |
53 | public TextColor getBackgroundColor() { | |
54 | return UiColors.getInstance().getBackgroundColor(this); | |
55 | } | |
56 | ||
57 | public Label createLabel(String text) { | |
58 | return UiColors.getInstance().createLabel(this, text); | |
59 | } | |
60 | ||
61 | public void themeLabel(Label lbl) { | |
62 | UiColors.getInstance().themeLabel(this, lbl); | |
63 | } | |
64 | } | |
65 | ||
66 | private Label createLabel(Element el, String text) { | |
67 | Label lbl = new Label(text); | |
68 | themeLabel(el, lbl); | |
69 | return lbl; | |
70 | } | |
71 | ||
72 | private void themeLabel(Element el, Label lbl) { | |
73 | lbl.setForegroundColor(el.getForegroundColor()); | |
74 | lbl.setBackgroundColor(el.getBackgroundColor()); | |
75 | } | |
76 | ||
77 | private TextColor getForegroundColor(Element el) { | |
78 | if (mapForegroundColor.containsKey(el)) { | |
79 | return mapForegroundColor.get(el); | |
80 | } | |
81 | ||
9c8baf0c | 82 | return TextColor.ANSI.BLACK; |
a3b510ab NR |
83 | } |
84 | ||
85 | private TextColor getBackgroundColor(Element el) { | |
86 | if (mapBackgroundColor.containsKey(el)) { | |
87 | return mapBackgroundColor.get(el); | |
88 | } | |
89 | ||
9c8baf0c | 90 | return TextColor.ANSI.WHITE; |
a3b510ab NR |
91 | } |
92 | ||
93 | private UiColors() { | |
94 | mapForegroundColor = new HashMap<Element, TextColor>(); | |
95 | mapBackgroundColor = new HashMap<Element, TextColor>(); | |
96 | ||
97 | // TODO: get from a file instead? | |
98 | // TODO: use a theme that doesn't give headaches... | |
99 | addEl(Element.ACTION_KEY, TextColor.ANSI.WHITE, TextColor.ANSI.RED); | |
100 | addEl(Element.ACTION_DESC, TextColor.ANSI.WHITE, TextColor.ANSI.BLUE); | |
101 | addEl(Element.CONTACT_LINE, TextColor.ANSI.WHITE, TextColor.ANSI.BLACK); | |
102 | addEl(Element.CONTACT_LINE_SELECTED, TextColor.ANSI.WHITE, | |
103 | TextColor.ANSI.BLUE); | |
9c8baf0c NR |
104 | addEl(Element.CONTACT_LINE_SEPARATOR, TextColor.ANSI.RED, TextColor.ANSI.BLACK); |
105 | addEl(Element.CONTACT_LINE_SEPARATOR_SELECTED, TextColor.ANSI.RED, | |
106 | TextColor.ANSI.BLUE); | |
a3b510ab NR |
107 | addEl(Element.LINE_MESSAGE, TextColor.ANSI.BLUE, TextColor.ANSI.WHITE); |
108 | addEl(Element.LINE_MESSAGE_ERR, TextColor.ANSI.RED, | |
109 | TextColor.ANSI.WHITE); | |
110 | addEl(Element.LINE_MESSAGE_QUESTION, TextColor.ANSI.BLUE, | |
111 | TextColor.ANSI.WHITE); | |
112 | addEl(Element.LINE_MESSAGE_ANS, TextColor.ANSI.BLUE, | |
113 | TextColor.ANSI.BLACK); | |
114 | } | |
115 | ||
116 | private void addEl(Element el, TextColor fore, TextColor back) { | |
117 | mapForegroundColor.put(el, fore); | |
118 | mapBackgroundColor.put(el, back); | |
119 | } | |
120 | ||
121 | } |