You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by tv...@apache.org on 2009/10/26 15:31:54 UTC

svn commit: r829812 - /incubator/pivot/trunk/tools/src/org/apache/pivot/tools/wtk/ComponentInspectorSkin.java

Author: tvolkert
Date: Mon Oct 26 14:31:53 2009
New Revision: 829812

URL: http://svn.apache.org/viewvc?rev=829812&view=rev
Log:
Added support for float properties in the component inspector tool

Modified:
    incubator/pivot/trunk/tools/src/org/apache/pivot/tools/wtk/ComponentInspectorSkin.java

Modified: incubator/pivot/trunk/tools/src/org/apache/pivot/tools/wtk/ComponentInspectorSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tools/src/org/apache/pivot/tools/wtk/ComponentInspectorSkin.java?rev=829812&r1=829811&r2=829812&view=diff
==============================================================================
--- incubator/pivot/trunk/tools/src/org/apache/pivot/tools/wtk/ComponentInspectorSkin.java (original)
+++ incubator/pivot/trunk/tools/src/org/apache/pivot/tools/wtk/ComponentInspectorSkin.java Mon Oct 26 14:31:53 2009
@@ -47,6 +47,7 @@
 import org.apache.pivot.wtk.TextInput;
 import org.apache.pivot.wtk.skin.ContainerSkin;
 import org.apache.pivot.wtk.text.validation.IntValidator;
+import org.apache.pivot.wtk.text.validation.FloatValidator;
 import org.apache.pivot.wtkx.WTKX;
 import org.apache.pivot.wtkx.WTKXSerializer;
 
@@ -99,6 +100,8 @@
                     updateBooleanControl(propertyName);
                 } else if (propertyType == Integer.TYPE) {
                     updateIntControl(propertyName);
+                } else if (propertyType == Float.TYPE) {
+                    updateFloatControl(propertyName);
                 } else if (propertyType.isEnum()) {
                     updateEnumControl(propertyName);
                 } else if (propertyType == Point.class) {
@@ -222,6 +225,8 @@
             inspectorComponent = addBooleanControl(propertyName, section);
         } else if (propertyType == Integer.TYPE) {
             inspectorComponent = addIntControl(propertyName, section);
+        } else if (propertyType == Float.TYPE) {
+            inspectorComponent = addFloatControl(propertyName, section);
         } else if (propertyType.isEnum()) {
             inspectorComponent = addEnumControl(propertyName, section);
         } else if (propertyType == Point.class) {
@@ -303,6 +308,44 @@
         }
     }
 
+    private Component addFloatControl(final String propertyName, Form.Section section) {
+        float propertyValue = (Float)beanDictionary.get(propertyName);
+
+        TextInput textInput = new TextInput();
+        textInput.setTextSize(10);
+        textInput.setValidator(new FloatValidator());
+        textInput.setText(String.valueOf(propertyValue));
+        section.add(textInput);
+        Form.setLabel(textInput, propertyName);
+
+        textInput.getComponentStateListeners().add(new ComponentStateListener.Adapter() {
+            @Override
+            public void focusedChanged(Component component, Component obverseComponent) {
+                if (!component.isFocused()) {
+                    TextInput textInput = (TextInput)component;
+
+                    try {
+                        beanDictionary.put(propertyName, Float.parseFloat(textInput.getText()));
+                    } catch (Exception exception) {
+                        Object propertyValue = beanDictionary.get(propertyName);
+                        textInput.setText(String.valueOf(propertyValue));
+                    }
+                }
+            }
+        });
+
+        return textInput;
+    }
+
+    private void updateFloatControl(String propertyName) {
+        TextInput textInput = (TextInput)inspectorComponents.get(propertyName);
+
+        if (textInput != null) {
+            float propertyValue = (Float)beanDictionary.get(propertyName);
+            textInput.setText(String.valueOf(propertyValue));
+        }
+    }
+
     @SuppressWarnings("unchecked")
     private Component addEnumControl(final String propertyName, Form.Section section) {
         Class<?> propertyType = beanDictionary.getType(propertyName);