You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by sm...@apache.org on 2011/05/10 00:45:29 UTC

svn commit: r1101254 - in /pivot/trunk/tests/src/org/apache/pivot/tests: ContextMenus.java ContextMenusSampleMenuHandlerAdapter.java context_menus.bxml

Author: smartini
Date: Mon May  9 22:45:29 2011
New Revision: 1101254

URL: http://svn.apache.org/viewvc?rev=1101254&view=rev
Log:
Contextual menu: add a sample under tests with more items/combinations than in the tutorial version, and with a sample of an external MenuHandler. Note that I'll reuse these classes in tests for PIVOT-737 to verify if/how contextual menus will be handled with that fix.

Added:
    pivot/trunk/tests/src/org/apache/pivot/tests/ContextMenus.java
    pivot/trunk/tests/src/org/apache/pivot/tests/ContextMenusSampleMenuHandlerAdapter.java
    pivot/trunk/tests/src/org/apache/pivot/tests/context_menus.bxml

Added: pivot/trunk/tests/src/org/apache/pivot/tests/ContextMenus.java
URL: http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/ContextMenus.java?rev=1101254&view=auto
==============================================================================
--- pivot/trunk/tests/src/org/apache/pivot/tests/ContextMenus.java (added)
+++ pivot/trunk/tests/src/org/apache/pivot/tests/ContextMenus.java Mon May  9 22:45:29 2011
@@ -0,0 +1,43 @@
+/*
+ * 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.tests;
+
+import java.net.URL;
+
+import org.apache.pivot.beans.Bindable;
+import org.apache.pivot.collections.Map;
+import org.apache.pivot.util.Resources;
+import org.apache.pivot.wtk.Component;
+import org.apache.pivot.wtk.Menu;
+import org.apache.pivot.wtk.MenuHandler;
+import org.apache.pivot.wtk.Window;
+
+public class ContextMenus extends Window implements Bindable {
+    private MenuHandler menuHandler = new ContextMenusSampleMenuHandlerAdapter() {
+        @Override
+        public boolean configureContextMenu(Component component, Menu menu, int x, int y) {
+            setDescendant(getDescendantAt(x, y));
+            return super.configureContextMenu(component, menu, x, y);
+        }
+    };
+
+    @Override
+    public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
+        setMenuHandler(menuHandler);
+    }
+
+}

Added: pivot/trunk/tests/src/org/apache/pivot/tests/ContextMenusSampleMenuHandlerAdapter.java
URL: http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/ContextMenusSampleMenuHandlerAdapter.java?rev=1101254&view=auto
==============================================================================
--- pivot/trunk/tests/src/org/apache/pivot/tests/ContextMenusSampleMenuHandlerAdapter.java (added)
+++ pivot/trunk/tests/src/org/apache/pivot/tests/ContextMenusSampleMenuHandlerAdapter.java Mon May  9 22:45:29 2011
@@ -0,0 +1,75 @@
+/*
+ * 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.tests;
+
+import org.apache.pivot.wtk.Action;
+import org.apache.pivot.wtk.Component;
+import org.apache.pivot.wtk.Menu;
+import org.apache.pivot.wtk.MenuBar;
+import org.apache.pivot.wtk.MenuHandler;
+
+public class ContextMenusSampleMenuHandlerAdapter extends MenuHandler.Adapter {
+    private Component descendant = null;
+
+    protected Component getDescendant() {
+        return descendant;
+    }
+
+    protected void setDescendant(Component descendant) {
+        this.descendant = descendant;
+    }
+    
+    @Override
+    public void configureMenuBar(Component component, MenuBar menuBar) {
+        System.out.println("Configure menu bar: " + component);
+    }
+
+    @Override
+    public void cleanupMenuBar(Component component, MenuBar menuBar) {
+        System.out.println("Clean up menu bar: " + component);
+    }
+
+    @Override
+    public boolean configureContextMenu(Component component, Menu menu, int x, int y) {
+        Menu.Section menuSection = new Menu.Section();
+        menu.getSections().add(menuSection);
+
+        menuSection.add(new Menu.Item("Do Nothing"));
+        Menu.Item doNothingMenuItem = new Menu.Item("Do Nothing and disabled");
+        doNothingMenuItem.setEnabled(false);
+        menuSection.add(doNothingMenuItem);
+
+        Menu.Item whatIsThisMenuItem = new Menu.Item("What is this?");
+        whatIsThisMenuItem.setAction(new Action() {
+            @Override
+            public void perform(Component source) {
+                String description = (descendant != null) ? (String)descendant.getUserData().get("description") : "empty";
+                String message = "This is a " + description + " description.";
+
+                System.out.println("perform: " + message);
+            }
+        });
+        menuSection.add(whatIsThisMenuItem);
+
+        Menu.Item nullActionMenuItem = new Menu.Item("Item with null action assigned");
+        nullActionMenuItem.setAction((Action) null);
+        menuSection.add(nullActionMenuItem);
+
+        return false;
+    }
+
+}

Added: pivot/trunk/tests/src/org/apache/pivot/tests/context_menus.bxml
URL: http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/context_menus.bxml?rev=1101254&view=auto
==============================================================================
--- pivot/trunk/tests/src/org/apache/pivot/tests/context_menus.bxml (added)
+++ pivot/trunk/tests/src/org/apache/pivot/tests/context_menus.bxml Mon May  9 22:45:29 2011
@@ -0,0 +1,53 @@
+<?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.
+-->
+
+<menus:ContextMenus title="Context Menus" maximized="true"
+    xmlns:bxml="http://pivot.apache.org/bxml"
+    xmlns:menus="org.apache.pivot.tests"
+    xmlns="org.apache.pivot.wtk"
+>
+    <Border styles="{color:10}">
+        <TablePane styles="{horizontalSpacing:1, verticalSpacing:1,
+            showHorizontalGridLines:true, showVerticalGridLines:true,
+            horizontalGridColor:10, verticalGridColor:10}"
+        >
+            <columns>
+                <TablePane.Column width="1*"/>
+                <TablePane.Column width="1*"/>
+            </columns>
+
+            <TablePane.Row height="1*">
+                <ImageView image="@anchor.png">
+                    <userData description="anchor"/>
+                </ImageView>
+                <ImageView image="@bell.png">
+                    <userData description="bell"/>
+                </ImageView>
+            </TablePane.Row>
+
+            <TablePane.Row height="1*">
+                <ImageView image="@clock.png">
+                    <userData description="clock"/>
+                </ImageView>
+                <ImageView image="@cup.png">
+                    <userData description="cup"/>
+                </ImageView>
+            </TablePane.Row>
+        </TablePane>
+    </Border>
+</menus:ContextMenus>