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/03/24 20:42:01 UTC
svn commit: r757979 - in /incubator/pivot/trunk/wtk/src/pivot/wtk: ./
content/ skin/
Author: tvolkert
Date: Tue Mar 24 19:41:59 2009
New Revision: 757979
URL: http://svn.apache.org/viewvc?rev=757979&view=rev
Log:
Added ability to consume ContainerMouseListener events
Modified:
incubator/pivot/trunk/wtk/src/pivot/wtk/Container.java
incubator/pivot/trunk/wtk/src/pivot/wtk/ContainerMouseListener.java
incubator/pivot/trunk/wtk/src/pivot/wtk/content/TreeViewNodeEditor.java
incubator/pivot/trunk/wtk/src/pivot/wtk/skin/CalendarButtonSkin.java
incubator/pivot/trunk/wtk/src/pivot/wtk/skin/ListButtonSkin.java
incubator/pivot/trunk/wtk/src/pivot/wtk/skin/MenuBarItemSkin.java
incubator/pivot/trunk/wtk/src/pivot/wtk/skin/MenuButtonSkin.java
incubator/pivot/trunk/wtk/src/pivot/wtk/skin/MenuItemSkin.java
Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/Container.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/Container.java?rev=757979&r1=757978&r2=757979&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/Container.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/Container.java Tue Mar 24 19:41:59 2009
@@ -76,29 +76,45 @@
private static class ContainerMouseListenerList extends ListenerList<ContainerMouseListener>
implements ContainerMouseListener {
- public void mouseMove(Container container, int x, int y) {
+ public boolean mouseMove(Container container, int x, int y) {
+ boolean consumed = false;
+
for (ContainerMouseListener listener : this) {
- listener.mouseMove(container, x, y);
+ consumed |= listener.mouseMove(container, x, y);
}
+
+ return consumed;
}
- public void mouseDown(Container container, Mouse.Button button, int x, int y) {
+ public boolean mouseDown(Container container, Mouse.Button button, int x, int y) {
+ boolean consumed = false;
+
for (ContainerMouseListener listener : this) {
- listener.mouseDown(container, button, x, y);
+ consumed |= listener.mouseDown(container, button, x, y);
}
+
+ return consumed;
}
- public void mouseUp(Container container, Mouse.Button button, int x, int y) {
+ public boolean mouseUp(Container container, Mouse.Button button, int x, int y) {
+ boolean consumed = false;
+
for (ContainerMouseListener listener : this) {
- listener.mouseUp(container, button, x, y);
+ consumed |= listener.mouseUp(container, button, x, y);
}
+
+ return consumed;
}
- public void mouseWheel(Container container, Mouse.ScrollType scrollType,
+ public boolean mouseWheel(Container container, Mouse.ScrollType scrollType,
int scrollAmount, int wheelRotation, int x, int y) {
+ boolean consumed = false;
+
for (ContainerMouseListener listener : this) {
- listener.mouseWheel(container, scrollType, scrollAmount, wheelRotation, x, y);
+ consumed |= listener.mouseWheel(container, scrollType, scrollAmount, wheelRotation, x, y);
}
+
+ return consumed;
}
}
@@ -579,43 +595,45 @@
if (isEnabled()) {
// Notify container listeners
- containerMouseListeners.mouseMove(this, x, y);
-
- // Clear the mouse over component if its mouse-over state has
- // changed (e.g. if its enabled or visible properties have
- // changed)
- if (mouseOverComponent != null
- && !mouseOverComponent.isMouseOver()) {
- mouseOverComponent = null;
- }
-
- // Synthesize mouse over/out events
- Component component = getComponentAt(x, y);
+ consumed = containerMouseListeners.mouseMove(this, x, y);
- if (mouseOverComponent != component) {
- if (mouseOverComponent != null) {
- mouseOverComponent.mouseOut();
+ if (!consumed) {
+ // Clear the mouse over component if its mouse-over state has
+ // changed (e.g. if its enabled or visible properties have
+ // changed)
+ if (mouseOverComponent != null
+ && !mouseOverComponent.isMouseOver()) {
+ mouseOverComponent = null;
}
- mouseOverComponent = component;
+ // Synthesize mouse over/out events
+ Component component = getComponentAt(x, y);
- if (mouseOverComponent == null) {
- Mouse.setCursor(this);
- } else {
- mouseOverComponent.mouseOver();
- Mouse.setCursor(mouseOverComponent);
+ if (mouseOverComponent != component) {
+ if (mouseOverComponent != null) {
+ mouseOverComponent.mouseOut();
+ }
+
+ mouseOverComponent = component;
+
+ if (mouseOverComponent == null) {
+ Mouse.setCursor(this);
+ } else {
+ mouseOverComponent.mouseOver();
+ Mouse.setCursor(mouseOverComponent);
+ }
}
- }
- // Propagate event to subcomponents
- if (component != null) {
- consumed = component.mouseMove(x - component.getX(),
- y - component.getY());
- }
+ // Propagate event to subcomponents
+ if (component != null) {
+ consumed = component.mouseMove(x - component.getX(),
+ y - component.getY());
+ }
- // Notify the base class
- if (!consumed) {
- consumed = super.mouseMove(x, y);
+ // Notify the base class
+ if (!consumed) {
+ consumed = super.mouseMove(x, y);
+ }
}
}
@@ -641,32 +659,34 @@
if (isEnabled()) {
// Notify container listeners
- containerMouseListeners.mouseDown(this, button, x, y);
+ consumed = containerMouseListeners.mouseDown(this, button, x, y);
- // Synthesize mouse click event
- Component component = getComponentAt(x, y);
+ if (!consumed) {
+ // Synthesize mouse click event
+ Component component = getComponentAt(x, y);
- long currentTime = System.currentTimeMillis();
- int multiClickInterval = Platform.getMultiClickInterval();
- if (mouseDownComponent == component
- && currentTime - mouseDownTime < multiClickInterval) {
- mouseClickCount++;
- } else {
- mouseDownTime = System.currentTimeMillis();
- mouseClickCount = 1;
- }
+ long currentTime = System.currentTimeMillis();
+ int multiClickInterval = Platform.getMultiClickInterval();
+ if (mouseDownComponent == component
+ && currentTime - mouseDownTime < multiClickInterval) {
+ mouseClickCount++;
+ } else {
+ mouseDownTime = System.currentTimeMillis();
+ mouseClickCount = 1;
+ }
- mouseDownComponent = component;
+ mouseDownComponent = component;
- // Propagate event to subcomponents
- if (component != null) {
- consumed = component.mouseDown(button, x - component.getX(),
- y - component.getY());
- }
+ // Propagate event to subcomponents
+ if (component != null) {
+ consumed = component.mouseDown(button, x - component.getX(),
+ y - component.getY());
+ }
- // Notify the base class
- if (!consumed) {
- consumed = super.mouseDown(button, x, y);
+ // Notify the base class
+ if (!consumed) {
+ consumed = super.mouseDown(button, x, y);
+ }
}
}
@@ -679,28 +699,30 @@
if (isEnabled()) {
// Notify container listeners
- containerMouseListeners.mouseUp(this, button, x, y);
+ consumed = containerMouseListeners.mouseUp(this, button, x, y);
- // Propagate event to subcomponents
- Component component = getComponentAt(x, y);
+ if (!consumed) {
+ // Propagate event to subcomponents
+ Component component = getComponentAt(x, y);
- if (component != null) {
- consumed = component.mouseUp(button, x - component.getX(),
- y - component.getY());
- }
+ if (component != null) {
+ consumed = component.mouseUp(button, x - component.getX(),
+ y - component.getY());
+ }
- // Notify the base class
- if (!consumed) {
- consumed = super.mouseUp(button, x, y);
- }
+ // Notify the base class
+ if (!consumed) {
+ consumed = super.mouseUp(button, x, y);
+ }
- // Synthesize mouse click event
- if (component != null
- && component == mouseDownComponent
- && mouseDownComponent.isEnabled()
- && mouseDownComponent.isVisible()) {
- mouseClickConsumed = component.mouseClick(button, x - component.getX(),
- y - component.getY(), mouseClickCount);
+ // Synthesize mouse click event
+ if (component != null
+ && component == mouseDownComponent
+ && mouseDownComponent.isEnabled()
+ && mouseDownComponent.isVisible()) {
+ mouseClickConsumed = component.mouseClick(button, x - component.getX(),
+ y - component.getY(), mouseClickCount);
+ }
}
}
@@ -726,20 +748,22 @@
if (isEnabled()) {
// Notify container listeners
- containerMouseListeners.mouseWheel(this, scrollType, scrollAmount,
+ consumed = containerMouseListeners.mouseWheel(this, scrollType, scrollAmount,
wheelRotation, x, y);
- // Propagate event to subcomponents
- Component component = getComponentAt(x, y);
+ if (!consumed) {
+ // Propagate event to subcomponents
+ Component component = getComponentAt(x, y);
- if (component != null) {
- consumed = component.mouseWheel(scrollType, scrollAmount, wheelRotation,
- x - component.getX(), y - component.getY());
- }
+ if (component != null) {
+ consumed = component.mouseWheel(scrollType, scrollAmount, wheelRotation,
+ x - component.getX(), y - component.getY());
+ }
- // Notify the base class
- if (!consumed) {
- consumed = super.mouseWheel(scrollType, scrollAmount, wheelRotation, x, y);
+ // Notify the base class
+ if (!consumed) {
+ consumed = super.mouseWheel(scrollType, scrollAmount, wheelRotation, x, y);
+ }
}
}
Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/ContainerMouseListener.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/ContainerMouseListener.java?rev=757979&r1=757978&r2=757979&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/ContainerMouseListener.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/ContainerMouseListener.java Tue Mar 24 19:41:59 2009
@@ -28,8 +28,12 @@
* @param container
* @param x
* @param y
+ *
+ * @return
+ * <tt>true</tt> to consume the event; <tt>false</tt> to allow it to
+ * propagate.
*/
- public void mouseMove(Container container, int x, int y);
+ public boolean mouseMove(Container container, int x, int y);
/**
* Called when the mouse is pressed over a container.
@@ -38,8 +42,12 @@
* @param button
* @param x
* @param y
+ *
+ * @return
+ * <tt>true</tt> to consume the event; <tt>false</tt> to allow it to
+ * propagate.
*/
- public void mouseDown(Container container, Mouse.Button button, int x, int y);
+ public boolean mouseDown(Container container, Mouse.Button button, int x, int y);
/**
* Called when the mouse is released over a container.
@@ -48,8 +56,12 @@
* @param button
* @param x
* @param y
+ *
+ * @return
+ * <tt>true</tt> to consume the event; <tt>false</tt> to allow it to
+ * propagate.
*/
- public void mouseUp(Container container, Mouse.Button button, int x, int y);
+ public boolean mouseUp(Container container, Mouse.Button button, int x, int y);
/**
* Called when the mouse wheel is scrolled over a container.
@@ -60,7 +72,11 @@
* @param wheelRotation
* @param x
* @param y
+ *
+ * @return
+ * <tt>true</tt> to consume the event; <tt>false</tt> to allow it to
+ * propagate.
*/
- public void mouseWheel(Container container, Mouse.ScrollType scrollType,
+ public boolean mouseWheel(Container container, Mouse.ScrollType scrollType,
int scrollAmount, int wheelRotation, int x, int y);
}
Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/content/TreeViewNodeEditor.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/content/TreeViewNodeEditor.java?rev=757979&r1=757978&r2=757979&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/content/TreeViewNodeEditor.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/content/TreeViewNodeEditor.java Tue Mar 24 19:41:59 2009
@@ -156,37 +156,41 @@
* @author tvolkert
*/
private ContainerMouseListener displayMouseHandler = new ContainerMouseListener() {
- public void mouseMove(Container container, int x, int y) {
+ public boolean mouseMove(Container container, int x, int y) {
+ return false;
}
- public void mouseDown(Container container, Mouse.Button button, int x, int y) {
+ public boolean mouseDown(Container container, Mouse.Button button, int x, int y) {
// If the event did not occur within a window that is owned by
// this popup, close the popup
Display display = (Display)container;
Window window = (Window)display.getComponentAt(x, y);
- if (popup != null
- && (window == null
- || !popup.isOwner(window))) {
+ if (popup != null && window != popup) {
popup.close();
}
+
+ return false;
}
- public void mouseUp(Container container, Mouse.Button button, int x, int y) {
+ public boolean mouseUp(Container container, Mouse.Button button, int x, int y) {
+ return false;
}
- public void mouseWheel(Container container, Mouse.ScrollType scrollType,
+ public boolean mouseWheel(Container container, Mouse.ScrollType scrollType,
int scrollAmount, int wheelRotation, int x, int y) {
+ boolean consumed = false;
+
// If the event did not occur within a window that is owned by
// this popup, close the popup
Display display = (Display)container;
Window window = (Window)display.getComponentAt(x, y);
- if (popup != null
- && (window == null
- || !popup.isOwner(window))) {
- popup.close();
+ if (popup != null && window != popup) {
+ consumed = true;
}
+
+ return consumed;
}
};
Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/skin/CalendarButtonSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/skin/CalendarButtonSkin.java?rev=757979&r1=757978&r2=757979&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/skin/CalendarButtonSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/skin/CalendarButtonSkin.java Tue Mar 24 19:41:59 2009
@@ -150,10 +150,11 @@
};
private ContainerMouseListener displayMouseListener = new ContainerMouseListener() {
- public void mouseMove(Container container, int x, int y) {
+ public boolean mouseMove(Container container, int x, int y) {
+ return false;
}
- public void mouseDown(Container container, Mouse.Button button, int x, int y) {
+ public boolean mouseDown(Container container, Mouse.Button button, int x, int y) {
Display display = (Display)container;
Component descendant = display.getDescendantAt(x, y);
@@ -161,19 +162,26 @@
&& descendant != CalendarButtonSkin.this.getComponent()) {
calendarPopup.close();
}
+
+ return false;
}
- public void mouseUp(Container container, Mouse.Button button, int x, int y) {
+ public boolean mouseUp(Container container, Mouse.Button button, int x, int y) {
+ return false;
}
- public void mouseWheel(Container container, Mouse.ScrollType scrollType,
+ public boolean mouseWheel(Container container, Mouse.ScrollType scrollType,
int scrollAmount, int wheelRotation, int x, int y) {
+ boolean consumed = false;
+
Display display = (Display)container;
Window window = (Window)display.getComponentAt(x, y);
if (window != calendarPopup) {
- calendarPopup.close();
+ consumed = true;
}
+
+ return consumed;
}
};
Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/skin/ListButtonSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/skin/ListButtonSkin.java?rev=757979&r1=757978&r2=757979&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/skin/ListButtonSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/skin/ListButtonSkin.java Tue Mar 24 19:41:59 2009
@@ -149,10 +149,11 @@
};
private ContainerMouseListener displayMouseListener = new ContainerMouseListener() {
- public void mouseMove(Container container, int x, int y) {
+ public boolean mouseMove(Container container, int x, int y) {
+ return false;
}
- public void mouseDown(Container container, Mouse.Button button, int x, int y) {
+ public boolean mouseDown(Container container, Mouse.Button button, int x, int y) {
Display display = (Display)container;
Component descendant = display.getDescendantAt(x, y);
@@ -160,19 +161,26 @@
&& descendant != ListButtonSkin.this.getComponent()) {
listViewPopup.close();
}
+
+ return false;
}
- public void mouseUp(Container container, Mouse.Button button, int x, int y) {
+ public boolean mouseUp(Container container, Mouse.Button button, int x, int y) {
+ return false;
}
- public void mouseWheel(Container container, Mouse.ScrollType scrollType,
+ public boolean mouseWheel(Container container, Mouse.ScrollType scrollType,
int scrollAmount, int wheelRotation, int x, int y) {
+ boolean consumed = false;
+
Display display = (Display)container;
Window window = (Window)display.getComponentAt(x, y);
if (window != listViewPopup) {
- listViewPopup.close();
+ consumed = true;
}
+
+ return consumed;
}
};
Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/skin/MenuBarItemSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/skin/MenuBarItemSkin.java?rev=757979&r1=757978&r2=757979&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/skin/MenuBarItemSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/skin/MenuBarItemSkin.java Tue Mar 24 19:41:59 2009
@@ -80,10 +80,11 @@
};
private ContainerMouseListener displayMouseListener = new ContainerMouseListener() {
- public void mouseMove(Container container, int x, int y) {
+ public boolean mouseMove(Container container, int x, int y) {
+ return false;
}
- public void mouseDown(Container container, Mouse.Button button, int x, int y) {
+ public boolean mouseDown(Container container, Mouse.Button button, int x, int y) {
Display display = (Display)container;
Component descendant = display.getDescendantAt(x, y);
@@ -92,20 +93,27 @@
&& descendant != MenuBarItemSkin.this.getComponent()) {
menuPopup.close();
}
+
+ return false;
}
- public void mouseUp(Container container, Mouse.Button button, int x, int y) {
+ public boolean mouseUp(Container container, Mouse.Button button, int x, int y) {
+ return false;
}
- public void mouseWheel(Container container, Mouse.ScrollType scrollType,
+ public boolean mouseWheel(Container container, Mouse.ScrollType scrollType,
int scrollAmount, int wheelRotation, int x, int y) {
+ boolean consumed = false;
+
Display display = (Display)container;
Window window = (Window)display.getComponentAt(x, y);
if (window != menuPopup
&& !menuPopup.isOwner(window)) {
- menuPopup.close();
+ consumed = true;
}
+
+ return consumed;
}
};
Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/skin/MenuButtonSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/skin/MenuButtonSkin.java?rev=757979&r1=757978&r2=757979&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/skin/MenuButtonSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/skin/MenuButtonSkin.java Tue Mar 24 19:41:59 2009
@@ -78,10 +78,11 @@
};
private ContainerMouseListener displayMouseListener = new ContainerMouseListener() {
- public void mouseMove(Container container, int x, int y) {
+ public boolean mouseMove(Container container, int x, int y) {
+ return false;
}
- public void mouseDown(Container container, Mouse.Button button, int x, int y) {
+ public boolean mouseDown(Container container, Mouse.Button button, int x, int y) {
Display display = (Display)container;
Component descendant = display.getDescendantAt(x, y);
@@ -90,20 +91,27 @@
&& descendant != MenuButtonSkin.this.getComponent()) {
menuPopup.close();
}
+
+ return false;
}
- public void mouseUp(Container container, Mouse.Button button, int x, int y) {
+ public boolean mouseUp(Container container, Mouse.Button button, int x, int y) {
+ return false;
}
- public void mouseWheel(Container container, Mouse.ScrollType scrollType,
+ public boolean mouseWheel(Container container, Mouse.ScrollType scrollType,
int scrollAmount, int wheelRotation, int x, int y) {
+ boolean consumed = false;
+
Display display = (Display)container;
Window window = (Window)display.getComponentAt(x, y);
if (window != menuPopup
&& !menuPopup.isOwner(window)) {
- menuPopup.close();
+ consumed = true;
}
+
+ return consumed;
}
};
Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/skin/MenuItemSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/skin/MenuItemSkin.java?rev=757979&r1=757978&r2=757979&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/skin/MenuItemSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/skin/MenuItemSkin.java Tue Mar 24 19:41:59 2009
@@ -77,10 +77,11 @@
};
private ContainerMouseListener displayMouseListener = new ContainerMouseListener() {
- public void mouseMove(Container container, int x, int y) {
+ public boolean mouseMove(Container container, int x, int y) {
+ return false;
}
- public void mouseDown(Container container, Mouse.Button button, int x, int y) {
+ public boolean mouseDown(Container container, Mouse.Button button, int x, int y) {
Display display = (Display)container;
Component descendant = display.getDescendantAt(x, y);
@@ -89,20 +90,27 @@
&& descendant != MenuItemSkin.this.getComponent()) {
menuPopup.close();
}
+
+ return false;
}
- public void mouseUp(Container container, Mouse.Button button, int x, int y) {
+ public boolean mouseUp(Container container, Mouse.Button button, int x, int y) {
+ return false;
}
- public void mouseWheel(Container container, Mouse.ScrollType scrollType,
+ public boolean mouseWheel(Container container, Mouse.ScrollType scrollType,
int scrollAmount, int wheelRotation, int x, int y) {
+ boolean consumed = false;
+
Display display = (Display)container;
Window window = (Window)display.getComponentAt(x, y);
if (window != menuPopup
&& !menuPopup.isOwner(window)) {
- menuPopup.close();
+ consumed = true;
}
+
+ return consumed;
}
};