Author: rwhitcomb
Date: Tue Feb  9 22:51:04 2016
New Revision: 1729493

URL: http://svn.apache.org/viewvc?rev=1729493&view=rev
Log:
Further refinement of the DataBindingTest program:  implement the "store" via a 
new button
in the GUI, and update the "context" display of the values after the store 
operation.

Modified:
    pivot/trunk/tests/src/org/apache/pivot/tests/DataBindingTest.java
    pivot/trunk/tests/src/org/apache/pivot/tests/data_binding_test.bxml

Modified: pivot/trunk/tests/src/org/apache/pivot/tests/DataBindingTest.java
URL: 
http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/DataBindingTest.java?rev=1729493&r1=1729492&r2=1729493&view=diff
==============================================================================
--- pivot/trunk/tests/src/org/apache/pivot/tests/DataBindingTest.java (original)
+++ pivot/trunk/tests/src/org/apache/pivot/tests/DataBindingTest.java Tue Feb  
9 22:51:04 2016
@@ -16,6 +16,7 @@
  */
 package org.apache.pivot.tests;
 
+import java.awt.Color;
 import org.apache.pivot.beans.BXMLSerializer;
 import org.apache.pivot.collections.HashMap;
 import org.apache.pivot.collections.List;
@@ -24,6 +25,7 @@ import org.apache.pivot.json.JSON;
 import org.apache.pivot.json.JSONSerializer;
 import org.apache.pivot.wtk.Application;
 import org.apache.pivot.wtk.Button;
+import org.apache.pivot.wtk.ButtonPressListener;
 import org.apache.pivot.wtk.DesktopApplicationContext;
 import org.apache.pivot.wtk.Display;
 import org.apache.pivot.wtk.Label;
@@ -88,6 +90,22 @@ public class DataBindingTest extends App
     }
 
     private Window window = null;
+    private HashMap<String, Object> context = new HashMap<>();
+    private int currentColorIndex = -1;
+
+    private static Color[] labelColors = {
+        Color.RED,
+        Color.decode("#FFA500"),
+        Color.decode("#FFD700"),
+        Color.GREEN,
+        Color.BLUE,
+        Color.decode("#4B0082"),
+        Color.decode("#EE82EE")
+    };
+    private Color getNextColor() {
+        currentColorIndex = (currentColorIndex + 1) % labelColors.length;
+        return labelColors[currentColorIndex];
+    }
 
     @Override
     public void startup(Display display, Map<String, String> properties) 
throws Exception {
@@ -95,18 +113,29 @@ public class DataBindingTest extends App
         window = (Window) bxmlSerializer.readObject(DataBindingTest.class, 
"data_binding_test.bxml");
         window.open(display);
 
-        HashMap<String, Object> context = new HashMap<>();
         context.put("id1", "1");
         context.put("id2", "2");
         context.put("id3", "3");
 
         window.getContent().load(context);
 
-        context = new HashMap<>();
-        window.getContent().store(context);
-
-        Label textLabel = 
(Label)(bxmlSerializer.getNamespace().get("bindingDataText"));
+        final Label textLabel = 
(Label)(bxmlSerializer.getNamespace().get("bindingDataText"));
         textLabel.setText(JSONSerializer.toString(context));
+
+        Button storeButton = 
(Button)(bxmlSerializer.getNamespace().get("storeButton"));
+        storeButton.getButtonPressListeners().add(new ButtonPressListener() {
+            @Override
+            public void buttonPressed(Button button) {
+                window.getContent().store(context);
+                try {
+                    textLabel.setText(JSONSerializer.toString(context));
+                    textLabel.getStyles().put("color", getNextColor());
+                } catch (Exception ex) {
+                    throw new RuntimeException(ex);
+                }
+            }
+        });
+
     }
 
     @Override

Modified: pivot/trunk/tests/src/org/apache/pivot/tests/data_binding_test.bxml
URL: 
http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/data_binding_test.bxml?rev=1729493&r1=1729492&r2=1729493&view=diff
==============================================================================
--- pivot/trunk/tests/src/org/apache/pivot/tests/data_binding_test.bxml 
(original)
+++ pivot/trunk/tests/src/org/apache/pivot/tests/data_binding_test.bxml Tue Feb 
 9 22:51:04 2016
@@ -45,8 +45,8 @@ limitations under the License.
             </ScrollPane>
         </Border>
 
-        <Separator heading="This is the 'selected item' binding data for each 
component:"/>
-        <Label bxml:id="bindingDataText"/>
+        <Separator heading="This is the current 'selected item' binding data 
for each component:"/>
+        <Label bxml:id="bindingDataText" styles="{font:'Monospaced Bold'}"/>
 
         <Separator heading="A ListView with selected key 'id1':"/>
         <ListView listData="$list" selectedItemKey="id1">
@@ -81,6 +81,11 @@ limitations under the License.
             </selectedItemBindMapping>
         </Spinner>
 
+        <Separator heading="Press 'Store' to test the other half of data 
binding."/>
+        <BoxPane styles="{horizontalAlignment:'center'}">
+            <PushButton bxml:id="storeButton" buttonData="Store"/>
+        </BoxPane>
+
         <Separator/>
         <Border styles="{padding:6,backgroundColor:'#F0E68C'}">
             <BoxPane orientation="horizontal">
@@ -88,5 +93,6 @@ limitations under the License.
                 <HyperlinkButton uri="http://www.quotes.net"/>
             </BoxPane>
         </Border>
+
     </BoxPane>
 </Window>


Reply via email to