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/26 00:42:04 UTC

svn commit: r819058 - in /incubator/pivot/trunk: tutorials/src/org/apache/pivot/tutorials/windows/ tutorials/www/ wtk/src/org/apache/pivot/wtk/skin/terra/

Author: gbrown
Date: Fri Sep 25 22:42:03 2009
New Revision: 819058

URL: http://svn.apache.org/viewvc?rev=819058&view=rev
Log:
Initial work on windows tutorial.

Added:
    incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/
    incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/Windows.java
    incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/application_form.png   (with props)
    incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/application_form_add.png   (with props)
    incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/desktop.wtkx
    incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/frame.wtkx
    incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/pivot_logo.png   (with props)
Modified:
    incubator/pivot/trunk/tutorials/www/platform_overview.template.html
    incubator/pivot/trunk/tutorials/www/windows.template.html
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraPanoramaSkin.java

Added: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/Windows.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/Windows.java?rev=819058&view=auto
==============================================================================
--- incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/Windows.java (added)
+++ incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/Windows.java Fri Sep 25 22:42:03 2009
@@ -0,0 +1,167 @@
+/*
+ * 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.windows;
+
+import java.io.IOException;
+
+import org.apache.pivot.collections.ArrayList;
+import org.apache.pivot.collections.Map;
+import org.apache.pivot.collections.Sequence;
+import org.apache.pivot.serialization.SerializationException;
+import org.apache.pivot.wtk.Application;
+import org.apache.pivot.wtk.ApplicationContext;
+import org.apache.pivot.wtk.BoxPane;
+import org.apache.pivot.wtk.Button;
+import org.apache.pivot.wtk.ButtonPressListener;
+import org.apache.pivot.wtk.Component;
+import org.apache.pivot.wtk.Container;
+import org.apache.pivot.wtk.ContainerListener;
+import org.apache.pivot.wtk.DesktopApplicationContext;
+import org.apache.pivot.wtk.Display;
+import org.apache.pivot.wtk.Frame;
+import org.apache.pivot.wtk.PushButton;
+import org.apache.pivot.wtk.Window;
+import org.apache.pivot.wtk.content.ButtonData;
+import org.apache.pivot.wtkx.WTKXSerializer;
+
+public class Windows implements Application {
+    private Window desktop = null;
+    private PushButton newFrameButton = null;
+    private BoxPane windowButtonBoxPane = null;
+
+    private int frameNumber = 1;
+    private int frameX = 0;
+    private int frameY = 0;
+
+    @Override
+    public void startup(final Display display, Map<String, String> properties) throws Exception {
+        WTKXSerializer wtkxSerializer = new WTKXSerializer();
+        desktop = (Window)wtkxSerializer.readObject(this, "desktop.wtkx");
+
+        display.getContainerListeners().add(new ContainerListener.Adapter() {
+            @Override
+            public void componentInserted(Container container, int index) {
+                final Window window = (Window)container.get(index);
+
+                if (window.getOwner() == desktop) {
+                    final PushButton windowButton = new PushButton();
+                    windowButton.getStyles().put("toolbar", true);
+
+                    ButtonData windowButtonData = new ButtonData(window.getIcon(), window.getTitle());
+                    windowButton.setButtonData(windowButtonData);
+                    windowButton.getUserData().put("window", window);
+
+                    windowButton.getButtonPressListeners().add(new ButtonPressListener() {
+                        @Override
+                        public void buttonPressed(Button button) {
+                            window.moveToFront();
+                        }
+                    });
+
+                    windowButtonBoxPane.add(windowButton);
+
+                    ApplicationContext.queueCallback(new Runnable() {
+                        @Override
+                        public void run() {
+                            windowButton.scrollAreaToVisible(0, 0, windowButton.getWidth(), windowButton.getHeight());
+                        }
+                    });
+                }
+            }
+
+            @Override
+            public void componentsRemoved(Container container, int index, Sequence<Component> removed) {
+                removed = new ArrayList<Component>(removed);
+
+                for (int i = windowButtonBoxPane.getLength() - 1; i >= 0; i--) {
+                    PushButton windowButton = (PushButton)windowButtonBoxPane.get(i);
+                    Window window = (Window)windowButton.getUserData().get("window");
+
+                    for (int j = 0, n = removed.getLength(); j < n; j++) {
+                        if (window == removed.get(j)) {
+                            windowButtonBoxPane.remove(i, 1);
+                            removed.remove(j, 1);
+                            break;
+                        }
+                    }
+
+                    if (removed.getLength() == 0) {
+                        break;
+                    }
+                }
+            }
+        });
+
+        newFrameButton = (PushButton)wtkxSerializer.get("newFrameButton");
+        newFrameButton.getButtonPressListeners().add(new ButtonPressListener() {
+            @Override
+            public void buttonPressed(Button button) {
+                WTKXSerializer wtkxSerializer = new WTKXSerializer();
+
+                Frame frame;
+                try {
+                    frame = (Frame)wtkxSerializer.readObject(Windows.this, "frame.wtkx");
+                } catch (SerializationException exception) {
+                    throw new RuntimeException(exception);
+                } catch (IOException exception) {
+                    throw new RuntimeException(exception);
+                }
+
+                frame.setTitle("Frame " + frameNumber);
+                frameNumber++;
+
+                frame.setLocation(frameX, frameY);
+                frameX += 20;
+                if (frameX > display.getWidth()) {
+                    frameX = 0;
+                }
+
+                frameY += 20;
+                if (frameY > display.getHeight()) {
+                    frameY = 0;
+                }
+
+                frame.open(desktop);
+            }
+        });
+
+        windowButtonBoxPane = (BoxPane)wtkxSerializer.get("windowButtonBoxPane");
+
+        desktop.open(display);
+    }
+
+    @Override
+    public boolean shutdown(boolean optional) {
+        if (desktop != null) {
+            desktop.close();
+        }
+
+        return false;
+    }
+
+    @Override
+    public void suspend() {
+    }
+
+    @Override
+    public void resume() {
+    }
+
+    public static void main(String[] args) {
+        DesktopApplicationContext.main(Windows.class, args);
+    }
+}

Added: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/application_form.png
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/application_form.png?rev=819058&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/application_form.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/application_form_add.png
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/application_form_add.png?rev=819058&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/application_form_add.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/desktop.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/desktop.wtkx?rev=819058&view=auto
==============================================================================
--- incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/desktop.wtkx (added)
+++ incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/desktop.wtkx Fri Sep 25 22:42:03 2009
@@ -0,0 +1,68 @@
+<?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="Windows" maximized="true"
+    xmlns:wtkx="http://pivot.apache.org/wtkx"
+    xmlns:content="org.apache.pivot.wtk.content"
+    xmlns="org.apache.pivot.wtk">
+    <content>
+        <Border styles="{padding:0}">
+            <content>
+                <TablePane>
+                    <columns>
+                        <TablePane.Column width="1*"/>
+                    </columns>
+                    <rows>
+                        <TablePane.Row height="1*">
+                            <ImageView image="@pivot_logo.png"/>
+                        </TablePane.Row>
+
+                        <TablePane.Row height="-1">
+                            <Separator styles="{padding:0}"/>
+                        </TablePane.Row>
+
+                        <TablePane.Row height="-1">
+                            <TablePane styles="{padding:2, backgroundColor:10}">
+                                <columns>
+                                    <TablePane.Column width="-1"/>
+                                    <TablePane.Column width="1*"/>
+                                </columns>
+                                <rows>
+                                    <TablePane.Row height="1*">
+                                        <PushButton wtkx:id="newFrameButton"
+                                            styles="org/apache/pivot/wtk/skin/terra/command_button.json">
+                                            <buttonData>
+                                                <content:ButtonData icon="@application_form_add.png" text="New Frame"/>
+                                            </buttonData>
+                                        </PushButton>
+
+                                        <Panorama styles="{buttonBackgroundColor:10}">
+                                            <view>
+                                                <BoxPane wtkx:id="windowButtonBoxPane" styles="{fill:true}"/>
+                                            </view>
+                                        </Panorama>
+                                    </TablePane.Row>
+                                </rows>
+                            </TablePane>
+                        </TablePane.Row>
+                    </rows>
+                </TablePane>
+            </content>
+        </Border>
+    </content>
+</Window>

Added: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/frame.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/frame.wtkx?rev=819058&view=auto
==============================================================================
--- incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/frame.wtkx (added)
+++ incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/frame.wtkx Fri Sep 25 22:42:03 2009
@@ -0,0 +1,26 @@
+<?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 icon="@application_form.png"
+    preferredWidth="320" preferredHeight="240"
+    xmlns:wtkx="http://pivot.apache.org/wtkx"
+    xmlns:content="org.apache.pivot.wtk.content"
+    xmlns="org.apache.pivot.wtk">
+    <content>
+    </content>
+</Frame>

Added: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/pivot_logo.png
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/pivot_logo.png?rev=819058&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/pivot_logo.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: incubator/pivot/trunk/tutorials/www/platform_overview.template.html
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/www/platform_overview.template.html?rev=819058&r1=819057&r2=819058&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/www/platform_overview.template.html (original)
+++ incubator/pivot/trunk/tutorials/www/platform_overview.template.html Fri Sep 25 22:42:03 2009
@@ -140,10 +140,11 @@
 <li><p><b>Frame</b> - A window with a title bar and border for dragging and resizing.</p></li>
 <li><p><b>Dialog</b> - A frame that is generally used for collecting user input (engaging in a "dialog" with the user); may optionally be "modal", blocking input to its owner.</p></li>
 <li><p><b>Alert</b> - A dialog that is generally used to present brief notifications to the user.</p></li>
-<li><p><b>Sheet</b> - A window that, like a dialog, is generally used for collecting user input; however, unlike dialogs, sheets always have an owner, and are always modal over the owner's content.</p></li>
+<li><p><b>Sheet</b> - A window that, like a dialog, is generally used for collecting user input; however, unlike dialogs, sheets always have an owner, and are always modal over the owner's client area.</p></li>
 <li><p><b>Prompt</b> - A sheet that is generally used to present brief notifications to the user; the sheet equivalent of <tt>Alert</tt>.</p></li>
+<li><p><b>MenuPopup</b> - A "popup" window that is used to present a menu to the user. It can be used stand-alone as a context menu, but is also used by other components including <tt>MenuBar</tt> and <tt>MenuButton</tt>.</p></li>
 <li><p><b>Palette</b> - A floating tool palette window.</p></li>
-<li><p><b>FileBrowserSheet</b> - A file browser sheet.</p></li>
+<li><p><b>FileBrowserSheet</b> - A sheet that allows the user to browse the local file system.</p></li>
 <li><p><b>Tooltip</b> - A small, popup-like window that disappears as soon as the user moves the mouse.</p></li>
 </ul>
 

Modified: incubator/pivot/trunk/tutorials/www/windows.template.html
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/www/windows.template.html?rev=819058&r1=819057&r2=819058&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/www/windows.template.html (original)
+++ incubator/pivot/trunk/tutorials/www/windows.template.html Fri Sep 25 22:42:03 2009
@@ -33,6 +33,42 @@
 </head>
 <body>
 <h1>Windows</h1>
-This section is not yet complete.
+<p>Though every tutorial example thus far has used windows, Pivot's actual window classes have not yet been explicitly discussed. This is because, for many applications (especially those that are browser-based), a single main application window is sufficient. However, more complex applications often require multiple windows, allowing a user to see and interact with a variety of information.</p>
+
+<p>Though the root of the WTK component hierarchy is an instance of <tt>Display</tt>, windows generally represent an application's primary entry point into the UI. Windows are always direct descendants of the display. They represent a place on the screen where the application can draw or place user interface elements.</p>
+
+<p>The class diagram below shows the Pivot window class hierarchy (though it is not shown in this diagram, Window actually extends Container, which extends Component, the root of all WTK UI classes):</p>
+
+<p><img src="windows/windows.png"></p>
+<p class="caption">Window class hierarchy.</p>
+
+<p>The following is a description of the window types shown in the diagram:</p>
+
+<ul>
+<li><p><b>Window</b> - Base window class; it is not abstract and is the most basic means by which content may be placed on the screen. It simply provides an undecorated region in which other components may be placed.</p></li>
+<li><p><b>Frame</b> - A window with a title bar and border for dragging and resizing.</p></li>
+<li><p><b>Dialog</b> - A frame that is generally used for collecting user input (engaging in a "dialog" with the user); may optionally be "modal", blocking input to its owner.</p></li>
+<li><p><b>Alert</b> - A dialog that is generally used to present brief notifications to the user.</p></li>
+<li><p><b>Sheet</b> - A window that, like a dialog, is generally used for collecting user input; however, unlike dialogs, sheets always have an owner, and are always modal over the owner's client area.</p></li>
+<li><p><b>Prompt</b> - A sheet that is generally used to present brief notifications to the user; the sheet equivalent of <tt>Alert</tt>.</p></li>
+<li><p><b>MenuPopup</b> - A "popup" window that is used to present a menu to the user. It can be used stand-alone as a context menu, but is also used by other components including <tt>MenuBar</tt> and <tt>MenuButton</tt>.</p></li>
+<li><p><b>Palette</b> - A floating tool palette window.</p></li>
+<li><p><b>FileBrowserSheet</b> - A sheet that allows the user to browse the local file system.</p></li>
+<li><p><b>Tooltip</b> - A small, popup-like window that disappears as soon as the user moves the mouse.</p></li>
+</ul>
+
+<p>Most of the tutorial examples up to this point have used a single, maximized, decorationless <tt>Window</tt> to host their example content, since this type of user interface is well-suited to browser-based deployment as employed by this tutorial. However, Pivot applications are not limited to this sort of interface. Just like a native windowing toolkit, a Pivot application can open as many windows on the display of as many different types as are required by the application.</p>
+
+<p>The following sample application simulates an "application launcher", such as the Microsoft Windows¨ task bar or the Mac OS X dock. It allows the user to create multiple top-level <tt>Frame</tt> instances, each of which can, in turn, open a selection of additional windows for which the frame will be the owner:</p>
+
+alert
+prompt
+modal dialog
+sheet
+file browser sheet
+palette
+menu popup
+tooltip
+
 </body>
 </html>

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraPanoramaSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraPanoramaSkin.java?rev=819058&r1=819057&r2=819058&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraPanoramaSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraPanoramaSkin.java Fri Sep 25 22:42:03 2009
@@ -542,6 +542,11 @@
         setButtonBackgroundColor(GraphicsUtilities.decodeColor(buttonBackgroundColor));
     }
 
+    public final void setButtonBackgroundColor(int buttonBackgroundColor) {
+        TerraTheme theme = (TerraTheme)Theme.getTheme();
+        setButtonBackgroundColor(theme.getColor(buttonBackgroundColor));
+    }
+
     public int getButtonPadding() {
         return buttonPadding;
     }