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/01/15 19:04:30 UTC

svn commit: r899736 - in /pivot/trunk: tests/src/org/apache/pivot/tests/ tutorials/src/org/apache/pivot/tutorials/calendars/ tutorials/src/org/apache/pivot/tutorials/explorer/layout/ tutorials/src/org/apache/pivot/tutorials/layout/ tutorials/src/org/ap...

Author: gbrown
Date: Fri Jan 15 18:04:16 2010
New Revision: 899736

URL: http://svn.apache.org/viewvc?rev=899736&view=rev
Log:
Add a "required" attribute to Form fields; add adapters for all attribute listener interfaces; preliminary updates to prepare for form skin enhancements.

Modified:
    pivot/trunk/tests/src/org/apache/pivot/tests/baseline_test.wtkx
    pivot/trunk/tests/src/org/apache/pivot/tests/form_test.wtkx
    pivot/trunk/tutorials/src/org/apache/pivot/tutorials/calendars/calendars.wtkx
    pivot/trunk/tutorials/src/org/apache/pivot/tutorials/explorer/layout/form.wtkx
    pivot/trunk/tutorials/src/org/apache/pivot/tutorials/layout/forms.wtkx
    pivot/trunk/tutorials/src/org/apache/pivot/tutorials/stocktracker/stocktracker.detail.wtkx
    pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraFormSkin.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/AccordionAttributeListener.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/Form.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/FormAttributeListener.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/TabPaneAttributeListener.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/TablePaneAttributeListener.java

Modified: pivot/trunk/tests/src/org/apache/pivot/tests/baseline_test.wtkx
URL: http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/baseline_test.wtkx?rev=899736&r1=899735&r2=899736&view=diff
==============================================================================
--- pivot/trunk/tests/src/org/apache/pivot/tests/baseline_test.wtkx (original)
+++ pivot/trunk/tests/src/org/apache/pivot/tests/baseline_test.wtkx Fri Jan 15 18:04:16 2010
@@ -16,7 +16,7 @@
 limitations under the License.
 -->
 
-<Form styles="{rightAlignLabels:true, fill:true}"
+<Form styles="{fill:true}"
     xmlns:wtkx="http://pivot.apache.org/wtkx"
     xmlns:content="org.apache.pivot.wtk.content"
     xmlns="org.apache.pivot.wtk">

Modified: pivot/trunk/tests/src/org/apache/pivot/tests/form_test.wtkx
URL: http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/form_test.wtkx?rev=899736&r1=899735&r2=899736&view=diff
==============================================================================
--- pivot/trunk/tests/src/org/apache/pivot/tests/form_test.wtkx (original)
+++ pivot/trunk/tests/src/org/apache/pivot/tests/form_test.wtkx Fri Jan 15 18:04:16 2010
@@ -16,7 +16,7 @@
 limitations under the License.
 -->
 
-<Form styles="{rightAlignLabels:true, fill:true}"
+<Form styles="{fill:true}"
     xmlns:wtkx="http://pivot.apache.org/wtkx"
     xmlns:effects="org.apache.pivot.wtk.effects"
     xmlns="org.apache.pivot.wtk">

Modified: pivot/trunk/tutorials/src/org/apache/pivot/tutorials/calendars/calendars.wtkx
URL: http://svn.apache.org/viewvc/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/calendars/calendars.wtkx?rev=899736&r1=899735&r2=899736&view=diff
==============================================================================
--- pivot/trunk/tutorials/src/org/apache/pivot/tutorials/calendars/calendars.wtkx (original)
+++ pivot/trunk/tutorials/src/org/apache/pivot/tutorials/calendars/calendars.wtkx Fri Jan 15 18:04:16 2010
@@ -22,7 +22,7 @@
     <content>
         <Border styles="{padding:8}">
             <content>
-                <Form styles="{rightAlignLabels:true}">
+                <Form>
                     <sections>
                         <Form.Section>
                             <Border Form.label="Calendar" styles="{color:10}">

Modified: pivot/trunk/tutorials/src/org/apache/pivot/tutorials/explorer/layout/form.wtkx
URL: http://svn.apache.org/viewvc/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/explorer/layout/form.wtkx?rev=899736&r1=899735&r2=899736&view=diff
==============================================================================
--- pivot/trunk/tutorials/src/org/apache/pivot/tutorials/explorer/layout/form.wtkx (original)
+++ pivot/trunk/tutorials/src/org/apache/pivot/tutorials/explorer/layout/form.wtkx Fri Jan 15 18:04:16 2010
@@ -16,8 +16,7 @@
 limitations under the License.
 -->
 
-<Form styles="{rightAlignLabels:true}"
-    xmlns:wtkx="http://pivot.apache.org/wtkx"
+<Form xmlns:wtkx="http://pivot.apache.org/wtkx"
     xmlns="org.apache.pivot.wtk">
     <sections>
         <Form.Section heading="Personal Information">

Modified: pivot/trunk/tutorials/src/org/apache/pivot/tutorials/layout/forms.wtkx
URL: http://svn.apache.org/viewvc/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/layout/forms.wtkx?rev=899736&r1=899735&r2=899736&view=diff
==============================================================================
--- pivot/trunk/tutorials/src/org/apache/pivot/tutorials/layout/forms.wtkx (original)
+++ pivot/trunk/tutorials/src/org/apache/pivot/tutorials/layout/forms.wtkx Fri Jan 15 18:04:16 2010
@@ -28,7 +28,7 @@
                     </columns>
                     <rows>
                         <TablePane.Row height="1*">
-                            <Form styles="{rightAlignLabels:true}">
+                            <Form>
                                 <sections>
                                     <Form.Section>
                                         <BoxPane wtkx:id="nameBoxPane" Form.label="Name">

Modified: pivot/trunk/tutorials/src/org/apache/pivot/tutorials/stocktracker/stocktracker.detail.wtkx
URL: http://svn.apache.org/viewvc/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/stocktracker/stocktracker.detail.wtkx?rev=899736&r1=899735&r2=899736&view=diff
==============================================================================
--- pivot/trunk/tutorials/src/org/apache/pivot/tutorials/stocktracker/stocktracker.detail.wtkx (original)
+++ pivot/trunk/tutorials/src/org/apache/pivot/tutorials/stocktracker/stocktracker.detail.wtkx Fri Jan 15 18:04:16 2010
@@ -21,7 +21,7 @@
     xmlns="org.apache.pivot.wtk">
     <Label textKey="companyName" styles="{font:{size:12, bold:true}}"/>
     <Separator/>
-    <Form styles="{rightAlignLabels:true, fill:true}">
+    <Form styles="{fill:true}">
         <sections>
             <Form.Section>
                 <Label Form.label="%value" textKey="value"

Modified: pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraFormSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraFormSkin.java?rev=899736&r1=899735&r2=899736&view=diff
==============================================================================
--- pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraFormSkin.java (original)
+++ pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraFormSkin.java Fri Jan 15 18:04:16 2010
@@ -40,8 +40,6 @@
     private ArrayList<ArrayList<Label>> labels = new ArrayList<ArrayList<Label>>();
     private ArrayList<ArrayList<ImageView>> flagImageViews = new ArrayList<ArrayList<ImageView>>();
 
-    private boolean rightAlignLabels = false;
-
     // Make the field fill the width of the form
     private boolean fill = false;
     private int horizontalSpacing = 6;
@@ -397,7 +395,7 @@
                     int rowHeight = Math.max(baseline + Math.max(labelDescent, fieldDescent), FLAG_IMAGE_SIZE);
 
                     // Align the label and field to baseline
-                    int labelX = rightAlignLabels ? maximumLabelWidth - label.getWidth() : 0;
+                    int labelX = maximumLabelWidth - label.getWidth();
                     int labelY = rowY + (baseline - labelAscent);
                     label.setLocation(labelX, labelY);
 
@@ -421,15 +419,6 @@
         }
     }
 
-    public boolean getRightAlignLabels() {
-        return rightAlignLabels;
-    }
-
-    public void setRightAlignLabels(boolean rightAlignLabels) {
-        this.rightAlignLabels = rightAlignLabels;
-        invalidateComponent();
-    }
-
     public boolean getFill() {
         return fill;
     }
@@ -565,6 +554,11 @@
     }
 
     @Override
+    public void requiredChanged(Form form, Component field) {
+        // TODO
+    }
+
+    @Override
     public void flagChanged(Form form, Component field, Form.Flag previousFlag) {
         Form.Section section = Form.getSection(field);
         updateFieldFlag(section, section.indexOf(field));

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/AccordionAttributeListener.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/AccordionAttributeListener.java?rev=899736&r1=899735&r2=899736&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/AccordionAttributeListener.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/AccordionAttributeListener.java Fri Jan 15 18:04:16 2010
@@ -23,6 +23,19 @@
  */
 public interface AccordionAttributeListener {
     /**
+     * Accordion attribute listener adapter.
+     */
+    public static class Adapter implements AccordionAttributeListener {
+        @Override
+        public void labelChanged(Accordion accordion, Component component, String previousLabel) {
+        }
+
+        @Override
+        public void iconChanged(Accordion accordion, Component component, Image previousIcon) {
+        }
+    }
+
+    /**
      * Called when a panel's label attribute has changed.
      *
      * @param accordion

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Form.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Form.java?rev=899736&r1=899735&r2=899736&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Form.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Form.java Fri Jan 15 18:04:16 2010
@@ -325,6 +325,7 @@
     private static class Attributes {
         public final Section section;
         public String label = null;
+        public boolean required = false;
         public Flag flag = null;
 
         public Attributes(Section section) {
@@ -380,6 +381,13 @@
         }
 
         @Override
+        public void requiredChanged(Form form, Component field) {
+            for (FormAttributeListener listener : this) {
+                listener.requiredChanged(form, field);
+            }
+        }
+
+        @Override
         public void flagChanged(Form form, Component component, Form.Flag previousFlag) {
             for (FormAttributeListener listener : this) {
                 listener.flagChanged(form, component, previousFlag);
@@ -500,6 +508,27 @@
         }
     }
 
+    public static boolean isRequired(Component component) {
+        Attributes attributes = (Attributes)component.getAttributes();
+        return (attributes == null) ? false : attributes.required;
+    }
+
+    public static void setRequired(Component component, boolean required) {
+        Attributes attributes = (Attributes)component.getAttributes();
+        if (attributes == null) {
+            throw new IllegalStateException();
+        }
+
+        if (attributes.required != required) {
+            attributes.required = required;
+
+            Form form = (Form)component.getParent();
+            if (form != null) {
+                form.formAttributeListeners.requiredChanged(form, component);
+            }
+        }
+    }
+
     public static Flag getFlag(Component component) {
         Attributes attributes = (Attributes)component.getAttributes();
         return (attributes == null) ? null : attributes.flag;

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/FormAttributeListener.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/FormAttributeListener.java?rev=899736&r1=899735&r2=899736&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/FormAttributeListener.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/FormAttributeListener.java Fri Jan 15 18:04:16 2010
@@ -21,13 +21,38 @@
  */
 public interface FormAttributeListener {
     /**
-     * Called when a fields's name attribute has changed.
+     * Form attribute listener adapter.
+     */
+    public class Adapter implements FormAttributeListener {
+        @Override
+        public void labelChanged(Form form, Component field, String previousLabel) {
+        }
+
+        @Override
+        public void requiredChanged(Form form, Component field) {
+        }
+
+        @Override
+        public void flagChanged(Form form, Component field, Form.Flag previousFlag) {
+        }
+    }
+
+    /**
+     * Called when a fields's label attribute has changed.
+     *
+     * @param form
+     * @param field
+     * @param previousLabel
+     */
+    public void labelChanged(Form form, Component field, String previousLabel);
+
+    /**
+     * Called when a fields's required attribute has changed.
      *
      * @param form
      * @param field
-     * @param previousName
      */
-    public void labelChanged(Form form, Component field, String previousName);
+    public void requiredChanged(Form form, Component field);
 
     /**
      * Called when a field's flag attribute has changed.

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/TabPaneAttributeListener.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/TabPaneAttributeListener.java?rev=899736&r1=899735&r2=899736&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/TabPaneAttributeListener.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/TabPaneAttributeListener.java Fri Jan 15 18:04:16 2010
@@ -23,7 +23,24 @@
  */
 public interface TabPaneAttributeListener {
     /**
-     * Called when a tab's name attribute has changed.
+     * Tab pane attribute listener adapter.
+     */
+    public static class Adapter implements TabPaneAttributeListener {
+        @Override
+        public void labelChanged(TabPane tabPane, Component component, String previousLabel) {
+        }
+
+        @Override
+        public void iconChanged(TabPane tabPane, Component component, Image previousIcon) {
+        }
+
+        @Override
+        public void closeableChanged(TabPane tabPane, Component component) {
+        }
+    }
+
+    /**
+     * Called when a tab's label attribute has changed.
      *
      * @param tabPane
      * @param component

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/TablePaneAttributeListener.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/TablePaneAttributeListener.java?rev=899736&r1=899735&r2=899736&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/TablePaneAttributeListener.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/TablePaneAttributeListener.java Fri Jan 15 18:04:16 2010
@@ -21,6 +21,20 @@
  */
 public interface TablePaneAttributeListener {
     /**
+     * Table pane attribute listener adapter.
+     */
+    public static class Adapter implements TablePaneAttributeListener {
+        @Override
+        public void rowSpanChanged(TablePane tablePane, Component component,
+            int previousRowSpan) {
+        }
+
+        @Override
+        public void columnSpanChanged(TablePane tablePane, Component component,
+            int previousColumnSpan) {
+        }
+    }
+    /**
      * Called when a component's row span attribute has changed.
      *
      * @param tablePane