X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fjvcard%2Ftui%2FUiColors.java;h=a851d4e5e18320a8a787082b6801eacde2a7278e;hb=f06c81000632cfb5f525ca458f719338f55f9f66;hp=877c73964defee82004f1e4c76ffb1ad685fbc72;hpb=ed91f27a4f628ec59b0e85cdbb0319287c503f9d;p=jvcard.git diff --git a/src/be/nikiroo/jvcard/tui/UiColors.java b/src/be/nikiroo/jvcard/tui/UiColors.java index 877c739..a851d4e 100644 --- a/src/be/nikiroo/jvcard/tui/UiColors.java +++ b/src/be/nikiroo/jvcard/tui/UiColors.java @@ -3,13 +3,16 @@ package be.nikiroo.jvcard.tui; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.io.Writer; import java.util.HashMap; import java.util.Map; import java.util.MissingResourceException; import java.util.Properties; -import be.nikiroo.jvcard.resources.bundles.ColorBundle; -import be.nikiroo.jvcard.resources.enums.ColorOption; +import be.nikiroo.jvcard.resources.ColorBundle; +import be.nikiroo.jvcard.resources.ColorOption; +import be.nikiroo.jvcard.resources.Target; +import be.nikiroo.utils.resources.Bundle; import com.googlecode.lanterna.TextColor; import com.googlecode.lanterna.graphics.PropertiesTheme; @@ -23,17 +26,67 @@ import com.googlecode.lanterna.gui2.Label; * @author niki * */ -public class UiColors extends ColorBundle { +public class UiColors { static private Object lock = new Object(); static private UiColors instance = null; private Map colorMap = null; + private ColorBundle bundle; private UiColors() { - super(); + bundle = new ColorBundle(); colorMap = new HashMap(); } + /** + * Return a {@link Theme} following the colours defined in + * colors.properties. + * + * @return the {@link Theme} + */ + static public Theme getCustomTheme() { + // Create a properties-theme with our own custom values for some of it + Properties properties = new Properties(); + try { + ClassLoader classLoader = AbstractTextGUI.class.getClassLoader(); + InputStream resourceAsStream = classLoader + .getResourceAsStream("default-theme.properties"); + if (resourceAsStream == null) { + resourceAsStream = new FileInputStream( + "src/main/resources/default-theme.properties"); + } + properties.load(resourceAsStream); + resourceAsStream.close(); + } catch (IOException e) { + } + + // default colours: + String fg = getForegroundColor(ColorOption.DEFAULT).toString(); + String bg = getBackgroundColor(ColorOption.DEFAULT).toString(); + for (String def : new String[] { "com.googlecode.lanterna", + "com.googlecode.lanterna.gui2.TextBox", + "com.googlecode.lanterna.gui2.AbstractListBox", + "com.googlecode.lanterna.gui2.Borders$StandardBorder" }) { + properties.put(def + ".foreground", fg); + properties.put(def + ".background", bg); + } + + // no bold on borders prelight: + properties + .put("com.googlecode.lanterna.gui2.Borders$StandardBorder.sgr[PRELIGHT]", + ""); + + // line answers: + fg = getForegroundColor(ColorOption.LINE_MESSAGE_ANS).toString(); + bg = getBackgroundColor(ColorOption.LINE_MESSAGE_ANS).toString(); + String prop = "com.googlecode.lanterna.gui2.TextBox"; + properties.put(prop + ".foreground[ACTIVE]", fg); + properties.put(prop + ".background[ACTIVE]", bg); + + PropertiesTheme theme = new PropertiesTheme(properties); + return theme; + } + /** * Create a new {@link Label} with the colours of the given * {@link ColorOption}. @@ -79,7 +132,7 @@ public class UiColors extends ColorBundle { if (!getInstance().colorMap.containsKey(el.name() + "_BG")) { String value = null; try { - value = getInstance().map.getString(el.name() + "_BG"); + value = getInstance().bundle.getStringX(el, "BG"); } catch (MissingResourceException mre) { value = null; } @@ -102,7 +155,7 @@ public class UiColors extends ColorBundle { if (!getInstance().colorMap.containsKey(el.name() + "_FG")) { String value = null; try { - value = getInstance().map.getString(el.name() + "_FG"); + value = getInstance().bundle.getStringX(el, "FG"); } catch (MissingResourceException mre) { value = null; } @@ -113,33 +166,6 @@ public class UiColors extends ColorBundle { return getInstance().colorMap.get(el.name() + "_FG"); } - /** - * Return a {@link Theme} following the colours defined in - * display.properties. - * - * @return the {@link Theme} - */ - static Theme getCustomTheme() { - // Create a properties-theme with our own custom values for some of it - Properties properties = new Properties(); - try { - ClassLoader classLoader = AbstractTextGUI.class.getClassLoader(); - InputStream resourceAsStream = classLoader - .getResourceAsStream("default-theme.properties"); - if (resourceAsStream == null) { - resourceAsStream = new FileInputStream( - "src/main/resources/default-theme.properties"); - } - properties.load(resourceAsStream); - resourceAsStream.close(); - } catch (IOException e) { - } - properties.put("com.googlecode.lanterna.background", "black"); - PropertiesTheme theme = new PropertiesTheme(properties); - - return theme; - } - /** * Get the (unique) instance of this class. *