New launcher class to start all 3 modes:
[jvcard.git] / src / be / nikiroo / jvcard / tui / UiColors.java
index a646dbead669ed9dafaf3f549b0eee783eb7f0e5..3fa83c7b9477f8f0fdde1b9a453add835dbbaa34 100644 (file)
@@ -2,6 +2,7 @@ package be.nikiroo.jvcard.tui;
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.MissingResourceException;
 import java.util.ResourceBundle;
 
 import be.nikiroo.jvcard.resources.Bundles;
@@ -21,7 +22,6 @@ public class UiColors {
 
        private ResourceBundle bundle = null;
        private Map<String, TextColor> colorMap = null;
-       private boolean utf = true;
 
        private UiColors() {
                colorMap = new HashMap<String, TextColor>();
@@ -85,25 +85,6 @@ public class UiColors {
                }
        }
 
-       /**
-        * Check if unicode characters should be used.
-        * 
-        * @return TRUE to allow unicode
-        */
-       public boolean isUnicode() {
-               return utf;
-       }
-
-       /**
-        * Allow or disallow unicode characters in the program.
-        * 
-        * @param utf
-        *            TRUE to allow unuciode, FALSE to only allow ASCII characters
-        */
-       public void setUnicode(boolean utf) {
-               this.utf = utf;
-       }
-
        /**
         * Create a new {@link Label} with the colours of the given {@link Element}.
         * 
@@ -146,7 +127,12 @@ public class UiColors {
         */
        private TextColor getBackgroundColor(Element el) {
                if (!colorMap.containsKey(el.name() + "_BG")) {
-                       String value = bundle.getString(el.name() + "_BG");
+                       String value = null;
+                       try {
+                               value = bundle.getString(el.name() + "_BG");
+                       } catch (MissingResourceException mre) {
+                               value = null;
+                       }
                        colorMap.put(el.name() + "_BG",
                                        convertToColor(value, TextColor.ANSI.BLACK));
                }
@@ -164,7 +150,12 @@ public class UiColors {
         */
        private TextColor getForegroundColor(Element el) {
                if (!colorMap.containsKey(el.name() + "_FG")) {
-                       String value = bundle.getString(el.name() + "_FG");
+                       String value = null;
+                       try {
+                               value = bundle.getString(el.name() + "_FG");
+                       } catch (MissingResourceException mre) {
+                               value = null;
+                       }
                        colorMap.put(el.name() + "_FG",
                                        convertToColor(value, TextColor.ANSI.WHITE));
                }
@@ -209,6 +200,8 @@ public class UiColors {
                                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);
                        }