Skip to content

Commit

Permalink
PIVOT-689, add defaultBackgroundColor and defaultForegroundColor in T…
Browse files Browse the repository at this point in the history
…erra 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.


git-svn-id: https://svn.apache.org/repos/asf/pivot/trunk@1619713 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Sandro Martini committed Aug 22, 2014
1 parent c4a6946 commit 612ef3e
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 11 deletions.
5 changes: 4 additions & 1 deletion tests/src/org/apache/pivot/tests/TerraTheme_test.json
Expand Up @@ -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"
}
42 changes: 42 additions & 0 deletions wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTheme.java
Expand Up @@ -102,6 +102,9 @@ public final class TerraTheme extends Theme {
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";

Expand Down Expand Up @@ -290,6 +293,25 @@ private void load(URL location) {
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();
}
Expand Down Expand Up @@ -503,6 +525,26 @@ public void setSmallMessageIcon(MessageType messageType, Image smallMessageIcon)
smallMessageIcons.put(messageType, smallMessageIcon);
}

/**
* 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
Expand Down
24 changes: 24 additions & 0 deletions wtk/src/org/apache/pivot/wtk/Theme.java
Expand Up @@ -214,6 +214,30 @@ public void set(Class<? extends Component> componentClass, Class<? extends Skin>
componentSkinMap.put(componentClass, skinClass);
}

/**
* 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}.
Expand Down
14 changes: 4 additions & 10 deletions wtk/src/org/apache/pivot/wtk/skin/ComponentSkin.java
Expand Up @@ -437,27 +437,21 @@ protected boolean themeIsFlat() {
}

/**
* 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();
}

}

0 comments on commit 612ef3e

Please sign in to comment.