1 package be
.nikiroo
.jvcard
.tui
;
3 import java
.util
.HashMap
;
6 import com
.googlecode
.lanterna
.TextColor
;
7 import com
.googlecode
.lanterna
.gui2
.Label
;
10 * All colour information must come from here.
15 public class UiColors
{
16 static private Object lock
= new Object();
17 static private UiColors instance
= null;
19 private Map
<Element
, TextColor
> mapForegroundColor
= null;
20 private Map
<Element
, TextColor
> mapBackgroundColor
= null;
21 private boolean utf
= true;
24 * Get the (unique) instance of this class.
26 * @return the (unique) instance
28 static public UiColors
getInstance() {
31 instance
= new UiColors();
39 TITLE_MAIN
, TITLE_VARIABLE
, TITLE_COUNT
, //
40 ACTION_KEY
, ACTION_DESC
, //
41 LINE_MESSAGE
, LINE_MESSAGE_ERR
, LINE_MESSAGE_QUESTION
, LINE_MESSAGE_ANS
, //
42 CONTACT_LINE
, CONTACT_LINE_SEPARATOR
, CONTACT_LINE_SELECTED
, CONTACT_LINE_SEPARATOR_SELECTED
, CONTACT_LINE_DIRTY
, CONTACT_LINE_DIRTY_SELECTED
;
45 * Get the foreground colour of this element.
49 public TextColor
getForegroundColor() {
50 return UiColors
.getInstance().getForegroundColor(this);
54 * Get the background colour of this element.
58 public TextColor
getBackgroundColor() {
59 return UiColors
.getInstance().getBackgroundColor(this);
62 public Label
createLabel(String text
) {
63 return UiColors
.getInstance().createLabel(this, text
);
66 public void themeLabel(Label lbl
) {
67 UiColors
.getInstance().themeLabel(this, lbl
);
72 * Check if unicode characters should be used.
74 * @return TRUE to allow unicode
76 public boolean isUnicode() {
81 * Allow or disallow unicode characters in the program.
84 * TRUE to allow unuciode, FALSE to only allow ASCII characters
86 public void setUnicode(boolean utf
) {
90 private Label
createLabel(Element el
, String text
) {
91 Label lbl
= new Label(text
);
96 private void themeLabel(Element el
, Label lbl
) {
97 lbl
.setForegroundColor(el
.getForegroundColor());
98 lbl
.setBackgroundColor(el
.getBackgroundColor());
101 private TextColor
getForegroundColor(Element el
) {
102 if (mapForegroundColor
.containsKey(el
)) {
103 return mapForegroundColor
.get(el
);
106 return TextColor
.ANSI
.BLACK
;
109 private TextColor
getBackgroundColor(Element el
) {
110 if (mapBackgroundColor
.containsKey(el
)) {
111 return mapBackgroundColor
.get(el
);
114 return TextColor
.ANSI
.WHITE
;
118 mapForegroundColor
= new HashMap
<Element
, TextColor
>();
119 mapBackgroundColor
= new HashMap
<Element
, TextColor
>();
121 // TODO: get from a file instead?
122 // TODO: use a theme that doesn't give headaches...
123 addEl(Element
.ACTION_KEY
, TextColor
.ANSI
.WHITE
, TextColor
.ANSI
.RED
);
124 addEl(Element
.ACTION_DESC
, TextColor
.ANSI
.WHITE
, TextColor
.ANSI
.BLUE
);
125 addEl(Element
.CONTACT_LINE
, TextColor
.ANSI
.WHITE
, TextColor
.ANSI
.BLACK
);
126 addEl(Element
.CONTACT_LINE_SELECTED
, TextColor
.ANSI
.WHITE
,
127 TextColor
.ANSI
.BLUE
);
128 addEl(Element
.CONTACT_LINE_SEPARATOR
, TextColor
.ANSI
.RED
,
129 TextColor
.ANSI
.BLACK
);
130 addEl(Element
.CONTACT_LINE_SEPARATOR_SELECTED
, TextColor
.ANSI
.RED
,
131 TextColor
.ANSI
.BLUE
);
132 addEl(Element
.LINE_MESSAGE
, TextColor
.ANSI
.BLUE
, TextColor
.ANSI
.WHITE
);
133 addEl(Element
.LINE_MESSAGE_ERR
, TextColor
.ANSI
.RED
,
134 TextColor
.ANSI
.WHITE
);
135 addEl(Element
.LINE_MESSAGE_QUESTION
, TextColor
.ANSI
.BLUE
,
136 TextColor
.ANSI
.WHITE
);
137 addEl(Element
.LINE_MESSAGE_ANS
, TextColor
.ANSI
.BLUE
,
138 TextColor
.ANSI
.BLACK
);
139 addEl(Element
.TITLE_MAIN
, TextColor
.ANSI
.WHITE
, TextColor
.ANSI
.BLUE
);
140 addEl(Element
.TITLE_VARIABLE
, TextColor
.ANSI
.GREEN
, TextColor
.ANSI
.BLUE
);
141 addEl(Element
.TITLE_COUNT
, TextColor
.ANSI
.RED
, TextColor
.ANSI
.BLUE
);
144 private void addEl(Element el
, TextColor fore
, TextColor back
) {
145 mapForegroundColor
.put(el
, fore
);
146 mapBackgroundColor
.put(el
, back
);