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/11 23:03:04 UTC

svn commit: r814028 - in /incubator/pivot/trunk: tutorials/src/org/apache/pivot/tutorials/menus/ tutorials/www/ wtk/src/org/apache/pivot/wtk/content/ wtk/src/org/apache/pivot/wtk/media/ wtk/src/org/apache/pivot/wtk/media/drawing/

Author: gbrown
Date: Fri Sep 11 21:02:58 2009
New Revision: 814028

URL: http://svn.apache.org/viewvc?rev=814028&view=rev
Log:
Add menu buttons tutorial example; minor drawing updates.

Added:
    incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menus/MenuButtons.java
    incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menus/menu_buttons.wtkx
    incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menus/shape_square_add.png   (with props)
    incubator/pivot/trunk/tutorials/www/context_menus.template.html
    incubator/pivot/trunk/tutorials/www/menu_bars.template.html
    incubator/pivot/trunk/tutorials/www/menu_buttons.template.html
Modified:
    incubator/pivot/trunk/tutorials/www/index.html
    incubator/pivot/trunk/tutorials/www/menus.template.html
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListButtonColorRenderer.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/Drawing.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Text.java

Added: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menus/MenuButtons.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menus/MenuButtons.java?rev=814028&view=auto
==============================================================================
--- incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menus/MenuButtons.java (added)
+++ incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menus/MenuButtons.java Fri Sep 11 21:02:58 2009
@@ -0,0 +1,142 @@
+/*
+ * 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.menus;
+
+import java.awt.Color;
+import java.awt.Paint;
+
+import org.apache.pivot.collections.Map;
+import org.apache.pivot.wtk.Action;
+import org.apache.pivot.wtk.Application;
+import org.apache.pivot.wtk.DesktopApplicationContext;
+import org.apache.pivot.wtk.Display;
+import org.apache.pivot.wtk.ImageView;
+import org.apache.pivot.wtk.ListButton;
+import org.apache.pivot.wtk.Point;
+import org.apache.pivot.wtk.Window;
+import org.apache.pivot.wtk.content.ColorItem;
+import org.apache.pivot.wtk.media.Drawing;
+import org.apache.pivot.wtk.media.drawing.Ellipse;
+import org.apache.pivot.wtk.media.drawing.Rectangle;
+import org.apache.pivot.wtk.media.drawing.Text;
+import org.apache.pivot.wtkx.WTKXSerializer;
+
+public class MenuButtons implements Application {
+    private Window window = null;
+    private ListButton colorListButton = null;
+    private ImageView imageView = null;
+
+    private Drawing drawing = null;
+
+    public MenuButtons() {
+        Action.getNamedActions().put("newCircle", new Action() {
+            @Override
+            public void perform() {
+                Ellipse ellipse = new Ellipse();
+                ellipse.setSize(50, 50);
+
+                ellipse.setStroke((Paint)null);
+                ellipse.setFill(getSelectedColor());
+                ellipse.setOrigin(getRandomLocation());
+
+                drawing.getCanvas().add(ellipse);
+            }
+        });
+
+        Action.getNamedActions().put("newSquare", new Action() {
+            @Override
+            public void perform() {
+                Rectangle rectangle = new Rectangle();
+                rectangle.setSize(50, 50);
+
+                rectangle.setStroke((Paint)null);
+                rectangle.setFill(getSelectedColor());
+                rectangle.setOrigin(getRandomLocation());
+
+                drawing.getCanvas().add(rectangle);
+            }
+        });
+
+        Action.getNamedActions().put("newText", new Action() {
+            @Override
+            public void perform() {
+                Text text = new Text();
+                text.setText("ABC");
+                text.setFont("Arial BOLD 24");
+
+                text.setFill(getSelectedColor());
+                text.setOrigin(getRandomLocation());
+
+                drawing.getCanvas().add(text);
+            }
+        });
+    }
+
+    @Override
+    public void startup(Display display, Map<String, String> properties) throws Exception {
+        WTKXSerializer wtkxSerializer = new WTKXSerializer();
+        window = (Window)wtkxSerializer.readObject(this, "menu_buttons.wtkx");
+        colorListButton = (ListButton)wtkxSerializer.get("colorListButton");
+        imageView = (ImageView)wtkxSerializer.get("imageView");
+
+        drawing = new Drawing(480, 360);
+
+        Rectangle border = new Rectangle();
+        border.setSize(479, 359);
+        border.setFill((Paint)null);
+        border.setStrokeThickness(1);
+
+        drawing.getCanvas().add(border);
+
+        imageView.setImage(drawing);
+
+        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 Color getSelectedColor() {
+        ColorItem colorItem = (ColorItem)colorListButton.getSelectedItem();
+        return colorItem.getColor();
+    }
+
+    public Point getRandomLocation() {
+        int x = (int)(Math.random() * (double)drawing.getWidth());
+        int y = (int)(Math.random() * (double)drawing.getHeight() - 20);
+
+        return new Point(x, y);
+    }
+
+    public static void main(String[] args) {
+        DesktopApplicationContext.main(MenuButtons.class, args);
+    }
+}

Added: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menus/menu_buttons.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menus/menu_buttons.wtkx?rev=814028&view=auto
==============================================================================
--- incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menus/menu_buttons.wtkx (added)
+++ incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menus/menu_buttons.wtkx Fri Sep 11 21:02:58 2009
@@ -0,0 +1,93 @@
+<?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="Menu Buttons" maximized="true"
+    xmlns:wtkx="http://pivot.apache.org/wtkx"
+    xmlns:collections="org.apache.pivot.collections"
+    xmlns:content="org.apache.pivot.wtk.content"
+    xmlns="org.apache.pivot.wtk">
+    <content>
+        <Border>
+            <content>
+                <TablePane styles="{verticalSpacing:2}">
+                    <columns>
+                        <TablePane.Column width="1*"/>
+                    </columns>
+                    <rows>
+                        <TablePane.Row height="-1">
+                            <BoxPane styles="{fill:true}">
+                                <MenuButton>
+                                    <buttonData>
+                                        <content:ButtonData icon="@shape_square_add.png" text="New Shape"/>
+                                    </buttonData>
+                                    <menu>
+                                        <Menu>
+                                            <sections>
+                                                <Menu.Section>
+                                                    <Menu.Item buttonData="Circle" action="newCircle"/>
+                                                    <Menu.Item buttonData="Square" action="newSquare"/>
+                                                    <Menu.Item buttonData="Text" action="newText"/>
+                                                </Menu.Section>
+                                            </sections>
+                                        </Menu>
+                                    </menu>
+                                </MenuButton>
+
+                                <ListButton wtkx:id="colorListButton" selectedIndex="0" styles="{listSize:6}">
+                                    <listData>
+                                        <collections:ArrayList>
+                                            <content:ColorItem color="#000000" name="Black"/>
+                                            <content:ColorItem color="#0000AA" name="Blue"/>
+                                            <content:ColorItem color="#00AA00" name="Green"/>
+                                            <content:ColorItem color="#00AAAA" name="Cyan"/>
+                                            <content:ColorItem color="#AA0000" name="Red"/>
+                                            <content:ColorItem color="#AA00AA" name="Magenta"/>
+                                            <content:ColorItem color="#AA5500" name="Brown"/>
+                                            <content:ColorItem color="#AAAAAA" name="Light Gray"/>
+                                            <content:ColorItem color="#555555" name="Dark Gray"/>
+                                            <content:ColorItem color="#5555FF" name="Bright Blue"/>
+                                            <content:ColorItem color="#55FF55" name="Bright Green"/>
+                                            <content:ColorItem color="#55FFFF" name="Bright Cyan"/>
+                                            <content:ColorItem color="#FF5555" name="Bright Red"/>
+                                            <content:ColorItem color="#FF55FF" name="Bright Magenta"/>
+                                            <content:ColorItem color="#FFFF55" name="Bright Yellow"/>
+                                            <content:ColorItem color="#FFFFFF" name="White"/>
+                                        </collections:ArrayList>
+                                    </listData>
+                                    <dataRenderer>
+                                        <content:ListButtonColorRenderer/>
+                                    </dataRenderer>
+                                    <itemRenderer>
+                                        <content:ListViewColorRenderer/>
+                                    </itemRenderer>
+                                </ListButton>
+                            </BoxPane>
+                        </TablePane.Row>
+                        <TablePane.Row height="1*">
+                            <Border>
+                                <content>
+                                    <ImageView wtkx:id="imageView"/>
+                                </content>
+                            </Border>
+                        </TablePane.Row>
+                    </rows>
+                </TablePane>
+            </content>
+        </Border>
+    </content>
+</Window>

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

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

Added: incubator/pivot/trunk/tutorials/www/context_menus.template.html
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/www/context_menus.template.html?rev=814028&view=auto
==============================================================================
--- incubator/pivot/trunk/tutorials/www/context_menus.template.html (added)
+++ incubator/pivot/trunk/tutorials/www/context_menus.template.html Fri Sep 11 21:02:58 2009
@@ -0,0 +1,40 @@
+<!--
+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.
+-->
+
+<html>
+<head>
+<title>Context Menus</title>
+<link rel="stylesheet" href="tutorial.css">
+<script src="http://java.com/js/deployJava.js"></script>
+
+<!-- NOTE: Syntax highlighting script is LGPL -->
+<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js"></script>
+<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js"></script>
+<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js"></script>
+<link type="text/css" rel="stylesheet" href="http://alexgorbatchev.com/pub/sh/current/styles/shCore.css"/>
+<link type="text/css" rel="stylesheet" href="http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css"/>
+<script type="text/javascript">
+    SyntaxHighlighter.all();
+</script>
+</head>
+<body>
+<h1>Context Menus</h1>
+This section is not yet complete.
+
+<a href="menu_bars.html">Menu Bars</a>
+</body>
+</html>

Modified: incubator/pivot/trunk/tutorials/www/index.html
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/www/index.html?rev=814028&r1=814027&r2=814028&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/www/index.html (original)
+++ incubator/pivot/trunk/tutorials/www/index.html Fri Sep 11 21:02:58 2009
@@ -106,7 +106,14 @@
     </ul>
   </li>
   <li><a href="calendars.html">Calendars</a></li>
-  <li><a href="menus.html">Menus</a></li>
+  <li>
+    <a href="menus.html">Menus</a>
+    <ul>
+        <li><a href="context_menus.html">Context Menus</a></li>
+        <li><a href="menu_buttons.html">Menu Buttons</a></li>
+        <li><a href="menu_bars.html">Menu Bars</a></li>
+    </ul>
+  </li>
   <li><a href="table_views.html">Table Views</a></li>
   <li><a href="tree_views.html">Tree Views</a></li>
   <li><a href="file_browsing.html">File Browsing</a></li>

Added: incubator/pivot/trunk/tutorials/www/menu_bars.template.html
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/www/menu_bars.template.html?rev=814028&view=auto
==============================================================================
--- incubator/pivot/trunk/tutorials/www/menu_bars.template.html (added)
+++ incubator/pivot/trunk/tutorials/www/menu_bars.template.html Fri Sep 11 21:02:58 2009
@@ -0,0 +1,40 @@
+<!--
+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.
+-->
+
+<html>
+<head>
+<title>Menu Bars</title>
+<link rel="stylesheet" href="tutorial.css">
+<script src="http://java.com/js/deployJava.js"></script>
+
+<!-- NOTE: Syntax highlighting script is LGPL -->
+<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js"></script>
+<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js"></script>
+<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js"></script>
+<link type="text/css" rel="stylesheet" href="http://alexgorbatchev.com/pub/sh/current/styles/shCore.css"/>
+<link type="text/css" rel="stylesheet" href="http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css"/>
+<script type="text/javascript">
+    SyntaxHighlighter.all();
+</script>
+</head>
+<body>
+<h1>Menu Bars</h1>
+This section is not yet complete.
+
+<a href="menu_buttons.html">Menu Buttons</a>
+</body>
+</html>

Added: incubator/pivot/trunk/tutorials/www/menu_buttons.template.html
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/www/menu_buttons.template.html?rev=814028&view=auto
==============================================================================
--- incubator/pivot/trunk/tutorials/www/menu_buttons.template.html (added)
+++ incubator/pivot/trunk/tutorials/www/menu_buttons.template.html Fri Sep 11 21:02:58 2009
@@ -0,0 +1,40 @@
+<!--
+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.
+-->
+
+<html>
+<head>
+<title>Menu Buttons</title>
+<link rel="stylesheet" href="tutorial.css">
+<script src="http://java.com/js/deployJava.js"></script>
+
+<!-- NOTE: Syntax highlighting script is LGPL -->
+<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js"></script>
+<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js"></script>
+<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js"></script>
+<link type="text/css" rel="stylesheet" href="http://alexgorbatchev.com/pub/sh/current/styles/shCore.css"/>
+<link type="text/css" rel="stylesheet" href="http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css"/>
+<script type="text/javascript">
+    SyntaxHighlighter.all();
+</script>
+</head>
+<body>
+<h1>Menu Buttons</h1>
+This section is not yet complete.
+
+<p>Next: <a href="table_views.html">Table Views</a></p>
+</body>
+</html>

Modified: incubator/pivot/trunk/tutorials/www/menus.template.html
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/www/menus.template.html?rev=814028&r1=814027&r2=814028&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/www/menus.template.html (original)
+++ incubator/pivot/trunk/tutorials/www/menus.template.html Fri Sep 11 21:02:58 2009
@@ -33,6 +33,16 @@
 </head>
 <body>
 <h1>Menus</h1>
-This section is not yet complete.
+Menus are used to present a user with a hierarchical selection of options. Pivot supports three primary means of incorporating menus into an application:
+
+<ul>
+<li><a href="context_menus.html"><b>Context Menus</b></a> - generally provide convenient "right-click" access to context-sensitive functionality.</li>
+<li><a href="menu_bars.html"><b>Menu Bars</b></a> - collection of menus generally located at the top of an application window that provide access to major application features.</li>
+<li><a href="menu_buttons.html"><b>Menu Buttons</b></a> - provide access to "drop-down" menus, similar to <a href="list_buttons.html">list buttons</a>; often used in toolbars.</a></li>
+</ul>
+
+<p>Context menus are discussed first.</p>
+
+<p>Next: <a href="context_menus.html">Context Menus</a></p>
 </body>
 </html>

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListButtonColorRenderer.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListButtonColorRenderer.java?rev=814028&r1=814027&r2=814028&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListButtonColorRenderer.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListButtonColorRenderer.java Fri Sep 11 21:02:58 2009
@@ -35,6 +35,15 @@
     }
 
     @Override
+    public void setSize(int width, int height) {
+        super.setSize(width, height);
+
+        // Since this component doesn't have a parent, it won't be validated
+        // via layout; ensure that it is valid here
+        validate();
+    }
+
+    @Override
     public void render(Object data, Button button, boolean highlighted) {
         Color color;
         if (data instanceof ColorItem) {

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/Drawing.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/Drawing.java?rev=814028&r1=814027&r2=814028&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/Drawing.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/Drawing.java Fri Sep 11 21:02:58 2009
@@ -65,11 +65,12 @@
     private DrawingListenerList drawingListeners = new DrawingListenerList();
 
     public Drawing() {
-        this(new Canvas());
+        this(640, 480);
     }
 
-    public Drawing(Canvas canvas) {
-        setCanvas(canvas);
+    public Drawing(int width, int height) {
+        setCanvas(new Canvas());
+        setSize(width, height);
     }
 
     public Canvas getCanvas() {

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Text.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Text.java?rev=814028&r1=814027&r2=814028&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Text.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Text.java Fri Sep 11 21:02:58 2009
@@ -206,6 +206,8 @@
             // Text must have a fill
             throw new IllegalArgumentException();
         }
+
+        super.setFill(fill);
     }
 
     @Override