summaryrefslogtreecommitdiffstats
path: root/src/newt/classes
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-03-21 17:38:26 +0100
committerSven Gothel <[email protected]>2013-03-21 17:38:26 +0100
commit98f6f99ddc6643cfa540d6c85c64c7f8510cc1ea (patch)
treea64af443e28b916c56fab435a0b3da967226a727 /src/newt/classes
parent9dcd8bba63cfbcd6e72c855065cf4dafdbcf037e (diff)
NEWTEvent: Add isConsumed() and setConsumed(boolean) methods to simply usage, using the existing consumedTag attachment for compatibility and efficiency.
Diffstat (limited to 'src/newt/classes')
-rw-r--r--src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java5
-rw-r--r--src/newt/classes/com/jogamp/newt/event/NEWTEvent.java41
-rw-r--r--src/newt/classes/jogamp/newt/WindowImpl.java10
3 files changed, 42 insertions, 14 deletions
diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
index a3c2a5dc8..d22e50cb8 100644
--- a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
+++ b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
@@ -60,7 +60,6 @@ import com.jogamp.newt.Display;
import com.jogamp.newt.Window;
import com.jogamp.newt.event.KeyEvent;
import com.jogamp.newt.event.KeyListener;
-import com.jogamp.newt.event.NEWTEvent;
import com.jogamp.newt.event.WindowAdapter;
import com.jogamp.newt.event.WindowEvent;
import com.jogamp.newt.event.WindowListener;
@@ -214,7 +213,7 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
}
public void keyTyped(KeyEvent e) {
if(suppress) {
- e.setAttachment(NEWTEvent.consumedTag);
+ e.setConsumed(true);
suppress = false; // reset
}
}
@@ -244,7 +243,7 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
}
}
if(suppress) {
- evt.setAttachment(NEWTEvent.consumedTag);
+ evt.setConsumed(true);
}
if(DEBUG) {
System.err.println("NewtCanvasAWT.focusKey: XXX: "+ks);
diff --git a/src/newt/classes/com/jogamp/newt/event/NEWTEvent.java b/src/newt/classes/com/jogamp/newt/event/NEWTEvent.java
index 17210cef8..67bc73652 100644
--- a/src/newt/classes/com/jogamp/newt/event/NEWTEvent.java
+++ b/src/newt/classes/com/jogamp/newt/event/NEWTEvent.java
@@ -49,8 +49,7 @@ package com.jogamp.newt.event;
@SuppressWarnings("serial")
public class NEWTEvent extends java.util.EventObject {
/**
- * Object when attached via {@link #setAttachment(Object)} marks the event consumed,
- * ie. stops propagating the event any further to the <i>other</i> event listener.
+ * See {@link #setConsumed(boolean)} for description.
*/
public static final Object consumedTag = new Object();
@@ -86,7 +85,7 @@ public class NEWTEvent extends java.util.EventObject {
* @param attachment User application specific object
*/
public final void setAttachment(Object attachment) {
- this.attachment=attachment;
+ this.attachment = attachment;
}
/**
@@ -95,7 +94,41 @@ public class NEWTEvent extends java.util.EventObject {
public final Object getAttachment() {
return attachment;
}
-
+
+ /**
+ * Returns <code>true</code> if this events has been {@link #setConsumed(boolean) consumed},
+ * otherwise <code>false</code>.
+ * @see #setConsumed(boolean)
+ */
+ public final boolean isConsumed() {
+ return consumedTag == attachment;
+ }
+
+ /**
+ * If <code>consumed</code> is <code>true</code>, this event is marked as consumed,
+ * ie. the event will not be propagated any further to potential <i>other</i> event listener.
+ * Otherwise the event will be propagated to other event listener, the default.
+ * <p>
+ * The event is marked as being consumed while {@link #setAttachment(Object) attaching}
+ * the {@link #consumedTag}.
+ * </p>
+ * <p>
+ * Events with platform specific actions will be supressed if marked as consumed.
+ * Examples are:
+ * <ul>
+ * <li>{@link KeyEvent#VK_ESCAPE} on Android's BACK button w/ Activity::finish()</li>
+ * <li>{@link KeyEvent#VK_HOME} on Android's HOME button w/ Intend.ACTION_MAIN[Intend.CATEGORY_HOME]</li>
+ * </ul>
+ * </p>
+ */
+ public final void setConsumed(boolean consumed) {
+ if( consumed ) {
+ setAttachment( consumedTag );
+ } else if( consumedTag == attachment ) {
+ setAttachment( null );
+ }
+ }
+
public String toString() {
return toString(null).toString();
}
diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java
index 45100421a..e8dc0d7d7 100644
--- a/src/newt/classes/jogamp/newt/WindowImpl.java
+++ b/src/newt/classes/jogamp/newt/WindowImpl.java
@@ -2194,8 +2194,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
if(DEBUG_MOUSE_EVENT) {
System.err.println("consumeMouseEvent: event: "+e);
}
- boolean consumed = false;
- for(int i = 0; !consumed && i < mouseListeners.size(); i++ ) {
+ for(int i = 0; !e.isConsumed() && i < mouseListeners.size(); i++ ) {
MouseListener l = mouseListeners.get(i);
switch(e.getEventType()) {
case MouseEvent.EVENT_MOUSE_CLICKED:
@@ -2225,7 +2224,6 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
default:
throw new NativeWindowException("Unexpected mouse event type " + e.getEventType());
}
- consumed = NEWTEvent.consumedTag == e.getAttachment();
}
}
@@ -2354,7 +2352,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
default:
throw new NativeWindowException("Unexpected key event type " + e.getEventType());
}
- return NEWTEvent.consumedTag == e.getAttachment();
+ return e.isConsumed();
}
@SuppressWarnings("deprecation")
@@ -2460,8 +2458,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
if(DEBUG_IMPLEMENTATION) {
System.err.println("consumeWindowEvent: "+e+", visible "+isVisible()+" "+getX()+"/"+getY()+" "+getWidth()+"x"+getHeight());
}
- boolean consumed = false;
- for(int i = 0; !consumed && i < windowListeners.size(); i++ ) {
+ for(int i = 0; !e.isConsumed() && i < windowListeners.size(); i++ ) {
WindowListener l = windowListeners.get(i);
switch(e.getEventType()) {
case WindowEvent.EVENT_WINDOW_RESIZED:
@@ -2490,7 +2487,6 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
new NativeWindowException("Unexpected window event type "
+ e.getEventType());
}
- consumed = NEWTEvent.consumedTag == e.getAttachment();
}
}