You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by sm...@apache.org on 2014/08/22 11:15:11 UTC

svn commit: r1619713 - in /pivot/trunk: tests/src/org/apache/pivot/tests/TerraTheme_test.json wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTheme.java wtk/src/org/apache/pivot/wtk/Theme.java wtk/src/org/apache/pivot/wtk/skin/ComponentSkin.java

Author: smartini
Date: Fri Aug 22 09:15:11 2014
New Revision: 1619713

URL: http://svn.apache.org/r1619713
Log:
PIVOT-689, add defaultBackgroundColor and defaultForegroundColor in Terra Theme json config file (to be able to set them) with a good fallback value.
Note that even in general Theme there are (general) default values for them.

As a sample, add some (very visible: red, and yellow) values for them.

Modified:
    pivot/trunk/tests/src/org/apache/pivot/tests/TerraTheme_test.json
    pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTheme.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/Theme.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ComponentSkin.java

Modified: pivot/trunk/tests/src/org/apache/pivot/tests/TerraTheme_test.json
URL: http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/TerraTheme_test.json?rev=1619713&r1=1619712&r2=1619713&view=diff
==============================================================================
--- pivot/trunk/tests/src/org/apache/pivot/tests/TerraTheme_test.json (original)
+++ pivot/trunk/tests/src/org/apache/pivot/tests/TerraTheme_test.json Fri Aug 22 09:15:11 2014
@@ -45,5 +45,8 @@
         warning: "message_type-warning-16x16.png",
         question: "message_type-question-16x16.png",
         info: "message_type-info-16x16.png"
-    }
+    },
+
+    defaultBackgroundColor: "#ff0000",
+    defaultForegroundColor: "#ffff00"
 }

Modified: pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTheme.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTheme.java?rev=1619713&r1=1619712&r2=1619713&view=diff
==============================================================================
--- pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTheme.java (original)
+++ pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTheme.java Fri Aug 22 09:15:11 2014
@@ -102,6 +102,9 @@ public final class TerraTheme extends Th
     private static boolean themeIsDark = false;
     private static boolean themeIsFlat = false;
 
+    private static Color defaultBackgroundColor;
+    private static Color defaultForegroundColor;
+
     public static final String LOCATION_PROPERTY = "location";
     public static final String COMMAND_BUTTON_STYLE = "commandButton";
 
@@ -290,6 +293,25 @@ public final class TerraTheme extends Th
                 Map<String, String> smallMessageIconNames = (Map<String, String>) properties.get("smallMessageIcons");
                 smallMessageIcons = new HashMap<>();
                 loadMessageIcons(smallMessageIconNames, smallMessageIcons);
+
+                try {
+                    defaultBackgroundColor = Color.decode((String) properties.get("defaultBackgroundColor"));
+                } catch (NullPointerException npe1) {
+                    if (!isThemeDark()) {
+                        defaultBackgroundColor = Color.WHITE;
+                    } else {
+                        defaultBackgroundColor = Color.BLACK;
+                    }
+                }
+                try {
+                    defaultForegroundColor = Color.decode((String) properties.get("defaultForegroundColor"));
+                } catch (NullPointerException npe2) {
+                    if (!isThemeDark()) {
+                        defaultForegroundColor = Color.WHITE;
+                    } else {
+                        defaultForegroundColor = Color.BLACK;
+                    }
+                }
             } finally {
                 inputStream.close();
             }
@@ -504,6 +526,26 @@ public final class TerraTheme extends Th
     }
 
     /**
+     * Gets the theme's default background color.
+     * 
+     * @return the color if set, or White if the theme is not dark (default), or Black.
+     */
+    @Override
+    public Color getDefaultBackgroundColor() {
+        return defaultBackgroundColor;
+    }
+
+    /**
+     * Gets the theme's default foreground color.
+     * 
+     * @return the color if set, or Black if the theme is not dark (default), or White.
+     */
+    @Override
+    public Color getDefaultForegroundColor() {
+        return defaultForegroundColor;
+    }
+
+    /**
      * Returns a brighter version of the specified color. Specifically, it
      * increases the brightness (in the HSB color model) by the
      * <tt>colorMultiplier</tt> factor and <tt>themeIsDark</tt> flag already

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Theme.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Theme.java?rev=1619713&r1=1619712&r2=1619713&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Theme.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Theme.java Fri Aug 22 09:15:11 2014
@@ -215,6 +215,30 @@ public abstract class Theme {
     }
 
     /**
+     * Returns a safe (and general) default background color.
+     * 
+     * @return White if the theme is not dark (default), or Black.
+     */
+    public Color getDefaultBackgroundColor() {
+        if (!isThemeDark()) {
+            return Color.WHITE;
+        }
+        return Color.BLACK;
+    }
+
+    /**
+     * Returns a safe (and general) default foreground color.
+     * 
+     * @return Black if the theme is not dark (default), or White.
+     */
+    public Color getDefaultForegroundColor() {
+        if (!isThemeDark()) {
+            return Color.BLACK;
+        }
+        return Color.WHITE;
+    }
+
+    /**
      * Gets the current theme, as determined by the {@linkplain #PROVIDER_NAME
      * theme provider}.
      *

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ComponentSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ComponentSkin.java?rev=1619713&r1=1619712&r2=1619713&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ComponentSkin.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ComponentSkin.java Fri Aug 22 09:15:11 2014
@@ -437,27 +437,21 @@ public abstract class ComponentSkin impl
     }
 
     /**
-     * Returns the default background color.
+     * Returns the Theme default background color.
      * 
      * @return White if the theme is not dark (default), or Black.
      */
     protected Color defaultBackgroundColor() {
-        if (!themeIsDark()) {
-            return Color.WHITE;
-        }
-        return Color.BLACK;
+        return currentTheme().getDefaultBackgroundColor();
     }
 
     /**
-     * Returns the default foreground color.
+     * Returns the Theme default foreground color.
      * 
      * @return Black if the theme is not dark (default), or White.
      */
     protected Color defaultForegroundColor() {
-        if (!themeIsDark()) {
-            return Color.BLACK;
-        }
-        return Color.WHITE;
+        return currentTheme().getDefaultForegroundColor();
     }
 
 }