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
, //
43 VIEW_CONTACT_NAME
, VIEW_CONTACT_NORMAL
, VIEW_CONTACT_NOTES_TITLE
, //
47 * Get the foreground colour of this element.
51 public TextColor
getForegroundColor() {
52 return UiColors
.getInstance().getForegroundColor(this);
56 * Get the background colour of this element.
60 public TextColor
getBackgroundColor() {
61 return UiColors
.getInstance().getBackgroundColor(this);
64 public Label
createLabel(String text
) {
65 return UiColors
.getInstance().createLabel(this, text
);
68 public void themeLabel(Label lbl
) {
69 UiColors
.getInstance().themeLabel(this, lbl
);
74 * Check if unicode characters should be used.
76 * @return TRUE to allow unicode
78 public boolean isUnicode() {
83 * Allow or disallow unicode characters in the program.
86 * TRUE to allow unuciode, FALSE to only allow ASCII characters
88 public void setUnicode(boolean utf
) {
92 private Label
createLabel(Element el
, String text
) {
96 Label lbl
= new Label(text
);
101 private void themeLabel(Element el
, Label lbl
) {
102 lbl
.setForegroundColor(el
.getForegroundColor());
103 lbl
.setBackgroundColor(el
.getBackgroundColor());
106 private TextColor
getForegroundColor(Element el
) {
107 if (mapForegroundColor
.containsKey(el
)) {
108 return mapForegroundColor
.get(el
);
111 return TextColor
.ANSI
.BLACK
;
114 private TextColor
getBackgroundColor(Element el
) {
115 if (mapBackgroundColor
.containsKey(el
)) {
116 return mapBackgroundColor
.get(el
);
119 return TextColor
.ANSI
.WHITE
;
123 mapForegroundColor
= new HashMap
<Element
, TextColor
>();
124 mapBackgroundColor
= new HashMap
<Element
, TextColor
>();
126 // TODO: get from a file instead?
127 // TODO: use a theme that doesn't give headaches...
128 addEl(Element
.ACTION_KEY
, TextColor
.ANSI
.WHITE
, TextColor
.ANSI
.RED
);
129 addEl(Element
.ACTION_DESC
, TextColor
.ANSI
.WHITE
, TextColor
.ANSI
.BLUE
);
130 addEl(Element
.CONTACT_LINE
, TextColor
.ANSI
.WHITE
, TextColor
.ANSI
.BLACK
);
131 addEl(Element
.CONTACT_LINE_SELECTED
, TextColor
.ANSI
.WHITE
,
132 TextColor
.ANSI
.BLUE
);
133 addEl(Element
.CONTACT_LINE_SEPARATOR
, TextColor
.ANSI
.RED
,
134 TextColor
.ANSI
.BLACK
);
135 addEl(Element
.CONTACT_LINE_SEPARATOR_SELECTED
, TextColor
.ANSI
.RED
,
136 TextColor
.ANSI
.BLUE
);
137 addEl(Element
.LINE_MESSAGE
, TextColor
.ANSI
.BLUE
, TextColor
.ANSI
.WHITE
);
138 addEl(Element
.LINE_MESSAGE_ERR
, TextColor
.ANSI
.RED
,
139 TextColor
.ANSI
.WHITE
);
140 addEl(Element
.LINE_MESSAGE_QUESTION
, TextColor
.ANSI
.BLUE
,
141 TextColor
.ANSI
.WHITE
);
142 addEl(Element
.LINE_MESSAGE_ANS
, TextColor
.ANSI
.BLUE
,
143 TextColor
.ANSI
.BLACK
);
144 addEl(Element
.TITLE_MAIN
, TextColor
.ANSI
.WHITE
, TextColor
.ANSI
.BLUE
);
145 addEl(Element
.TITLE_VARIABLE
, TextColor
.ANSI
.GREEN
, TextColor
.ANSI
.BLUE
);
146 addEl(Element
.TITLE_COUNT
, TextColor
.ANSI
.RED
, TextColor
.ANSI
.BLUE
);
147 addEl(Element
.VIEW_CONTACT_NAME
, TextColor
.ANSI
.BLACK
,
148 TextColor
.ANSI
.WHITE
);
149 addEl(Element
.VIEW_CONTACT_NORMAL
, TextColor
.ANSI
.WHITE
,
150 TextColor
.ANSI
.BLACK
);
151 addEl(Element
.VIEW_CONTACT_NOTES_TITLE
, TextColor
.ANSI
.BLACK
,
152 TextColor
.ANSI
.WHITE
);
155 private void addEl(Element el
, TextColor fore
, TextColor back
) {
156 mapForegroundColor
.put(el
, fore
);
157 mapBackgroundColor
.put(el
, back
);