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/09/29 22:04:37 UTC

svn commit: r820077 - in /incubator/pivot/trunk: demos/src/org/apache/pivot/demos/scripting/ tutorials/src/org/apache/pivot/tutorials/ tutorials/www/

Author: gbrown
Date: Tue Sep 29 20:04:37 2009
New Revision: 820077

URL: http://svn.apache.org/viewvc?rev=820077&view=rev
Log:
Add a "Hello JavaScript!" example to the tutorial.

Added:
    incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/HelloJavaScript.java
    incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/hello_javascript.wtkx
Modified:
    incubator/pivot/trunk/demos/src/org/apache/pivot/demos/scripting/scripting_demo.wtkx
    incubator/pivot/trunk/tutorials/www/hello_wtkx.template.html

Modified: incubator/pivot/trunk/demos/src/org/apache/pivot/demos/scripting/scripting_demo.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/demos/src/org/apache/pivot/demos/scripting/scripting_demo.wtkx?rev=820077&r1=820076&r2=820077&view=diff
==============================================================================
Binary files - no diff available.

Added: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/HelloJavaScript.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/HelloJavaScript.java?rev=820077&view=auto
==============================================================================
--- incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/HelloJavaScript.java (added)
+++ incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/HelloJavaScript.java Tue Sep 29 20:04:37 2009
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ */
+package org.apache.pivot.tutorials;
+
+import org.apache.pivot.collections.Map;
+import org.apache.pivot.wtk.Application;
+import org.apache.pivot.wtk.DesktopApplicationContext;
+import org.apache.pivot.wtk.Display;
+import org.apache.pivot.wtk.Window;
+import org.apache.pivot.wtkx.WTKXSerializer;
+
+public class HelloJavaScript implements Application {
+    private Window window = null;
+
+    @Override
+    public void startup(Display display, Map<String, String> properties)
+        throws Exception {
+        WTKXSerializer wtkxSerializer = new WTKXSerializer();
+        window = (Window)wtkxSerializer.readObject(this, "hello_javascript.wtkx");
+        window.open(display);
+    }
+
+    @Override
+    public boolean shutdown(boolean optional) {
+        if (window != null) {
+            window.close();
+        }
+
+        return false;
+    }
+
+    @Override
+    public void suspend() {
+    }
+
+    @Override
+    public void resume() {
+    }
+
+    public static void main(String[] args) {
+        DesktopApplicationContext.main(HelloJavaScript.class, args);
+    }
+}

Added: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/hello_javascript.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/hello_javascript.wtkx?rev=820077&view=auto
==============================================================================
--- incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/hello_javascript.wtkx (added)
+++ incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/hello_javascript.wtkx Tue Sep 29 20:04:37 2009
@@ -0,0 +1,40 @@
+<?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.
+-->
+
+<Window title="Hello JavaScript!" maximized="true"
+    xmlns:wtkx="http://pivot.apache.org/wtkx"
+    xmlns="org.apache.pivot.wtk">
+    <windowStateListeners>
+        <wtkx:script>
+        <![CDATA[
+        importPackage(org.apache.pivot.wtk);
+
+        function windowOpened(window) {
+            var label = new Label();
+            label.setText("Hello JavaScript!");
+            label.getStyles().put("font", "Arial BOLD 24");
+            label.getStyles().put("color", "#ff0000");
+            label.getStyles().put("horizontalAlignment", HorizontalAlignment.CENTER);
+            label.getStyles().put("verticalAlignment", VerticalAlignment.CENTER);
+
+            window.setContent(label);
+        }
+        ]]>
+        </wtkx:script>
+    </windowStateListeners>
+</Window>

Modified: incubator/pivot/trunk/tutorials/www/hello_wtkx.template.html
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/www/hello_wtkx.template.html?rev=820077&r1=820076&r2=820077&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/www/hello_wtkx.template.html (original)
+++ incubator/pivot/trunk/tutorials/www/hello_wtkx.template.html Tue Sep 29 20:04:37 2009
@@ -104,7 +104,48 @@
 &lt;/Window&gt;
 </pre>
 
-<p>Most Pivot applications will be constructed this way, by declaring the structure of the UI in WTKX rather than in Java. However, event handlers, which allow an application to respond to user input, are often defined in Java (though they can also be defined within script blocks in the WTKX file). Event handlers are discussed in more detail in later sections.</p>
+<p>Most Pivot applications will be constructed this way, declaring the structure of the UI in WTKX rather than creating it programmatically in code. However, event handlers, which allow an application to respond to user input, are always defined in code (either Java or a compatible JVM scripting language). For example, the following WTKX produces output very similar to the previous two versions, using a combination of WTKX and JavaScript:</p>
+
+<pre class="brush:xml">
+&lt;Window title="Hello JavaScript!" maximized="true"
+    xmlns:wtkx="http://pivot.apache.org/wtkx"
+    xmlns="org.apache.pivot.wtk"&gt;
+    &lt;windowStateListeners&gt;
+        &lt;wtkx:script&gt;
+        &lt;![CDATA[
+        importPackage(org.apache.pivot.wtk);
+
+        function windowOpened(window) {
+            var label = new Label();
+            label.setText("Hello JavaScript!");
+            label.getStyles().put("font", "Arial BOLD 24");
+            label.getStyles().put("color", "#ff0000");
+            label.getStyles().put("horizontalAlignment", HorizontalAlignment.CENTER);
+            label.getStyles().put("verticalAlignment", VerticalAlignment.CENTER);
+
+            window.setContent(label);
+        }
+        ]]&gt;
+        &lt;/wtkx:script&gt;
+    &lt;/windowStateListeners&gt;
+&lt;/Window&gt;
+</pre>
+
+<p>The actual output is shown below:</p>
+
+<script>
+var attributes = {code:"org.apache.pivot.wtk.BrowserApplicationContext$HostApplet",
+    archive:"lib/@project_name@-core-@version@.jar,lib/@project_name@-wtk-@version@.jar,lib/@project_name@-wtk-@version@.terra.jar,lib/@project_name@-tutorials-@version@.jar",
+    width:240,
+    height:80
+};
+var parameters = {application_class_name:"org.apache.pivot.tutorials.HelloJavaScript",
+    codebase_lookup:false
+};
+deployJava.writeAppletTag(attributes, parameters);
+</script>
+
+<p>Though most examples in this tutorial implement event handlers in Java, some use script code when it is more concise or convenient to do so. Scripting is discussed in more detail in the <a href="scripting.html">Scripting</a> section.</p>
 
 <p>Next: <a href="component_and_container.html">Component & Container</a></p>
 </body>