You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by tv...@apache.org on 2009/07/23 04:19:21 UTC
svn commit: r796929 - in /incubator/pivot/trunk:
tutorials/src/org/apache/pivot/tutorials/ wtk/src/org/apache/pivot/wtk/
Author: tvolkert
Date: Thu Jul 23 02:19:21 2009
New Revision: 796929
URL: http://svn.apache.org/viewvc?rev=796929&view=rev
Log:
PIVOT-181 : context menu handler
Added:
incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menu_section.wtkx (contents, props changed)
- copied, changed from r796911, incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menu_popup.wtkx
Removed:
incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menu_popup.wtkx
Modified:
incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/KitchenSink.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ApplicationContext.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Menu.java
Modified: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/KitchenSink.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/KitchenSink.java?rev=796929&r1=796928&r2=796929&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/KitchenSink.java (original)
+++ incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/KitchenSink.java Thu Jul 23 02:19:21 2009
@@ -40,6 +40,7 @@
import org.apache.pivot.wtk.Button;
import org.apache.pivot.wtk.ButtonPressListener;
import org.apache.pivot.wtk.ComponentMouseButtonListener;
+import org.apache.pivot.wtk.ContextMenuHandler;
import org.apache.pivot.wtk.DesktopApplicationContext;
import org.apache.pivot.wtk.DragSource;
import org.apache.pivot.wtk.DropAction;
@@ -50,7 +51,6 @@
import org.apache.pivot.wtk.LocalManifest;
import org.apache.pivot.wtk.Manifest;
import org.apache.pivot.wtk.Menu;
-import org.apache.pivot.wtk.MenuPopup;
import org.apache.pivot.wtk.MessageType;
import org.apache.pivot.wtk.Mouse;
import org.apache.pivot.wtk.Point;
@@ -269,7 +269,7 @@
private ImageView menuImageView = null;
private Menu.Item helpAboutMenuItem = null;
- private MenuPopup menuPopup = null;
+ private Menu.Section menuSection = null;
public Vote previewExpandedChange(Rollup rollup) {
if (component == null) {
@@ -319,22 +319,23 @@
rollup.setContent(component);
try {
- menuPopup = (MenuPopup)wtkxSerializer.readObject(this, "menu_popup.wtkx");
+ menuSection = (Menu.Section)wtkxSerializer.readObject(this, "menu_section.wtkx");
} catch(IOException exception) {
throw new RuntimeException(exception);
} catch(SerializationException exception) {
throw new RuntimeException(exception);
}
- menuImageView.getComponentMouseButtonListeners().add(new ComponentMouseButtonListener.Adapter() {
- @Override
- public boolean mouseDown(Component component, Mouse.Button button, int x, int y) {
- if (button == Mouse.Button.RIGHT
- || (button == Mouse.Button.LEFT
- && Keyboard.isPressed(Keyboard.Modifier.CTRL))) {
- menuPopup.open(window, component.mapPointToAncestor(component.getDisplay(), x, y));
+ menuImageView.setContextMenuHandler(new ContextMenuHandler() {
+ public boolean configureMenu(Menu menu) {
+ Menu previousMenu = menuSection.getMenu();
+
+ if (previousMenu != null) {
+ previousMenu.getSections().remove(menuSection);
}
+ menu.getSections().add(menuSection);
+
return false;
}
});
Copied: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menu_section.wtkx (from r796911, incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menu_popup.wtkx)
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menu_section.wtkx?p2=incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menu_section.wtkx&p1=incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menu_popup.wtkx&r1=796911&r2=796929&rev=796929&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menu_popup.wtkx (original)
+++ incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menu_section.wtkx Thu Jul 23 02:19:21 2009
@@ -16,26 +16,18 @@
limitations under the License.
-->
-<MenuPopup xmlns:wtkx="http://pivot.apache.org/wtkx"
+<Menu.Section xmlns:wtkx="http://pivot.apache.org/wtkx"
xmlns="org.apache.pivot.wtk">
- <menu>
- <Menu>
- <sections>
- <Menu.Section>
- <Menu.Item buttonData="IMG_0725_2.jpg" toggleButton="true"
- group="imageMenuGroup" action="selectImageAction">
- <userData image="IMG_0725_2.jpg"/>
- </Menu.Item>
- <Menu.Item buttonData="IMG_0735_2.jpg" toggleButton="true"
- group="imageMenuGroup" action="selectImageAction">
- <userData image="IMG_0735_2.jpg"/>
- </Menu.Item>
- <Menu.Item buttonData="IMG_0767_2.jpg" toggleButton="true"
- group="imageMenuGroup" action="selectImageAction">
- <userData image="IMG_0767_2.jpg"/>
- </Menu.Item>
- </Menu.Section>
- </sections>
- </Menu>
- </menu>
-</MenuPopup>
+ <Menu.Item buttonData="IMG_0725_2.jpg" toggleButton="true"
+ group="imageMenuGroup" action="selectImageAction">
+ <userData image="IMG_0725_2.jpg"/>
+ </Menu.Item>
+ <Menu.Item buttonData="IMG_0735_2.jpg" toggleButton="true"
+ group="imageMenuGroup" action="selectImageAction">
+ <userData image="IMG_0735_2.jpg"/>
+ </Menu.Item>
+ <Menu.Item buttonData="IMG_0767_2.jpg" toggleButton="true"
+ group="imageMenuGroup" action="selectImageAction">
+ <userData image="IMG_0767_2.jpg"/>
+ </Menu.Item>
+</Menu.Section>
Propchange: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menu_section.wtkx
------------------------------------------------------------------------------
svn:mergeinfo =
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ApplicationContext.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ApplicationContext.java?rev=796929&r1=796928&r2=796929&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ApplicationContext.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ApplicationContext.java Thu Jul 23 02:19:21 2009
@@ -51,6 +51,7 @@
import org.apache.pivot.collections.Dictionary;
import org.apache.pivot.collections.HashMap;
+import org.apache.pivot.collections.LinkedList;
import org.apache.pivot.util.ImmutableIterator;
import org.apache.pivot.util.Version;
import org.apache.pivot.wtk.Manifest;
@@ -778,8 +779,42 @@
switch (eventID) {
case MouseEvent.MOUSE_PRESSED: {
requestFocus();
- dragLocation = new Point(x, y);
+
mouseOwner.mouseDown(button, x, y);
+
+ if (button == Mouse.Button.LEFT) {
+ dragLocation = new Point(x, y);
+ } else if (button == Mouse.Button.RIGHT) {
+ Component descendant = mouseOwner;
+ if (mouseOwner instanceof Container) {
+ descendant = ((Container)mouseOwner).getDescendantAt(x, y);
+ }
+
+ LinkedList<Component> componentPath = new LinkedList<Component>(descendant);
+ while (descendant != mouseOwner) {
+ descendant = descendant.getParent();
+ componentPath.insert(descendant, 0);
+ }
+
+ Menu menu = new Menu();
+ MenuPopup menuPopup = new MenuPopup(menu);
+
+ for (Component component : componentPath) {
+ ContextMenuHandler contextMenuHandler = component.getContextMenuHandler();
+
+ if (contextMenuHandler != null) {
+ if (contextMenuHandler.configureMenu(menu)) {
+ break;
+ }
+ }
+ }
+
+ if (menu.getSections().getLength() > 0) {
+ Display display = mouseOwner.getDisplay();
+ menuPopup.open(display, mouseOwner.mapPointToAncestor(display, x, y));
+ }
+ }
+
break;
}
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Menu.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Menu.java?rev=796929&r1=796928&r2=796929&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Menu.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Menu.java Thu Jul 23 02:19:21 2009
@@ -556,7 +556,8 @@
for (int i = index, n = index + count; i < n; i++) {
Item item = (Item)get(i);
- if (item.getSection() != null) {
+ if (item.getSection() != null
+ && item.getSection().getMenu() != null) {
throw new UnsupportedOperationException();
}
}