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/12/06 02:25:45 UTC

svn commit: r887626 - in /incubator/pivot/trunk/tutorials/www: drawing.html drawing.xml expanders.html expanders.xml

Author: gbrown
Date: Sun Dec  6 01:25:44 2009
New Revision: 887626

URL: http://svn.apache.org/viewvc?rev=887626&view=rev
Log:
Continue migrating tutorial content to XML.

Removed:
    incubator/pivot/trunk/tutorials/www/drawing.html
    incubator/pivot/trunk/tutorials/www/expanders.html
Modified:
    incubator/pivot/trunk/tutorials/www/drawing.xml
    incubator/pivot/trunk/tutorials/www/expanders.xml

Modified: incubator/pivot/trunk/tutorials/www/drawing.xml
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/www/drawing.xml?rev=887626&r1=887625&r2=887626&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/www/drawing.xml (original)
+++ incubator/pivot/trunk/tutorials/www/drawing.xml Sun Dec  6 01:25:44 2009
@@ -22,5 +22,169 @@
     </properties>
 
     <body>
+        <p>
+            While most of Pivot's user interface features are rendered using immediate-mode Java2D
+            calls during a <tt>paint()</tt> operation, Pivot also supports a retained mode drawing
+            API (sometimes called a "scene graph"). This API allows a caller to construct a drawing
+            programmatically by assembling a shape hierarchy, similar to the component hierarchy
+            used to construct a user interface.
+        </p>
+
+        <p>
+            For example, the following simple drawing was constructed using three <tt>Ellipse</tt>
+            shapes and an <tt>Arc</tt>:
+        </p>
+
+        <application class="org.apache.pivot.wtk.ScriptApplication"
+            width="260" height="260">
+            <libraries>
+                <library>core</library>
+                <library>wtk</library>
+                <library>wtk-terra</library>
+                <library>tutorials</library>
+            </libraries>
+            <startup-properties>
+                <src>org/apache/pivot/tutorials/drawing/simple_drawing.wtkx</src>
+            </startup-properties>
+        </application>
+
+        <p>
+            The WTKX source for the drawing is as follows:
+        </p>
+
+        <source type="xml" location="org/apache/pivot/tutorials/drawing/simple_drawing.wtkx">
+            <![CDATA[
+            <Window title="Simple Drawing" maximized="true"
+                xmlns:wtkx="http://pivot.apache.org/wtkx"
+                xmlns:media="org.apache.pivot.wtk.media"
+                xmlns="org.apache.pivot.wtk">
+                <content>
+                    <ImageView>
+                        <image>
+                            <media:Drawing>
+                                <canvas>
+                                    <Canvas xmlns="org.apache.pivot.wtk.media.drawing">
+                                        <Ellipse x="0" y="0" width="240" height="240" stroke="" fill="#ffff00"/>
+                                        <Ellipse x="70" y="60" width="30" height="40" fill="#000000"/>
+                                        <Ellipse x="140" y="60" width="30" height="40" fill="#000000"/>
+                                        <Arc x="60" y="120" width="120" height="70"
+                                            start="190" extent="160" type="open" strokeThickness="8"/>
+                                    </Canvas>
+                                </canvas>
+                            </media:Drawing>
+                        </image>
+                    </ImageView>
+                </content>
+            </Window>
+            ]]>
+        </source>
+
+        <p>
+            Drawings can be modified programmatically at regular intervals to create animations.
+            For example, the following application simulates the second hand of a clock:
+        </p>
+
+        <application class="org.apache.pivot.tutorials.drawing.RotateLine"
+            width="360" height="360">
+            <libraries>
+                <library>core</library>
+                <library>wtk</library>
+                <library>wtk-terra</library>
+                <library>tutorials</library>
+            </libraries>
+        </application>
+
+        <p>
+            The following WTKX creates the initial shape:
+        </p>
+
+        <source type="xml" location="org/apache/pivot/tutorials/drawing/rotate_line.wtkd">
+            <![CDATA[
+            <Drawing xmlns:wtkx="http://pivot.apache.org/wtkx"
+                xmlns="org.apache.pivot.wtk.media">
+                <canvas>
+                    <Canvas xmlns="org.apache.pivot.wtk.media.drawing">
+                        <Ellipse width="320" height="320" stroke="" fill="#eeeeee"/>
+                        <Line x1="0" y1="0" x2="0" y2="-160" strokeThickness="4">
+                            <transforms>
+                                <Shape.Translate x="160" y="160"/>
+                                <Shape.Rotate wtkx:id="rotation"/>
+                            </transforms>
+                        </Line>
+                    </Canvas>
+                </canvas>
+            </Drawing>
+            ]]>
+        </source>
+
+        <p>
+            Then, this Java code is used to alter the line's rotation every 1000 milliseconds:
+        </p>
+
+        <source type="java" location="org/apache/pivot/tutorials/drawing/RotateLine.java">
+            <![CDATA[
+            package org.apache.pivot.tutorials.drawing;
+
+            import org.apache.pivot.collections.Map;
+            import org.apache.pivot.wtk.Application;
+            import org.apache.pivot.wtk.ApplicationContext;
+            import org.apache.pivot.wtk.DesktopApplicationContext;
+            import org.apache.pivot.wtk.Display;
+            import org.apache.pivot.wtk.ImageView;
+            import org.apache.pivot.wtk.Window;
+            import org.apache.pivot.wtk.media.Drawing;
+            import org.apache.pivot.wtk.media.drawing.Shape;
+            import org.apache.pivot.wtkx.WTKXSerializer;
+
+            public class RotateLine implements Application {
+                private Drawing drawing = null;
+                private Shape.Rotate rotation = null;
+
+                private Window window = null;
+
+                @Override
+                public void startup(Display display, Map<String, String> properties)
+                    throws Exception{
+                    WTKXSerializer wtkxSerializer = new WTKXSerializer();
+                    drawing = (Drawing)wtkxSerializer.readObject(this, "rotate_line.wtkd");
+                    rotation = (Shape.Rotate)wtkxSerializer.get("rotation");
+
+                    ApplicationContext.scheduleRecurringCallback(new Runnable() {
+                        @Override
+                        public void run() {
+                            int angle = (int)rotation.getAngle();
+                            angle = (angle + 6) % 360;
+                            rotation.setAngle(angle);
+                        }
+                    }, 1000);
+
+                    window = new Window(new ImageView(drawing));
+                    window.setMaximized(true);
+                    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(RotateLine.class, args);
+                }
+            }
+            ]]>
+        </source>
     </body>
 </document>

Modified: incubator/pivot/trunk/tutorials/www/expanders.xml
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/www/expanders.xml?rev=887626&r1=887625&r2=887626&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/www/expanders.xml (original)
+++ incubator/pivot/trunk/tutorials/www/expanders.xml Sun Dec  6 01:25:44 2009
@@ -22,5 +22,140 @@
     </properties>
 
     <body>
+        <p>
+            Expanders are often used to present small amounts of information to the user. Since the
+            information may not be relevant to the user all the time, expanders allow the user to
+            "collapse" the panel to make more room for other content, similar to rolling up a
+            window shade. The following example demonstrates the use of the <tt>Expander</tt>
+            component:
+        </p>
+
+        <application class="org.apache.pivot.tutorials.navigation.Expanders"
+            width="220" height="360">
+            <libraries>
+                <library>core</library>
+                <library>wtk</library>
+                <library>wtk-terra</library>
+                <library>tutorials</library>
+            </libraries>
+        </application>
+
+        <p>
+            The WTKX source for this example is as follows. It declares three expanders contained
+            in a vertical flow pane, which itself is contained in a scroll pane. The contents of
+            the expanders are defined in several external WTKX files that are included by the main
+            file:
+        </p>
+
+        <source type="xml" location="org/apache/pivot/tutorials/navigation/expanders.wtkx">
+            <![CDATA[
+            <Window title="Expanders" maximized="true"
+                xmlns:wtkx="http://pivot.apache.org/wtkx"
+                xmlns="org.apache.pivot.wtk">
+                <content>
+                    <Border styles="{padding:6}">
+                        <content>
+                            <ScrollPane horizontalScrollBarPolicy="fill">
+                                <view>
+                                    <BoxPane orientation="vertical" styles="{fill:true,
+                                        padding:{left:2, right:2}}">
+                                        <Expander wtkx:id="stocksExpander" title="Stocks">
+                                            <content>
+                                                <wtkx:include src="stocks.wtkx"/>
+                                            </content>
+                                        </Expander>
+                                        <Expander wtkx:id="weatherExpander" title="Weather" expanded="false">
+                                            <content>
+                                                <wtkx:include src="weather.wtkx"/>
+                                            </content>
+                                        </Expander>
+                                        <Expander wtkx:id="calendarExpander" title="Calendar" expanded="false">
+                                            <content>
+                                                <Calendar/>
+                                            </content>
+                                        </Expander>
+                                    </BoxPane>
+                                </view>
+                            </ScrollPane>
+                        </content>
+                    </Border>
+                </content>
+            </Window>
+            ]]>
+        </source>
+
+        <p>
+            The Java source for this is extremely simple. It loads the WTKX source, and then simply
+            attaches an expander listener that ensures that the entire expander is visible when it
+            becomes expanded:
+        </p>
+
+        <source type="java" location="org/apache/pivot/tutorials/navigation/Expanders.java">
+            <![CDATA[
+            package org.apache.pivot.tutorials.navigation;
+
+            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.Expander;
+            import org.apache.pivot.wtk.ExpanderListener;
+            import org.apache.pivot.wtk.Window;
+            import org.apache.pivot.wtkx.WTKXSerializer;
+
+            public class Expanders implements Application {
+                private Window window = null;
+                private Expander stocksExpander = null;
+                private Expander weatherExpander = null;
+                private Expander calendarExpander = null;
+
+                @Override
+                public void startup(Display display, Map<String, String> properties)
+                    throws Exception {
+                    WTKXSerializer wtkxSerializer = new WTKXSerializer();
+                    window = (Window)wtkxSerializer.readObject(this, "expanders.wtkx");
+                    stocksExpander = (Expander)wtkxSerializer.get("stocksExpander");
+                    weatherExpander = (Expander)wtkxSerializer.get("weatherExpander");
+                    calendarExpander = (Expander)wtkxSerializer.get("calendarExpander");
+
+                    ExpanderListener expanderListener = new ExpanderListener.Adapter() {
+                        @Override
+                        public void expandedChanged(Expander expander) {
+                            if (expander.isExpanded()) {
+                                expander.scrollAreaToVisible(0, 0, expander.getWidth(), expander.getHeight());
+                            }
+                        }
+                    };
+
+                    stocksExpander.getExpanderListeners().add(expanderListener);
+                    weatherExpander.getExpanderListeners().add(expanderListener);
+                    calendarExpander.getExpanderListeners().add(expanderListener);
+
+                    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(Expanders.class, args);
+                }
+            }
+            ]]>
+        </source>
     </body>
 </document>