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 2009/05/08 20:46:22 UTC

svn commit: r773062 - in /incubator/pivot/trunk: tutorials/src/pivot/tutorials/ tutorials/src/pivot/tutorials/stocktracker/ wtk/src/pivot/wtk/skin/terra/ wtk/src/pivot/wtkx/

Author: gbrown
Date: Fri May  8 18:46:22 2009
New Revision: 773062

URL: http://svn.apache.org/viewvc?rev=773062&view=rev
Log:
Draw rounded rectangles in activity indicator; add another activity indicator to Kitchen Sink demo; add convenience main() method to StockTracker; update Bindable#bind() to reflectively invoke generated bind() overload if available.

Modified:
    incubator/pivot/trunk/tutorials/src/pivot/tutorials/Demo.java
    incubator/pivot/trunk/tutorials/src/pivot/tutorials/meters.wtkx
    incubator/pivot/trunk/tutorials/src/pivot/tutorials/stocktracker/StockTracker.java
    incubator/pivot/trunk/wtk/src/pivot/wtk/skin/terra/TerraActivityIndicatorSkin.java
    incubator/pivot/trunk/wtk/src/pivot/wtkx/Bindable.java
    incubator/pivot/trunk/wtk/src/pivot/wtkx/WTKXSerializer.java

Modified: incubator/pivot/trunk/tutorials/src/pivot/tutorials/Demo.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/pivot/tutorials/Demo.java?rev=773062&r1=773061&r2=773062&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/pivot/tutorials/Demo.java (original)
+++ incubator/pivot/trunk/tutorials/src/pivot/tutorials/Demo.java Fri May  8 18:46:22 2009
@@ -328,6 +328,7 @@
             @Load(name="meters.wtkx") private Component component;
             @Bind(property="component") private ActivityIndicator activityIndicator1;
             @Bind(property="component") private ActivityIndicator activityIndicator2;
+            @Bind(property="component") private ActivityIndicator activityIndicator3;
 
             public Vote previewExpandedChange(Rollup rollup) {
                 if (component == null) {
@@ -346,6 +347,7 @@
                         public void expandedChanged(Rollup rollup) {
                             activityIndicator1.setActive(rollup.isExpanded());
                             activityIndicator2.setActive(rollup.isExpanded());
+                            activityIndicator3.setActive(rollup.isExpanded());
                         }
                     });
 }

Modified: incubator/pivot/trunk/tutorials/src/pivot/tutorials/meters.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/pivot/tutorials/meters.wtkx?rev=773062&r1=773061&r2=773062&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/pivot/tutorials/meters.wtkx (original)
+++ incubator/pivot/trunk/tutorials/src/pivot/tutorials/meters.wtkx Fri May  8 18:46:22 2009
@@ -45,10 +45,14 @@
 
             <FlowPane orientation="vertical" styles="{padding:6, spacing:8}">
                 <Label text="Activity Indicators" styles="{fontBold:true}"/>
-                <ActivityIndicator wtkx:id="activityIndicator1"
-                    preferredWidth="32" preferredHeight="32"/>
-                <ActivityIndicator wtkx:id="activityIndicator2" styles="{color:16}"
-                    preferredWidth="64" preferredHeight="64"/>
+                <FlowPane>
+	                <ActivityIndicator wtkx:id="activityIndicator1"
+	                    preferredWidth="24" preferredHeight="24"/>
+	                <ActivityIndicator wtkx:id="activityIndicator2" styles="{color:'#aa0000'}"
+	                    preferredWidth="48" preferredHeight="48"/>
+					<ActivityIndicator wtkx:id="activityIndicator3" styles="{color:16}"
+					    preferredWidth="96" preferredHeight="96"/>
+                </FlowPane>
             </FlowPane>
         </FlowPane>
     </content>

Modified: incubator/pivot/trunk/tutorials/src/pivot/tutorials/stocktracker/StockTracker.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/pivot/tutorials/stocktracker/StockTracker.java?rev=773062&r1=773061&r2=773062&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/pivot/tutorials/stocktracker/StockTracker.java (original)
+++ incubator/pivot/trunk/tutorials/src/pivot/tutorials/stocktracker/StockTracker.java Fri May  8 18:46:22 2009
@@ -38,6 +38,7 @@
 import pivot.wtk.Component;
 import pivot.wtk.ComponentKeyListener;
 import pivot.wtk.Container;
+import pivot.wtk.DesktopApplicationContext;
 import pivot.wtk.Display;
 import pivot.wtk.Form;
 import pivot.wtk.Keyboard;
@@ -199,7 +200,10 @@
     }
 
     public boolean shutdown(boolean optional) {
-        window.close();
+        if (window != null) {
+            window.close();
+        }
+
         return true;
     }
 
@@ -342,4 +346,8 @@
             refreshDetail();
         }
     }
+
+    public static void main(String[] args) {
+        DesktopApplicationContext.main(StockTracker.class, args);
+    }
 }

Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/skin/terra/TerraActivityIndicatorSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/skin/terra/TerraActivityIndicatorSkin.java?rev=773062&r1=773061&r2=773062&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/skin/terra/TerraActivityIndicatorSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/skin/terra/TerraActivityIndicatorSkin.java Fri May  8 18:46:22 2009
@@ -35,7 +35,7 @@
 
     public TerraActivityIndicatorSkin() {
         TerraTheme theme = (TerraTheme)Theme.getTheme();
-        setColor(theme.getColor(7));
+        setColor(theme.getColor(2));
         backgroundColor = null;
     }
 
@@ -80,7 +80,7 @@
 
             for (int i = 0; i < 12; i++) {
                 graphics.setColor(colors[i]);
-                graphics.fillRect(32, -4, 32, 8);
+                graphics.fillRoundRect(24, -4, 32, 8, 8, 8);
 
                 graphics.rotate(increment);
             }

Modified: incubator/pivot/trunk/wtk/src/pivot/wtkx/Bindable.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtkx/Bindable.java?rev=773062&r1=773061&r2=773062&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtkx/Bindable.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtkx/Bindable.java Fri May  8 18:46:22 2009
@@ -22,6 +22,8 @@
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.net.URL;
 import java.util.Locale;
@@ -29,6 +31,7 @@
 
 import pivot.collections.ArrayList;
 import pivot.collections.HashMap;
+import pivot.collections.Map;
 import pivot.serialization.SerializationException;
 import pivot.util.Resources;
 
@@ -68,154 +71,174 @@
      */
     @BindMethodProcessor.BindMethod
     protected final void bind() throws BindException {
-        // Walk fields and resolve annotations
-        ArrayList<Class<?>> typeHierarchy = new ArrayList<Class<?>>();
-        Class<?> type = getClass();
-        while (type != Bindable.class) {
-            typeHierarchy.add(type);
-            type = type.getSuperclass();
+        Method bindOverload = null;
+        try {
+            bindOverload = getClass().getDeclaredMethod("__bind__", new Class<?>[] {Map.class});
+        } catch(NoSuchMethodException exception) {
+            // No-op
         }
 
-        // Maps field name to the serializer that loaded the property; public
-        // and protected serializers are retained for sub-types, but private
-        // serializers are removed at the end of the block
-        HashMap<String, WTKXSerializer> wtkxSerializers = new HashMap<String, WTKXSerializer>();
-
-        for (int i = typeHierarchy.getLength() - 1; i >= 0; i--) {
-            type = typeHierarchy.get(i);
-            Field[] fields = type.getDeclaredFields();
-
-            ArrayList<String> privateFieldNames = new ArrayList<String>();
-
-            for (int j = 0, n = fields.length; j < n; j++) {
-                Field field = fields[j];
-                String fieldName = field.getName();
-                int fieldModifiers = field.getModifiers();
-
-                Load loadAnnotation = field.getAnnotation(Load.class);
-                if (loadAnnotation != null) {
-                    // Ensure that we can write to the field
-                    if ((fieldModifiers & Modifier.FINAL) > 0) {
-                        throw new BindException(fieldName + " is final.");
-                    }
+        if (bindOverload == null) {
+            // Walk fields and resolve annotations
+            ArrayList<Class<?>> typeHierarchy = new ArrayList<Class<?>>();
+            Class<?> type = getClass();
+            while (type != Bindable.class) {
+                typeHierarchy.add(type);
+                type = type.getSuperclass();
+            }
 
-                    if ((fieldModifiers & Modifier.PUBLIC) == 0) {
-                        try {
-                            field.setAccessible(true);
-                        } catch(SecurityException exception) {
-                            throw new BindException(fieldName + " is not accessible.");
-                        }
-                    }
+            // Maps field name to the serializer that loaded the property; public
+            // and protected serializers are retained for sub-types, but private
+            // serializers are removed at the end of the block
+            HashMap<String, WTKXSerializer> wtkxSerializers = new HashMap<String, WTKXSerializer>();
+
+            for (int i = typeHierarchy.getLength() - 1; i >= 0; i--) {
+                type = typeHierarchy.get(i);
+                Field[] fields = type.getDeclaredFields();
+
+                ArrayList<String> privateFieldNames = new ArrayList<String>();
+
+                for (int j = 0, n = fields.length; j < n; j++) {
+                    Field field = fields[j];
+                    String fieldName = field.getName();
+                    int fieldModifiers = field.getModifiers();
 
-                    assert(!wtkxSerializers.containsKey(fieldName));
+                    Load loadAnnotation = field.getAnnotation(Load.class);
+                    if (loadAnnotation != null) {
+                        // Ensure that we can write to the field
+                        if ((fieldModifiers & Modifier.FINAL) > 0) {
+                            throw new BindException(fieldName + " is final.");
+                        }
 
-                    if ((fieldModifiers & Modifier.PRIVATE) > 0) {
-                        privateFieldNames.add(fieldName);
-                    }
+                        if ((fieldModifiers & Modifier.PUBLIC) == 0) {
+                            try {
+                                field.setAccessible(true);
+                            } catch(SecurityException exception) {
+                                throw new BindException(fieldName + " is not accessible.");
+                            }
+                        }
 
-                    // Get the name of the resource file to use
-                    Resources resources = null;
-                    boolean defaultResources = false;
-
-                    String baseName = loadAnnotation.resources();
-                    if (baseName.equals("\0")) {
-                        baseName = type.getName();
-                        defaultResources = true;
-                    }
+                        assert(!wtkxSerializers.containsKey(fieldName));
 
-                    // Get the resource locale
-                    Locale locale;
-                    String language = loadAnnotation.locale();
-                    if (language.equals("\0")) {
-                        locale = Locale.getDefault();
-                    } else {
-                        locale = new Locale(language);
-                    }
+                        if ((fieldModifiers & Modifier.PRIVATE) > 0) {
+                            privateFieldNames.add(fieldName);
+                        }
 
-                    // Attmpt to load the resources
-                    try {
-                        resources = new Resources(baseName, locale, "UTF8");
-                    } catch(IOException exception) {
-                        throw new BindException(exception);
-                    } catch(SerializationException exception) {
-                        throw new BindException(exception);
-                    } catch(MissingResourceException exception) {
-                        if (!defaultResources) {
-                            throw new BindException(baseName + " not found.");
+                        // Get the name of the resource file to use
+                        Resources resources = null;
+                        boolean defaultResources = false;
+
+                        String baseName = loadAnnotation.resources();
+                        if (baseName.equals("\0")) {
+                            baseName = type.getName();
+                            defaultResources = true;
                         }
-                    }
 
-                    // Deserialize the value
-                    WTKXSerializer wtkxSerializer = new WTKXSerializer(resources);
-                    wtkxSerializers.put(fieldName, wtkxSerializer);
-
-                    URL location = type.getResource(loadAnnotation.name());
-                    Object resource;
-                    try {
-                        resource = wtkxSerializer.readObject(location);
-                    } catch(IOException exception) {
-                        throw new BindException(exception);
-                    } catch (SerializationException exception) {
-                        throw new BindException(exception);
-                    }
+                        // Get the resource locale
+                        Locale locale;
+                        String language = loadAnnotation.locale();
+                        if (language.equals("\0")) {
+                            locale = Locale.getDefault();
+                        } else {
+                            locale = new Locale(language);
+                        }
 
-                    // Set the deserialized value into the field
-                    try {
-                        field.set(this, resource);
-                    } catch (IllegalAccessException exception) {
-                        throw new BindException(exception);
-                    }
-                }
+                        // Attmpt to load the resources
+                        try {
+                            resources = new Resources(baseName, locale, "UTF8");
+                        } catch(IOException exception) {
+                            throw new BindException(exception);
+                        } catch(SerializationException exception) {
+                            throw new BindException(exception);
+                        } catch(MissingResourceException exception) {
+                            if (!defaultResources) {
+                                throw new BindException(baseName + " not found.");
+                            }
+                        }
 
-                Bind bindAnnotation = field.getAnnotation(Bind.class);
-                if (bindAnnotation != null) {
-                    if (loadAnnotation != null) {
-                        throw new BindException("Cannot combine " + Load.class.getName()
-                            + " and " + Bind.class.getName() + " annotations.");
-                    }
+                        // Deserialize the value
+                        WTKXSerializer wtkxSerializer = new WTKXSerializer(resources);
+                        wtkxSerializers.put(fieldName, wtkxSerializer);
 
-                    // Ensure that we can write to the field
-                    if ((fieldModifiers & Modifier.FINAL) > 0) {
-                        throw new BindException(fieldName + " is final.");
-                    }
+                        URL location = type.getResource(loadAnnotation.name());
+                        Object resource;
+                        try {
+                            resource = wtkxSerializer.readObject(location);
+                        } catch(IOException exception) {
+                            throw new BindException(exception);
+                        } catch (SerializationException exception) {
+                            throw new BindException(exception);
+                        }
 
-                    if ((fieldModifiers & Modifier.PUBLIC) == 0) {
+                        // Set the deserialized value into the field
                         try {
-                            field.setAccessible(true);
-                        } catch(SecurityException exception) {
-                            throw new BindException(fieldName + " is not accessible.");
+                            field.set(this, resource);
+                        } catch (IllegalAccessException exception) {
+                            throw new BindException(exception);
                         }
                     }
 
-                    // Bind to the value loaded by the property's serializer
-                    String property = bindAnnotation.property();
-                    WTKXSerializer wtkxSerializer = wtkxSerializers.get(property);
-                    if (wtkxSerializer == null) {
-                        throw new BindException("Property \"" + property + "\" has not been loaded.");
-                    }
+                    Bind bindAnnotation = field.getAnnotation(Bind.class);
+                    if (bindAnnotation != null) {
+                        if (loadAnnotation != null) {
+                            throw new BindException("Cannot combine " + Load.class.getName()
+                                + " and " + Bind.class.getName() + " annotations.");
+                        }
 
-                    String id = bindAnnotation.name();
-                    if (id.equals("\0")) {
-                        id = field.getName();
-                    }
+                        // Ensure that we can write to the field
+                        if ((fieldModifiers & Modifier.FINAL) > 0) {
+                            throw new BindException(fieldName + " is final.");
+                        }
 
-                    Object value = wtkxSerializer.getObjectByName(id);
-                    if (value == null) {
-                        throw new BindException("\"" + id + "\" does not exist.");
-                    }
+                        if ((fieldModifiers & Modifier.PUBLIC) == 0) {
+                            try {
+                                field.setAccessible(true);
+                            } catch(SecurityException exception) {
+                                throw new BindException(fieldName + " is not accessible.");
+                            }
+                        }
+
+                        // Bind to the value loaded by the property's serializer
+                        String property = bindAnnotation.property();
+                        WTKXSerializer wtkxSerializer = wtkxSerializers.get(property);
+                        if (wtkxSerializer == null) {
+                            throw new BindException("Property \"" + property + "\" has not been loaded.");
+                        }
+
+                        String id = bindAnnotation.name();
+                        if (id.equals("\0")) {
+                            id = field.getName();
+                        }
+
+                        Object value = wtkxSerializer.getObjectByName(id);
+                        if (value == null) {
+                            throw new BindException("\"" + id + "\" does not exist.");
+                        }
 
-                    // Set the value into the field
-                    try {
-                        field.set(this, value);
-                    } catch (IllegalAccessException exception) {
-                        throw new BindException(exception);
+                        // Set the value into the field
+                        try {
+                            field.set(this, value);
+                        } catch (IllegalAccessException exception) {
+                            throw new BindException(exception);
+                        }
                     }
                 }
-            }
 
-            // Remove the private field serializers
-            for (String privateFieldName : privateFieldNames) {
-                wtkxSerializers.remove(privateFieldName);
+                // Remove the private field serializers
+                for (String privateFieldName : privateFieldNames) {
+                    wtkxSerializers.remove(privateFieldName);
+                }
+            }
+        } else {
+            // Invoke the bind overload
+            HashMap<String, WTKXSerializer> namedSerializers = new HashMap<String, WTKXSerializer>();
+
+            try {
+                bindOverload.invoke(this, new Object[] {namedSerializers});
+            } catch(IllegalAccessException exception) {
+                throw new BindException(exception);
+            } catch(InvocationTargetException exception) {
+                throw new BindException(exception);
             }
         }
     }

Modified: incubator/pivot/trunk/wtk/src/pivot/wtkx/WTKXSerializer.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtkx/WTKXSerializer.java?rev=773062&r1=773061&r2=773062&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtkx/WTKXSerializer.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtkx/WTKXSerializer.java Fri May  8 18:46:22 2009
@@ -875,7 +875,7 @@
                             resolvedValue = attributeValue.substring(1);
                         } else {
                             if (resources == null) {
-                                throw new IllegalStateException("Resource dictionary is undefined.");
+                                throw new IllegalStateException("Resources is null.");
                             }
 
                             resolvedValue = resources.get(attributeValue.substring(1));