- private UiColors() {
- mapForegroundColor = new HashMap<Element, TextColor>();
- mapBackgroundColor = new HashMap<Element, TextColor>();
-
- // TODO: get from a file instead?
- // TODO: use a theme that doesn't give headaches...
- addEl(Element.ACTION_KEY, TextColor.ANSI.WHITE, TextColor.ANSI.RED);
- addEl(Element.ACTION_DESC, TextColor.ANSI.WHITE, TextColor.ANSI.BLUE);
- addEl(Element.CONTACT_LINE, TextColor.ANSI.WHITE, TextColor.ANSI.BLACK);
- addEl(Element.CONTACT_LINE_SELECTED, TextColor.ANSI.WHITE,
- TextColor.ANSI.BLUE);
- addEl(Element.CONTACT_LINE_SEPARATOR, TextColor.ANSI.RED,
- TextColor.ANSI.BLACK);
- addEl(Element.CONTACT_LINE_SEPARATOR_SELECTED, TextColor.ANSI.RED,
- TextColor.ANSI.BLUE);
- addEl(Element.LINE_MESSAGE, TextColor.ANSI.BLUE, TextColor.ANSI.WHITE);
- addEl(Element.LINE_MESSAGE_ERR, TextColor.ANSI.RED,
- TextColor.ANSI.WHITE);
- addEl(Element.LINE_MESSAGE_QUESTION, TextColor.ANSI.BLUE,
- TextColor.ANSI.WHITE);
- addEl(Element.LINE_MESSAGE_ANS, TextColor.ANSI.BLUE,
- TextColor.ANSI.BLACK);
- addEl(Element.TITLE_MAIN, TextColor.ANSI.WHITE, TextColor.ANSI.BLUE);
- addEl(Element.TITLE_VARIABLE, TextColor.ANSI.GREEN, TextColor.ANSI.BLUE);
- addEl(Element.TITLE_COUNT, TextColor.ANSI.RED, TextColor.ANSI.BLUE);
- addEl(Element.VIEW_CONTACT_NAME, TextColor.ANSI.BLACK,
- TextColor.ANSI.WHITE);
- addEl(Element.VIEW_CONTACT_NORMAL, TextColor.ANSI.WHITE,
- TextColor.ANSI.BLACK);
- addEl(Element.VIEW_CONTACT_NOTES_TITLE, TextColor.ANSI.BLACK,
- TextColor.ANSI.WHITE);
- }
+ /**
+ * Convert the given {@link String} value to a {@link TextColor}.
+ *
+ * @param value
+ * the {@link String} to convert
+ * @param defaultColor
+ * the default {@link TextColor} to return if the conversion
+ * failed
+ *
+ * @return the converted colour
+ */
+ static private TextColor convertToColor(String value, TextColor defaultColor) {
+ try {
+ if (value.startsWith("@")) {
+ int r = Integer.parseInt(value.substring(1, 3), 16);
+ int g = Integer.parseInt(value.substring(3, 5), 16);
+ int b = Integer.parseInt(value.substring(5, 7), 16);
+ return TextColor.Indexed.fromRGB(r, g, b);
+ } else if (value.startsWith("#")) {
+ int r = Integer.parseInt(value.substring(1, 3), 16);
+ int g = Integer.parseInt(value.substring(3, 5), 16);
+ int b = Integer.parseInt(value.substring(5, 7), 16);
+ return new TextColor.RGB(r, g, b);
+ } else if (value.replaceAll("[0-9]*", "").length() == 0) {
+ return new TextColor.Indexed(Integer.parseInt(value));
+ } else {
+ return TextColor.ANSI.valueOf(value);
+ }
+ } catch (Exception e) {
+ new Exception("Cannot convert value to colour: " + value, e)
+ .printStackTrace();
+ }