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();
38 TITLE_MAIN
, TITLE_VARIABLE
, TITLE_COUNT
, //
39 ACTION_KEY
, ACTION_DESC
, //
40 LINE_MESSAGE
, LINE_MESSAGE_ERR
, LINE_MESSAGE_QUESTION
, LINE_MESSAGE_ANS
, //
41 CONTACT_LINE
, CONTACT_LINE_SEPARATOR
, CONTACT_LINE_SELECTED
, CONTACT_LINE_SEPARATOR_SELECTED
, CONTACT_LINE_DIRTY
, CONTACT_LINE_DIRTY_SELECTED
;
44 * Get the foreground colour of this element.
48 public TextColor
getForegroundColor() {
49 return UiColors
.getInstance().getForegroundColor(this);
53 * Get the background colour of this element.
57 public TextColor
getBackgroundColor() {
58 return UiColors
.getInstance().getBackgroundColor(this);
61 public Label
createLabel(String text
) {
62 return UiColors
.getInstance().createLabel(this, text
);
65 public void themeLabel(Label lbl
) {
66 UiColors
.getInstance().themeLabel(this, lbl
);
70 private Label
createLabel(Element el
, String text
) {
71 Label lbl
= new Label(text
);
76 private void themeLabel(Element el
, Label lbl
) {
77 lbl
.setForegroundColor(el
.getForegroundColor());
78 lbl
.setBackgroundColor(el
.getBackgroundColor());
81 private TextColor
getForegroundColor(Element el
) {
82 if (mapForegroundColor
.containsKey(el
)) {
83 return mapForegroundColor
.get(el
);
86 return TextColor
.ANSI
.BLACK
;
89 private TextColor
getBackgroundColor(Element el
) {
90 if (mapBackgroundColor
.containsKey(el
)) {
91 return mapBackgroundColor
.get(el
);
94 return TextColor
.ANSI
.WHITE
;
98 mapForegroundColor
= new HashMap
<Element
, TextColor
>();
99 mapBackgroundColor
= new HashMap
<Element
, TextColor
>();
101 // TODO: get from a file instead?
102 // TODO: use a theme that doesn't give headaches...
103 addEl(Element
.ACTION_KEY
, TextColor
.ANSI
.WHITE
, TextColor
.ANSI
.RED
);
104 addEl(Element
.ACTION_DESC
, TextColor
.ANSI
.WHITE
, TextColor
.ANSI
.BLUE
);
105 addEl(Element
.CONTACT_LINE
, TextColor
.ANSI
.WHITE
, TextColor
.ANSI
.BLACK
);
106 addEl(Element
.CONTACT_LINE_SELECTED
, TextColor
.ANSI
.WHITE
,
107 TextColor
.ANSI
.BLUE
);
108 addEl(Element
.CONTACT_LINE_SEPARATOR
, TextColor
.ANSI
.RED
,
109 TextColor
.ANSI
.BLACK
);
110 addEl(Element
.CONTACT_LINE_SEPARATOR_SELECTED
, TextColor
.ANSI
.RED
,
111 TextColor
.ANSI
.BLUE
);
112 addEl(Element
.LINE_MESSAGE
, TextColor
.ANSI
.BLUE
, TextColor
.ANSI
.WHITE
);
113 addEl(Element
.LINE_MESSAGE_ERR
, TextColor
.ANSI
.RED
,
114 TextColor
.ANSI
.WHITE
);
115 addEl(Element
.LINE_MESSAGE_QUESTION
, TextColor
.ANSI
.BLUE
,
116 TextColor
.ANSI
.WHITE
);
117 addEl(Element
.LINE_MESSAGE_ANS
, TextColor
.ANSI
.BLUE
,
118 TextColor
.ANSI
.BLACK
);
119 addEl(Element
.TITLE_MAIN
, TextColor
.ANSI
.WHITE
, TextColor
.ANSI
.BLUE
);
120 addEl(Element
.TITLE_VARIABLE
, TextColor
.ANSI
.GREEN
,
121 TextColor
.ANSI
.BLUE
);
122 addEl(Element
.TITLE_COUNT
, TextColor
.ANSI
.RED
, TextColor
.ANSI
.BLUE
);
125 private void addEl(Element el
, TextColor fore
, TextColor back
) {
126 mapForegroundColor
.put(el
, fore
);
127 mapBackgroundColor
.put(el
, back
);