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/10/02 01:50:50 UTC

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

Author: gbrown
Date: Thu Oct  1 23:50:49 2009
New Revision: 820847

URL: http://svn.apache.org/viewvc?rev=820847&view=rev
Log:
Complete context menu tutorial documentation; fix bug that occurs in push buttons when container mouse events are consumed.

Modified:
    incubator/pivot/trunk/tutorials/www/context_menus.template.html
    incubator/pivot/trunk/tutorials/www/menu_bars.template.html
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraDialogSkin.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraPushButtonSkin.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSheetSkin.java
    incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/SheetTest.java

Modified: 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=820847&r1=820846&r2=820847&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/www/context_menus.template.html (original)
+++ incubator/pivot/trunk/tutorials/www/context_menus.template.html Thu Oct  1 23:50:49 2009
@@ -33,8 +33,151 @@
 </head>
 <body>
 <h1>Context Menus</h1>
-This section is not yet complete.
 
-<a href="menu_bars.html">Menu Bars</a>
+<p>The Pivot framework provides platform support for context menus via the <tt>MenuPopup</tt> class, a subclass of <tt>Window</tt> that contains an instance of <tt>Menu</tt>. Though it is possible to instantiate and open a <tt>MenuPopup</tt> directly, it is often more convenient to use the <tt>MenuHandler</tt> interface. When an instance of <tt>MenuHandler</tt> is attached to a component, the Pivot platform automatically handles many of the details associated with menu processing. <tt>MenuHandler</tt> defines the following methods:</p>
+
+<pre class="snippet">
+public void configureMenuBar(Component component, MenuBar menuBar);
+public void cleanupMenuBar(Component component, MenuBar menuBar);
+public boolean configureContextMenu(Component component, Menu menu, int x, int y);
+</pre>
+
+<p>The first two methods are related to menu bars and are discussed in the next section. The third method can be used to automatically present a context menu when the user right-clicks on a component to which the handler is attached. For example, the following application uses a menu handler to present a simple context-sensitive help menu that describes what the user clicked on:</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:420,
+    height:240
+};
+var parameters = {application_class_name:"org.apache.pivot.tutorials.menus.ContextMenus",
+    codebase_lookup:false,
+    java_arguments:"-Dsun.awt.noerasebackground=true -Dsun.awt.erasebackgroundonresize=true"
+};
+deployJava.writeAppletTag(attributes, parameters);
+</script>
+
+<p>The WTKX source for the example is shown below. It simply instantiates four image view components and places a description of the image shown in each in the component's user data:</p>
+
+<pre class="brush:xml">
+&lt;Window title="Context Menus" maximized="true"
+    xmlns:wtkx="http://pivot.apache.org/wtkx"
+    xmlns="org.apache.pivot.wtk"&gt;
+    &lt;content&gt;
+        &lt;Border styles="{color:10, padding:0}"&gt;
+            &lt;content&gt;
+                &lt;TablePane styles="{horizontalSpacing:1, verticalSpacing:1,
+                    showHorizontalGridLines:true, showVerticalGridLines:true,
+                    horizontalGridColor:10, verticalGridColor:10}"&gt;
+                    &lt;columns&gt;
+                        &lt;TablePane.Column width="1*"/&gt;
+                        &lt;TablePane.Column width="1*"/&gt;
+                    &lt;/columns&gt;
+                    &lt;rows&gt;
+                        &lt;TablePane.Row height="1*"&gt;
+                            &lt;ImageView image="@battery.png"&gt;
+                                &lt;userData description="battery"/&gt;
+                            &lt;/ImageView&gt;
+                            &lt;ImageView image="@emblem-favorite.png"&gt;
+                                &lt;userData description="heart"/&gt;
+                            &lt;/ImageView&gt;
+                        &lt;/TablePane.Row&gt;
+                        &lt;TablePane.Row height="1*"&gt;
+                            &lt;ImageView image="@edit-paste.png"&gt;
+                                &lt;userData description="clipboard"/&gt;
+                            &lt;/ImageView&gt;
+                            &lt;ImageView image="@face-smile.png"&gt;
+                                &lt;userData description="smiley face"/&gt;
+                            &lt;/ImageView&gt;
+                        &lt;/TablePane.Row&gt;
+                    &lt;/rows&gt;
+                &lt;/TablePane&gt;
+            &lt;/content&gt;
+        &lt;/Border&gt;
+    &lt;/content&gt;
+&lt;/Window&gt;
+</pre>
+
+<p>The Java source is shown below. The application class defines an anonymous inner class instance that extends <tt>MenuHandler.Adapter</tt> and overrides the <tt>configureContextMenu()</tt> method to add a menu section containing a single "What is this?" menu item. When the item is pressed, a prompt is displayed containing a description of the selected item:</p>
+
+<pre class="brush:java">
+package org.apache.pivot.tutorials.menus;
+
+import org.apache.pivot.collections.Map;
+import org.apache.pivot.wtk.Action;
+import org.apache.pivot.wtk.Application;
+import org.apache.pivot.wtk.Component;
+import org.apache.pivot.wtk.DesktopApplicationContext;
+import org.apache.pivot.wtk.Display;
+import org.apache.pivot.wtk.Menu;
+import org.apache.pivot.wtk.MenuHandler;
+import org.apache.pivot.wtk.Prompt;
+import org.apache.pivot.wtk.Window;
+import org.apache.pivot.wtkx.WTKXSerializer;
+
+public class ContextMenus implements Application {
+    private Window window = null;
+    private MenuHandler menuHandler = new MenuHandler.Adapter() {
+        @Override
+        public boolean configureContextMenu(Component component, Menu menu, int x, int y) {
+            final Component descendant = window.getDescendantAt(x, y);
+
+            Menu.Section menuSection = new Menu.Section();
+            menu.getSections().add(menuSection);
+
+            Menu.Item whatIsThisMenuItem = new Menu.Item("What is this?");
+            whatIsThisMenuItem.setAction(new Action() {
+                @Override
+                public void perform() {
+                    String description = (String)descendant.getUserData().get("description");
+                    String message = "This is a " + description + ".";
+
+                    Prompt.prompt(message, window);
+                }
+            });
+
+            menuSection.add(whatIsThisMenuItem);
+
+            return false;
+        }
+    };
+
+    @Override
+    public void startup(Display display, Map&lt;String, String&gt; properties) throws Exception {
+        WTKXSerializer wtkxSerializer = new WTKXSerializer();
+        window = (Window)wtkxSerializer.readObject(this, "context_menus.wtkx");
+        window.setMenuHandler(menuHandler);
+
+        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(ContextMenus.class, args);
+    }
+}
+</pre>
+
+<p>The Pivot platform handles the details of detecting the right click and instantiating and configuring the menu popup. It walks the ancestry of the component over which the mouse click occurred from the top down, calling <tt>configureContextMenu()</tt> for each menu handler it encounters along the way. This allows handlers attached to sub-components to override any menu configuration performed by an ancestor.</p>
+
+<p>When the menu closes, the platform takes care of cleaning up the menu instance - no further interaction by the handler is required.</p>
+
+<p>Next: <a href="menu_bars.html">Menu Bars</a></p>
 </body>
 </html>

Modified: 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=820847&r1=820846&r2=820847&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/www/menu_bars.template.html (original)
+++ incubator/pivot/trunk/tutorials/www/menu_bars.template.html Thu Oct  1 23:50:49 2009
@@ -33,8 +33,8 @@
 </head>
 <body>
 <h1>Menu Bars</h1>
-This section is not yet complete.
+<p>This section is not yet complete.</p>
 
-<a href="menu_buttons.html">Menu Buttons</a>
+<p>Next: <a href="menu_buttons.html">Menu Buttons</a></p>
 </body>
 </html>

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraDialogSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraDialogSkin.java?rev=820847&r1=820846&r2=820847&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraDialogSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraDialogSkin.java Thu Oct  1 23:50:49 2009
@@ -1,5 +1,4 @@
 /*
- * 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,
@@ -179,6 +178,8 @@
         Display display = window.getDisplay();
         display.getContainerMouseListeners().add(displayMouseListener);
 
+        Mouse.setCursor(display);
+
         if (!window.requestFocus()) {
             Component.clearFocus();
         }

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraPushButtonSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraPushButtonSkin.java?rev=820847&r1=820846&r2=820847&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraPushButtonSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraPushButtonSkin.java Thu Oct  1 23:50:49 2009
@@ -550,7 +550,10 @@
 
     @Override
     public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
-        if (!toolbar) {
+        if (toolbar) {
+            highlighted = false;
+            repaintComponent();
+        } else {
             component.requestFocus();
         }
 

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSheetSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSheetSkin.java?rev=820847&r1=820846&r2=820847&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSheetSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSheetSkin.java Thu Oct  1 23:50:49 2009
@@ -402,6 +402,8 @@
         Display display = window.getDisplay();
         display.getContainerMouseListeners().add(displayMouseListener);
 
+        Mouse.setCursor(display);
+
         dropShadowDecorator.setShadowOpacity(DropShadowDecorator.DEFAULT_SHADOW_OPACITY);
 
         Window owner = window.getOwner();

Modified: incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/SheetTest.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/SheetTest.java?rev=820847&r1=820846&r2=820847&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/SheetTest.java (original)
+++ incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/SheetTest.java Thu Oct  1 23:50:49 2009
@@ -49,7 +49,11 @@
         Picture picture = (Picture)Image.load(getClass().getResource("IMG_0767_2.jpg"));
         picture.resample(120);
 
-        PushButton windowContent = new PushButton(picture);
+        BoxPane windowContent = new BoxPane();
+        PushButton button = new PushButton(picture);
+        button.getStyles().put("toolbar", true);
+
+        windowContent.add(button);
         windowContent.setPreferredSize(480, 360);
 
         frame = new Frame(windowContent);
@@ -99,7 +103,7 @@
             }
         });
 
-        windowContent.getButtonPressListeners().add(new ButtonPressListener() {
+        button.getButtonPressListeners().add(new ButtonPressListener() {
             @Override
             public void buttonPressed(Button button) {
                 prompt.open(frame);