Fix inclusion of lanterna's resources + fix warning
[jvcard.git] / src / be / nikiroo / jvcard / tui / UiColors.java
index abac7d54b56146746a88b6ae83c2451ac9d11178..877c73964defee82004f1e4c76ffb1ad685fbc72 100644 (file)
@@ -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,8 @@ public class UiColors extends ColorBundle {
        }
 
        /**
-        * Create a new {@link Label} with the colours of the given {@link ColorOption}.
+        * Create a new {@link Label} with the colours of the given
+        * {@link ColorOption}.
         * 
         * @param el
         *            the {@link ColorOption}
@@ -105,6 +113,33 @@ 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.
         *