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 2013/10/29 15:40:26 UTC

svn commit: r1536737 - in /pivot/trunk: wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTheme.java wtk/src/org/apache/pivot/wtk/Theme.java

Author: smartini
Date: Tue Oct 29 14:40:26 2013
New Revision: 1536737

URL: http://svn.apache.org/r1536737
Log:
PIVOT-689, add dark theme generic support, and cleanup of methods moved in ColorUtilities.
Note that all theme definition files must be updated to include the new parameter (I'll do it in next commit).

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

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=1536737&r1=1536736&r2=1536737&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 Tue Oct 29 14:40:26 2013
@@ -86,6 +86,7 @@ import org.apache.pivot.wtk.TreeView;
 import org.apache.pivot.wtk.VFSBrowser;
 import org.apache.pivot.wtk.VFSBrowserSheet;
 import org.apache.pivot.wtk.media.Image;
+import org.apache.pivot.wtk.util.ColorUtilities;
 
 /**
  * Terra theme.
@@ -98,6 +99,7 @@ public final class TerraTheme extends Th
     private HashMap<MessageType, Image> smallMessageIcons = null;
 
     private static float colorMultiplier = 0.1f;
+    private static boolean themeDark = false;
 
     public static final String LOCATION_PROPERTY = "location";
     public static final String COMMAND_BUTTON_STYLE = "commandButton";
@@ -258,6 +260,8 @@ public final class TerraTheme extends Th
 
                 colorMultiplier = ((Double) properties.get("colorMultiplier")).floatValue();
 
+                themeDark = ((Boolean) properties.get("themeIsDark")).booleanValue();
+
                 for (String colorCode : colorCodes) {
                     Color baseColor = Color.decode(colorCode);
                     colors.add(darken(baseColor));
@@ -311,6 +315,8 @@ public final class TerraTheme extends Th
 
     /**
      * Sets the theme's font.
+     *
+     * @param font the font
      */
     @Override
     public void setFont(Font font) {
@@ -381,7 +387,7 @@ public final class TerraTheme extends Th
     }
 
     /**
-     * Gets the total number of Colors
+     * Gets the total number of Colors (including derived colors if any)
      *
      * @return the number
      */
@@ -391,6 +397,18 @@ public final class TerraTheme extends Th
     }
 
     /**
+     * Tell if the theme is dark.<br/> Usually this means that (if true) any
+     * color will be transformed in the opposite way (brightening instead of
+     * darkening, and darkening instead of brightening).
+     *
+     * @return true if dark, false otherwise
+     */
+    @Override
+    public boolean isThemeDark() {
+        return themeDark;
+    }
+
+    /**
      * Gets the image that this theme uses to represent messages of the
      * specified type.
      *
@@ -443,44 +461,25 @@ public final class TerraTheme extends Th
     /**
      * Returns a brighter version of the specified color. Specifically, it
      * increases the brightness (in the HSB color model) by the
-     * <tt>colorMultiplier</tt> factor already set.
+     * <tt>colorMultiplier</tt> factor and <tt>themeDark</tt> flag already set.
      */
     public static Color brighten(Color color) {
-        return adjustBrightness(color, colorMultiplier);
+        if (themeDark == false) {
+            return ColorUtilities.adjustBrightness(color, colorMultiplier);
+        }
+        return ColorUtilities.adjustBrightness(color, (colorMultiplier * -1.0f));
     }
 
     /**
      * Returns a darker version of the specified color. Specifically, it
      * decreases the brightness (in the HSB color model) by the
-     * <tt>colorMultiplier</tt> factor already set.
+     * <tt>colorMultiplier</tt> factor and <tt>themeDark</tt> flag already set.
      */
     public static Color darken(Color color) {
-        return adjustBrightness(color, (colorMultiplier * -1.0f));
-    }
-
-    /**
-     * Returns a brighter version of the specified color. Specifically, it
-     * increases the brightness (in the HSB color model) by the given
-     * <tt>adjustment</tt> factor (usually in the range ]0 .. 1[).
-     */
-    public static Color brighten(Color color, float adjustment) {
-        return adjustBrightness(color, adjustment);
-    }
-
-    /**
-     * Returns a darker version of the specified color. Specifically, it
-     * decreases the brightness (in the HSB color model) by the given
-     * <tt>adjustment</tt> factor (usually in the range ]0 .. 1[).
-     */
-    public static Color darken(Color color, float adjustment) {
-        return adjustBrightness(color, (adjustment * -1.0f));
-    }
-
-    private static Color adjustBrightness(Color color, float adjustment) {
-        float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null);
-        hsb[2] = Math.min(Math.max(hsb[2] + adjustment, 0f), 1f);
-        int rgb = Color.HSBtoRGB(hsb[0], hsb[1], hsb[2]);
-        return new Color((color.getAlpha() << 24) | (rgb & 0xffffff), true);
+        if (themeDark == false) {
+            return ColorUtilities.adjustBrightness(color, (colorMultiplier * -1.0f));
+        }
+        return ColorUtilities.adjustBrightness(color, colorMultiplier);
     }
 
 }

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=1536737&r1=1536736&r2=1536737&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Theme.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Theme.java Tue Oct 29 14:40:26 2013
@@ -103,15 +103,42 @@ public abstract class Theme {
         return componentSkinMap.get(componentClass);
     }
 
+    /**
+     * Gets the theme's font.
+     */
     public abstract Font getFont();
 
+    /**
+     * Sets the theme's font.
+     *
+     * @param font the font
+     */
     public abstract void setFont(Font font);
 
+    /**
+     * Gets the number of Palette Colors
+     *
+     * @return the number
+     */
     public abstract int getNumberOfPaletteColors();
 
+    /**
+     * Gets the total number of Colors (including derived colors if any)
+     *
+     * @return the number
+     */
     public abstract int getNumberOfColors();
 
     /**
+     * Tell if the theme is dark.<br/> Usually this means that (if true) any
+     * color will be transformed in the opposite way (brightening instead of
+     * darkening, and darkening instead of brightening).
+     *
+     * @return true if dark, false otherwise
+     */
+    public abstract boolean isThemeDark();
+
+    /**
      * Returns the skin class responsible for skinning the specified component
      * class.
      *