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/06/16 15:04:52 UTC

svn commit: r785192 - in /incubator/pivot/trunk: tutorials/src/org/apache/pivot/tutorials/ wtk/ wtk/lib/ wtk/src/org/apache/pivot/wtk/ wtk/src/org/apache/pivot/wtkx/ wtk/test/org/apache/pivot/wtk/test/

Author: gbrown
Date: Tue Jun 16 13:04:52 2009
New Revision: 785192

URL: http://svn.apache.org/viewvc?rev=785192&view=rev
Log:
Add wtkx:define tag for instantiating objects outside the object hierarchy; remove StAX JARs.
 

Added:
    incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/script_application_test.frame.wtkx
Removed:
    incubator/pivot/trunk/wtk/lib/stax-1.2.0.jar
    incubator/pivot/trunk/wtk/lib/stax-api-1.0.1.jar
Modified:
    incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/kitchen_sink.wtkx
    incubator/pivot/trunk/wtk/.classpath
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ScriptApplication.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java
    incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/script_application_test.wtkx

Modified: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/kitchen_sink.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/kitchen_sink.wtkx?rev=785192&r1=785191&r2=785192&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/kitchen_sink.wtkx (original)
+++ incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/kitchen_sink.wtkx Tue Jun 16 13:04:52 2009
@@ -16,9 +16,8 @@
 limitations under the License.
 -->
 
-<Window title="Pivot Demo"
-    maximized="true"
-    xmlns:wtkx="http://incubator.apache.org/pivot/wtkx/1.1"
+<Window title="Pivot Demo" maximized="true"
+    xmlns:wtkx="http://pivot.apache.org/wtkx"
     xmlns:effects="org.apache.pivot.wtk.effects"
     xmlns="org.apache.pivot.wtk">
     <content>

Modified: incubator/pivot/trunk/wtk/.classpath
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/.classpath?rev=785192&r1=785191&r2=785192&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/.classpath (original)
+++ incubator/pivot/trunk/wtk/.classpath Tue Jun 16 13:04:52 2009
@@ -4,7 +4,5 @@
 	<classpathentry kind="src" path="test"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
 	<classpathentry combineaccessrules="false" kind="src" path="/core"/>
-	<classpathentry kind="lib" path="lib/stax-1.2.0.jar"/>
-	<classpathentry kind="lib" path="lib/stax-api-1.0.1.jar"/>
 	<classpathentry kind="output" path="bin"/>
 </classpath>

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ScriptApplication.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ScriptApplication.java?rev=785192&r1=785191&r2=785192&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ScriptApplication.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ScriptApplication.java Tue Jun 16 13:04:52 2009
@@ -28,34 +28,25 @@
     private Window window = null;
 
     public static final String SRC_ARGUMENT = "src";
-    public static final String TITLE_ARGUMENT = "title";
-    public static final String WINDOW_PROPERTY = "window";
 
     public void startup(Display display, Map<String, String> properties)
         throws Exception {
-        if (!properties.containsKey(SRC_ARGUMENT)) {
-            throw new IllegalArgumentException(SRC_ARGUMENT + " argument is required.");
-        }
-
-        String src = properties.get(SRC_ARGUMENT);
-        String title = properties.get(TITLE_ARGUMENT);
+        String src = null;
 
         WTKXSerializer wtkxSerializer = new WTKXSerializer();
         for (String property : properties) {
-            if (!property.equals(SRC_ARGUMENT)
-                && !property.equals(TITLE_ARGUMENT)) {
+            if (property.equals(SRC_ARGUMENT)) {
+                src = properties.get(property);
+            } else {
                 wtkxSerializer.put(property, properties.get(property));
             }
         }
 
-        window = new Window();
-        window.setTitle(title);
-        window.setMaximized(true);
-        wtkxSerializer.put(WINDOW_PROPERTY, window);
-
-        Component content = (Component)wtkxSerializer.readObject(src);
-        window.setContent(content);
+        if (src == null) {
+            throw new IllegalArgumentException(SRC_ARGUMENT + " argument is required.");
+        }
 
+        window = (Window)wtkxSerializer.readObject(src);
         window.open(display);
     }
 

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java?rev=785192&r1=785191&r2=785192&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java Tue Jun 16 13:04:52 2009
@@ -59,7 +59,6 @@
 import org.apache.pivot.util.Resources;
 import org.apache.pivot.util.ThreadUtilities;
 
-
 /**
  * Loads an object hierarchy from an XML document.
  *
@@ -143,6 +142,7 @@
 
     private static class Element  {
         public enum Type {
+            DEFINE,
             INSTANCE,
             INCLUDE,
             SCRIPT,
@@ -223,6 +223,10 @@
     public static final String SCRIPT_SRC_ATTRIBUTE = "src";
     public static final String SCRIPT_LANGUAGE_ATTRIBUTE = "language";
 
+    public static final String DEFINE_TAG = "define";
+
+    public static final String ROOT_OBJECT_ID = "root";
+
     public static final String MIME_TYPE = "application/wtkx";
 
     public WTKXSerializer() {
@@ -405,6 +409,13 @@
                                 elementType = Element.Type.INCLUDE;
                             } else if (localName.equals(SCRIPT_TAG)) {
                                 elementType = Element.Type.SCRIPT;
+                            } else if (localName.equals(DEFINE_TAG)) {
+                                if (attributes.getLength() > 0) {
+                                    throw new SerializationException(WTKX_PREFIX + ":" + DEFINE_TAG
+                                        + " cannot have attributes.");
+                                }
+
+                                elementType = Element.Type.DEFINE;
                             } else {
                                 throw new SerializationException(prefix + ":" + localName
                                     + " is not a valid element.");
@@ -433,7 +444,8 @@
                                     throw new SerializationException("Parent element must be a typed object.");
                                 }
 
-                                if (prefix != null) {
+                                if (prefix != null
+                                    && prefix.length() > 0) {
                                     throw new SerializationException("Property elements cannot have a namespace prefix.");
                                 }
 
@@ -595,10 +607,11 @@
                                     }
                                 }
 
-                                // If the parent element is a writable property, set this as its value; it
-                                // will be applied later in the parent's closing tag
+                                // If the parent element is a writable property or a define, set this as its
+                                // value; it will be applied later in the parent's closing tag
                                 if (element.parent != null
-                                    && element.parent.type == Element.Type.WRITABLE_PROPERTY) {
+                                    && (element.parent.type == Element.Type.WRITABLE_PROPERTY
+                                        || element.parent.type == Element.Type.DEFINE)) {
                                     element.parent.value = element.value;
                                 }
 
@@ -640,24 +653,20 @@
                                 String src = null;
                                 String language = null;
                                 for (Attribute attribute : element.attributes) {
-                                    if (attribute.prefix != null) {
-                                        throw new SerializationException(WTKX_PREFIX + ":" + attribute.localName
-                                            + " is not a valid attribute.");
-                                    } else {
-                                        if (attribute.prefix != null) {
-                                            throw new SerializationException(attribute.prefix + ":" +
-                                                attribute.localName + " is not a valid" + " attribute for the "
-                                                + WTKX_PREFIX + ":" + SCRIPT_TAG + " tag.");
-                                        }
+                                    if (attribute.prefix != null
+                                        && attribute.prefix.length() > 0) {
+                                        throw new SerializationException(attribute.prefix + ":" +
+                                            attribute.localName + " is not a valid" + " attribute for the "
+                                            + WTKX_PREFIX + ":" + SCRIPT_TAG + " tag.");
+                                    }
 
-                                        if (attribute.localName.equals(SCRIPT_SRC_ATTRIBUTE)) {
-                                            src = attribute.value;
-                                        } else if (attribute.localName.equals(SCRIPT_LANGUAGE_ATTRIBUTE)) {
-                                            language = attribute.value;
-                                        } else {
-                                            throw new SerializationException(attribute.localName + " is not a valid"
-                                                + " attribute for the " + WTKX_PREFIX + ":" + SCRIPT_TAG + " tag.");
-                                        }
+                                    if (attribute.localName.equals(SCRIPT_SRC_ATTRIBUTE)) {
+                                        src = attribute.value;
+                                    } else if (attribute.localName.equals(SCRIPT_LANGUAGE_ATTRIBUTE)) {
+                                        language = attribute.value;
+                                    } else {
+                                        throw new SerializationException(attribute.localName + " is not a valid"
+                                            + " attribute for the " + WTKX_PREFIX + ":" + SCRIPT_TAG + " tag.");
                                     }
                                 }
 
@@ -802,6 +811,7 @@
                         // otherwise, move up the stack
                         if (element.parent == null) {
                             object = element.value;
+                            namedObjects.put(ROOT_OBJECT_ID, object);
                         } else {
                             element = element.parent;
                         }

Added: incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/script_application_test.frame.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/script_application_test.frame.wtkx?rev=785192&view=auto
==============================================================================
--- incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/script_application_test.frame.wtkx (added)
+++ incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/script_application_test.frame.wtkx Tue Jun 16 13:04:52 2009
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License,
+Version 2.0 (the "License"); you may not use this file except in
+compliance with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+
+<Frame title="Script Application Test Frame" preferredWidth="320" preferredHeight="240"
+    xmlns:wtkx="http://pivot.apache.org/wtkx"
+    xmlns="org.apache.pivot.wtk">
+    <content>
+        <Label text="Sample Frame"
+            styles="{horizontalAlignment:'center', verticalAlignment:'center'}"/>
+    </content>
+</Frame>
+

Modified: incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/script_application_test.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/script_application_test.wtkx?rev=785192&r1=785191&r2=785192&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/script_application_test.wtkx (original)
+++ incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/script_application_test.wtkx Tue Jun 16 13:04:52 2009
@@ -16,14 +16,36 @@
 limitations under the License.
 -->
 
-<FlowPane orientation="vertical"
+<Window title="Script Application Test" maximized="true"
     xmlns:wtkx="http://pivot.apache.org/wtkx"
     xmlns="org.apache.pivot.wtk">
-    <Label wtkx:id="fooLabel"/>
-    <Label wtkx:id="barLabel"/>
+    <wtkx:define>
+        <wtkx:include wtkx:id="testFrame" src="script_application_test.frame.wtkx"/>
+    </wtkx:define>
+
+    <content>
+        <FlowPane orientation="vertical">
+            <Label wtkx:id="fooLabel"/>
+            <Label wtkx:id="barLabel"/>
+            <PushButton buttonData="Click Me">
+                <buttonPressListeners>
+                    <wtkx:script language="javascript">
+                    <![CDATA[
+                    function buttonPressed(button) {
+                        testFrame.open(root);
+                    }
+                    ]]>
+                    </wtkx:script>
+                </buttonPressListeners>
+            </PushButton>
+        </FlowPane>
+    </content>
 
     <wtkx:script language="javascript">
+    <![CDATA[
     fooLabel.setText(foo);
     barLabel.setText(bar);
+    ]]>
     </wtkx:script>
-</FlowPane>
+</Window>
+