X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fjvcard%2Ftui%2FUiColors.java;h=7d951c8d06869dee17ce3ebd9b8398148fb8875d;hb=71fa2aace64c4470e091abfd5ae4bef115133467;hp=abac7d54b56146746a88b6ae83c2451ac9d11178;hpb=e119a1c1a924998b9315e46c96b1c750aab1deb9;p=jvcard.git diff --git a/src/be/nikiroo/jvcard/tui/UiColors.java b/src/be/nikiroo/jvcard/tui/UiColors.java index abac7d5..7d951c8 100644 --- a/src/be/nikiroo/jvcard/tui/UiColors.java +++ b/src/be/nikiroo/jvcard/tui/UiColors.java @@ -1,13 +1,20 @@ package be.nikiroo.jvcard.tui; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; 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 com.googlecode.lanterna.TextColor; +import com.googlecode.lanterna.graphics.PropertiesTheme; +import com.googlecode.lanterna.graphics.Theme; +import com.googlecode.lanterna.gui2.AbstractTextGUI; import com.googlecode.lanterna.gui2.Label; /** @@ -28,7 +35,57 @@ public class UiColors extends ColorBundle { } /** - * Create a new {@link Label} with the colours of the given {@link ColorOption}. + * 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}. * * @param el * the {@link ColorOption}