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;
23 * Get the (unique) instance of this class.
25 * @return the (unique) instance
27 static public UiColors
getInstance() {
30 instance
= new UiColors();
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
;
40 * Get the foreground colour of this element.
44 public TextColor
getForegroundColor() {
45 return UiColors
.getInstance().getForegroundColor(this);
49 * Get the background colour of this element.
53 public TextColor
getBackgroundColor() {
54 return UiColors
.getInstance().getBackgroundColor(this);
57 public Label
createLabel(String text
) {
58 return UiColors
.getInstance().createLabel(this, text
);
61 public void themeLabel(Label lbl
) {
62 UiColors
.getInstance().themeLabel(this, lbl
);
66 private Label
createLabel(Element el
, String text
) {
67 Label lbl
= new Label(text
);
72 private void themeLabel(Element el
, Label lbl
) {
73 lbl
.setForegroundColor(el
.getForegroundColor());
74 lbl
.setBackgroundColor(el
.getBackgroundColor());
77 private TextColor
getForegroundColor(Element el
) {
78 if (mapForegroundColor
.containsKey(el
)) {
79 return mapForegroundColor
.get(el
);
82 return TextColor
.ANSI
.BLACK
;
85 private TextColor
getBackgroundColor(Element el
) {
86 if (mapBackgroundColor
.containsKey(el
)) {
87 return mapBackgroundColor
.get(el
);
90 return TextColor
.ANSI
.WHITE
;
94 mapForegroundColor
= new HashMap
<Element
, TextColor
>();
95 mapBackgroundColor
= new HashMap
<Element
, TextColor
>();
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
);
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
);
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
);
116 private void addEl(Element el
, TextColor fore
, TextColor back
) {
117 mapForegroundColor
.put(el
, fore
);
118 mapBackgroundColor
.put(el
, back
);