You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2010/07/15 16:05:01 UTC
svn commit: r964439 -
/pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java
Author: gbrown
Date: Thu Jul 15 14:05:01 2010
New Revision: 964439
URL: http://svn.apache.org/viewvc?rev=964439&view=rev
Log:
Apply typed styles in Component#setSkin().
Modified:
pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java?rev=964439&r1=964438&r2=964439&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java Thu Jul 15 14:05:01 2010
@@ -642,7 +642,7 @@ public abstract class Component implemen
// The component's automation ID
private String automationID;
- // Event listener lists.
+ // Event listener lists
private ComponentListenerList componentListeners = new ComponentListenerList();
private ComponentStateListenerList componentStateListeners = new ComponentStateListenerList();
private ComponentDecoratorListenerList componentDecoratorListeners = new ComponentDecoratorListenerList();
@@ -653,9 +653,17 @@ public abstract class Component implemen
private ComponentKeyListenerList componentKeyListeners = new ComponentKeyListenerList();
private ComponentDataListenerList componentDataListeners = new ComponentDataListenerList();
+ /**
+ * The extension used by style definition files.
+ */
+ public static final String STYLES_EXTENSION = "styles";
+
// The component that currently has the focus
private static Component focusedComponent = null;
+ // Map of typed styles
+ private static HashMap<Class<?>, Map<String, ?>> typedStyles = new HashMap<Class<?>, Map<String,?>>();
+
// Class event listeners
private static ComponentClassListenerList componentClassListeners = new ComponentClassListenerList();
@@ -710,6 +718,7 @@ public abstract class Component implemen
* @param skin
* The new skin.
*/
+ @SuppressWarnings("unchecked")
protected void setSkin(Skin skin) {
if (skin == null) {
throw new IllegalArgumentException("skin is null.");
@@ -723,6 +732,41 @@ public abstract class Component implemen
styles = new BeanAdapter(skin);
skin.install(this);
+ // Apply any defined type styles
+ Class<?> type = getClass();
+
+ while (type != Object.class) {
+ if (!typedStyles.containsKey(type)) {
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ URL location = classLoader.getResource(type.getName().replace(".", "/") + "."
+ + STYLES_EXTENSION);
+
+ if (location == null) {
+ // This type does not have any styles defined
+ typedStyles.put(type, null);
+ } else {
+ // Load the styles
+ JSONSerializer jsonSerializer = new JSONSerializer();
+
+ try {
+ typedStyles.put(type, (Map<String, ?>)jsonSerializer.readObject(location.openStream()));
+ } catch (IOException exception) {
+ System.err.println(exception);
+ } catch (SerializationException exception) {
+ System.err.println(exception);
+ }
+ }
+ }
+
+ Map<String, ?> styles = typedStyles.get(type);
+
+ if (styles != null) {
+ setStyles(styles);
+ }
+
+ type = type.getSuperclass();
+ }
+
invalidate();
repaint();
}