aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-06-05 19:28:17 +0200
committerSven Gothel <[email protected]>2014-06-05 19:28:17 +0200
commit026cade97eab6fbd04e8bc902f24a2b61723acb8 (patch)
tree578bd8aee6d8b49f46e84b9ebbf3b3f82032719d
parentf9ce025372b0b1cb9b8db78a0d4294861172bc1e (diff)
NEWT AWTAdapter: Simplify event processing / Window.enqueueEvent(..): Add API doc
Simplify event processing of NEWT's AWTAdapter: - enqueueEvent -> processEvent - add return value (new enum) determinating action Using processEvent(..) now reduces manual invocation of NEWT Window.enqeueEvent(..).
-rw-r--r--src/newt/classes/com/jogamp/newt/Window.java5
-rw-r--r--src/newt/classes/com/jogamp/newt/event/awt/AWTAdapter.java37
-rw-r--r--src/newt/classes/com/jogamp/newt/event/awt/AWTKeyAdapter.java8
-rw-r--r--src/newt/classes/com/jogamp/newt/event/awt/AWTMouseAdapter.java32
-rw-r--r--src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java32
5 files changed, 58 insertions, 56 deletions
diff --git a/src/newt/classes/com/jogamp/newt/Window.java b/src/newt/classes/com/jogamp/newt/Window.java
index 57fcb626d..82199e9b5 100644
--- a/src/newt/classes/com/jogamp/newt/Window.java
+++ b/src/newt/classes/com/jogamp/newt/Window.java
@@ -603,6 +603,11 @@ public interface Window extends NativeWindow, WindowClosingProtocol {
*/
void windowRepaint(int x, int y, int width, int height);
+ /**
+ * Enqueues a {@link com.jogamp.newt.event.NEWTEvent NEWT event}.
+ * @param wait Passing <code>true</code> will block until the event has been processed, otherwise method returns immediately.
+ * @param event The {@link com.jogamp.newt.event.NEWTEvent event} to enqueue.
+ */
void enqueueEvent(boolean wait, com.jogamp.newt.event.NEWTEvent event);
void runOnEDTIfAvail(boolean wait, final Runnable task);
diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTAdapter.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTAdapter.java
index 864db1f7b..cf533eb9e 100644
--- a/src/newt/classes/com/jogamp/newt/event/awt/AWTAdapter.java
+++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTAdapter.java
@@ -218,12 +218,45 @@ public abstract class AWTAdapter implements java.util.EventListener
public abstract AWTAdapter removeFrom(java.awt.Component awtComponent);
/**
- * Enqueues the event to the {@link #getNewtWindow()} is not null.
+ * Return value for {@link AWTAdapter#processEvent(boolean, com.jogamp.newt.event.NEWTEvent) event processing}.
*/
- void enqueueEvent(boolean wait, com.jogamp.newt.event.NEWTEvent event) {
+ static enum EventProcRes {
+ /** Event shall be dispatched appropriately */
+ DISPATCH,
+ /** Event has been enqueued */
+ ENQUEUED,
+ /** No known processing method applies */
+ NOP
+ }
+
+ /**
+ * Process the event.
+ * <p>
+ * If {@link #getNewtEventListener()} is not <code>null</code>,
+ * {@link EventProcRes#DISPATCH DISPATCH} is returned and caller shall dispatch the event appropriately.
+ * </p>
+ * <p>
+ * If {@link #getNewtWindow()} is not <code>null</code>,
+ * {@link EventProcRes#ENQUEUED ENQUEUED} is returned and the event has been {@link com.jogamp.newt.Window#enqueueEvent(boolean, com.jogamp.newt.event.NEWTEvent) enqueued already}.
+ * </p>
+ * <p>
+ * If none of the above matches, {@link EventProcRes#NOP NOP} is returned and none of the above processing method applies.
+ * </p>
+ *
+ * @param wait In case the event will be {@link EventProcRes#ENQUEUED ENQUEUED},
+ * passing <code>true</code> will block until the event has been processed, otherwise method returns immediately.
+ * @param event The {@link com.jogamp.newt.event.NEWTEvent event} to enqueue.
+ * @return One of the {@link EventProcRes} values, see above.
+ */
+ EventProcRes processEvent(final boolean wait, final com.jogamp.newt.event.NEWTEvent event) {
+ if(null != newtListener) {
+ return EventProcRes.DISPATCH;
+ }
if( null != newtWindow ) {
newtWindow.enqueueEvent(wait, event);
+ return EventProcRes.ENQUEUED;
}
+ return EventProcRes.NOP;
}
}
diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTKeyAdapter.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTKeyAdapter.java
index d4226f53e..ddbeb6e42 100644
--- a/src/newt/classes/com/jogamp/newt/event/awt/AWTKeyAdapter.java
+++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTKeyAdapter.java
@@ -72,10 +72,8 @@ public class AWTKeyAdapter extends AWTAdapter implements java.awt.event.KeyListe
if( consumeAWTEvent ) {
e.consume();
}
- if(null!=newtListener) {
+ if( EventProcRes.DISPATCH == processEvent(false, event) ) {
((com.jogamp.newt.event.KeyListener)newtListener).keyPressed(event);
- } else {
- enqueueEvent(false, event);
}
}
@@ -86,10 +84,8 @@ public class AWTKeyAdapter extends AWTAdapter implements java.awt.event.KeyListe
if( consumeAWTEvent ) {
e.consume();
}
- if(null!=newtListener) {
+ if( EventProcRes.DISPATCH == processEvent(false, event) ) {
((com.jogamp.newt.event.KeyListener)newtListener).keyReleased(event);
- } else {
- enqueueEvent(false, event);
}
}
diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTMouseAdapter.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTMouseAdapter.java
index 8ad1fa6ab..d0f73ef33 100644
--- a/src/newt/classes/com/jogamp/newt/event/awt/AWTMouseAdapter.java
+++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTMouseAdapter.java
@@ -73,10 +73,8 @@ public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseL
if( consumeAWTEvent ) {
e.consume();
}
- if(null!=newtListener) {
+ if( EventProcRes.DISPATCH == processEvent(false, event) ) {
((com.jogamp.newt.event.MouseListener)newtListener).mouseClicked(event);
- } else {
- enqueueEvent(false, event);
}
}
@@ -87,10 +85,8 @@ public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseL
if( consumeAWTEvent ) {
e.consume();
}
- if(null!=newtListener) {
+ if( EventProcRes.DISPATCH == processEvent(false, event) ) {
((com.jogamp.newt.event.MouseListener)newtListener).mouseEntered(event);
- } else {
- enqueueEvent(false, event);
}
}
@@ -101,10 +97,8 @@ public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseL
if( consumeAWTEvent ) {
e.consume();
}
- if(null!=newtListener) {
+ if( EventProcRes.DISPATCH == processEvent(false, event) ) {
((com.jogamp.newt.event.MouseListener)newtListener).mouseExited(event);
- } else {
- enqueueEvent(false, event);
}
}
@@ -115,10 +109,8 @@ public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseL
if( consumeAWTEvent ) {
e.consume();
}
- if(null!=newtListener) {
+ if( EventProcRes.DISPATCH == processEvent(false, event) ) {
((com.jogamp.newt.event.MouseListener)newtListener).mousePressed(event);
- } else {
- enqueueEvent(false, event);
}
}
@@ -129,10 +121,8 @@ public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseL
if( consumeAWTEvent ) {
e.consume();
}
- if(null!=newtListener) {
+ if( EventProcRes.DISPATCH == processEvent(false, event) ) {
((com.jogamp.newt.event.MouseListener)newtListener).mouseReleased(event);
- } else {
- enqueueEvent(false, event);
}
}
@@ -143,10 +133,8 @@ public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseL
if( consumeAWTEvent ) {
e.consume();
}
- if(null!=newtListener) {
+ if( EventProcRes.DISPATCH == processEvent(false, event) ) {
((com.jogamp.newt.event.MouseListener)newtListener).mouseDragged(event);
- } else {
- enqueueEvent(false, event);
}
}
@@ -157,10 +145,8 @@ public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseL
if( consumeAWTEvent ) {
e.consume();
}
- if(null!=newtListener) {
+ if( EventProcRes.DISPATCH == processEvent(false, event) ) {
((com.jogamp.newt.event.MouseListener)newtListener).mouseMoved(event);
- } else {
- enqueueEvent(false, event);
}
}
@@ -171,10 +157,8 @@ public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseL
if( consumeAWTEvent ) {
e.consume();
}
- if(null!=newtListener) {
+ if( EventProcRes.DISPATCH == processEvent(false, event) ) {
((com.jogamp.newt.event.MouseListener)newtListener).mouseWheelMoved(event);
- } else {
- enqueueEvent(false, event);
}
}
}
diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java
index 2e5527ee1..43a28b3b3 100644
--- a/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java
+++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java
@@ -104,10 +104,8 @@ public class AWTWindowAdapter
if(DEBUG_IMPLEMENTATION) {
System.err.println("AWT: focusGained: "+e+" -> "+event);
}
- if(null!=newtListener) {
+ if( EventProcRes.DISPATCH == processEvent(false, event) ) {
((com.jogamp.newt.event.WindowListener)newtListener).windowGainedFocus(event);
- } else {
- enqueueEvent(false, event);
}
}
@@ -118,10 +116,8 @@ public class AWTWindowAdapter
if(DEBUG_IMPLEMENTATION) {
System.err.println("AWT: focusLost: "+e+" -> "+event);
}
- if(null!=newtListener) {
+ if( EventProcRes.DISPATCH == processEvent(false, event) ) {
((com.jogamp.newt.event.WindowListener)newtListener).windowLostFocus(event);
- } else {
- enqueueEvent(false, event);
}
}
@@ -144,10 +140,8 @@ public class AWTWindowAdapter
}
System.err.println("AWT: componentResized: "+sz+" ( "+insets+", "+sz2+" ), "+e+" -> "+event);
}
- if(null!=newtListener) {
+ if( EventProcRes.DISPATCH == processEvent(false, event) ) {
((com.jogamp.newt.event.WindowListener)newtListener).windowResized(event);
- } else {
- enqueueEvent(false, event);
}
}
@@ -158,10 +152,8 @@ public class AWTWindowAdapter
if(DEBUG_IMPLEMENTATION) {
System.err.println("AWT: componentMoved: "+e+" -> "+event);
}
- if(null!=newtListener) {
+ if( EventProcRes.DISPATCH == processEvent(false, event) ) {
((com.jogamp.newt.event.WindowListener)newtListener).windowMoved(event);
- } else {
- enqueueEvent(false, event);
}
}
@@ -207,10 +199,8 @@ public class AWTWindowAdapter
public synchronized void windowActivated(java.awt.event.WindowEvent e) {
if( !isSetup ) { return; }
com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow);
- if(null!=newtListener) {
+ if( EventProcRes.DISPATCH == processEvent(false, event) ) {
((com.jogamp.newt.event.WindowListener)newtListener).windowGainedFocus(event);
- } else {
- enqueueEvent(false, event);
}
}
@@ -224,10 +214,8 @@ public class AWTWindowAdapter
public synchronized void windowDeactivated(java.awt.event.WindowEvent e) {
if( !isSetup ) { return; }
com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow);
- if(null!=newtListener) {
+ if( EventProcRes.DISPATCH == processEvent(false, event) ) {
((com.jogamp.newt.event.WindowListener)newtListener).windowLostFocus(event);
- } else {
- enqueueEvent(false, event);
}
}
@@ -246,10 +234,8 @@ public class AWTWindowAdapter
synchronized( AWTWindowAdapter.this ) {
if( !isSetup ) { return; }
com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow);
- if(null!=newtListener) {
+ if( EventProcRes.DISPATCH == processEvent(true, event) ) {
((com.jogamp.newt.event.WindowListener)newtListener).windowDestroyNotify(event);
- } else {
- enqueueEvent(true, event);
}
}
}
@@ -258,10 +244,8 @@ public class AWTWindowAdapter
synchronized( AWTWindowAdapter.this ) {
if( !isSetup ) { return; }
com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow);
- if(null!=newtListener) {
+ if( EventProcRes.DISPATCH == processEvent(true, event) ) {
((com.jogamp.newt.event.WindowListener)newtListener).windowDestroyed(event);
- } else {
- enqueueEvent(true, event);
}
}
}