diff options
Diffstat (limited to 'src/newt/classes/com/jogamp')
15 files changed, 693 insertions, 544 deletions
diff --git a/src/newt/classes/com/jogamp/newt/Window.java b/src/newt/classes/com/jogamp/newt/Window.java index cc42465f1..ab1eef308 100644 --- a/src/newt/classes/com/jogamp/newt/Window.java +++ b/src/newt/classes/com/jogamp/newt/Window.java @@ -28,12 +28,15 @@ package com.jogamp.newt; +import com.jogamp.newt.event.WindowEvent; import com.jogamp.newt.event.WindowListener; import com.jogamp.newt.event.KeyListener; import com.jogamp.newt.event.KeyEvent; import com.jogamp.newt.event.InputEvent; import com.jogamp.newt.event.MouseListener; import jogamp.newt.Debug; +import jogamp.newt.WindowImpl; + import javax.media.nativewindow.CapabilitiesChooser; import javax.media.nativewindow.CapabilitiesImmutable; import javax.media.nativewindow.NativeWindow; @@ -104,14 +107,26 @@ public interface Window extends NativeWindow, WindowClosingProtocol { CapabilitiesImmutable getChosenCapabilities(); /** - * Destroy the Window and it's children, incl. native destruction.<br> - * The Window can be recreate via {@link #setVisible(boolean) setVisible(true)}. - * <p>Visibility is set to false.</p> + * {@inheritDoc} + * <p> + * Also iterates through this window's children and destroys them. + * </p> + * <p> + * Visibility is set to false. + * </p> + * <p> + * Method sends out {@link WindowEvent#EVENT_WINDOW_DESTROY_NOTIFY pre-} and + * {@link WindowEvent#EVENT_WINDOW_DESTROYED post-} destruction events + * to all of it's {@link WindowListener}. + * </p> * <p> * This method invokes {@link Screen#removeReference()} after it's own destruction,<br> * which will issue {@link Screen#destroy()} if the reference count becomes 0.<br> * This destruction sequence shall end up in {@link Display#destroy()}, if all reference counts become 0. * </p> + * <p> + * The Window can be recreate via {@link #setVisible(boolean) setVisible(true)}. + * </p> * @see #destroy() * @see #setVisible(boolean) */ @@ -119,6 +134,16 @@ public interface Window extends NativeWindow, WindowClosingProtocol { void destroy(); /** + * Set a custom action handling destruction issued by a {@link WindowImpl#windowDestroyNotify(boolean) toolkit triggered window destroy} + * replacing the default {@link #destroy()} action. + * <p> + * The custom action shall call {@link #destroy()} + * but may perform further tasks before and after. + * </p> + */ + void setWindowDestroyNotifyAction(Runnable r); + + /** * <code>setVisible</code> makes the window and children visible if <code>visible</code> is true, * otherwise the window and children becomes invisible. * <p> @@ -383,10 +408,13 @@ public interface Window extends NativeWindow, WindowClosingProtocol { // WindowListener // + /** + * Send a {@link WindowEvent} to all {@link WindowListener}. + * @param eventType a {@link WindowEvent} type, e.g. {@link WindowEvent#EVENT_WINDOW_REPAINT}. + */ public void sendWindowEvent(int eventType); /** - * * Appends the given {@link com.jogamp.newt.event.WindowListener} to the end of * the list. */ diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java index 89a749c51..3c10859bf 100644 --- a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java +++ b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java @@ -34,6 +34,7 @@ import java.awt.Canvas; import java.awt.Graphics; import java.awt.GraphicsConfiguration; import java.awt.KeyboardFocusManager; +import java.beans.Beans; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.lang.reflect.Method; @@ -50,6 +51,7 @@ import javax.swing.MenuSelectionManager; import jogamp.nativewindow.awt.AWTMisc; import jogamp.newt.Debug; +import jogamp.newt.WindowImpl; import jogamp.newt.awt.NewtFactoryAWT; import jogamp.newt.awt.event.AWTParentWindowAdapter; import jogamp.newt.driver.DriverClearFocus; @@ -58,9 +60,9 @@ import com.jogamp.nativewindow.awt.AWTWindowClosingProtocol; import com.jogamp.nativewindow.awt.JAWTWindow; import com.jogamp.newt.Display; import com.jogamp.newt.Window; -import com.jogamp.newt.event.InputEvent; 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; @@ -84,18 +86,25 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto private JAWTWindow jawtWindow = null; private boolean shallUseOffscreenLayer = false; private Window newtChild = null; + private boolean newtChildAttached = false; private boolean isOnscreen = true; private WindowClosingMode newtChildCloseOp; - private AWTAdapter awtAdapter = null; + private AWTParentWindowAdapter awtAdapter = null; private AWTAdapter awtMouseAdapter = null; private AWTAdapter awtKeyAdapter = null; private AWTWindowClosingProtocol awtWindowClosingProtocol = new AWTWindowClosingProtocol(this, new Runnable() { public void run() { - NewtCanvasAWT.this.destroy(); + NewtCanvasAWT.this.destroyImpl(false /* removeNotify */, true /* windowClosing */); } - }); + }, new Runnable() { + public void run() { + if( newtChild != null ) { + newtChild.sendWindowEvent(WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY); + } + } + } ); /** * Instantiates a NewtCanvas without a NEWT child.<br> @@ -181,6 +190,10 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto WindowListener clearAWTMenusOnNewtFocus = new WindowAdapter() { @Override + public void windowResized(WindowEvent e) { + updateLayoutSize(); + } + @Override public void windowGainedFocus(WindowEvent arg0) { if( isParent() && !isFullscreen() ) { MenuSelectionManager.defaultManager().clearSelectedPath(); @@ -203,7 +216,7 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto } public void keyTyped(KeyEvent e) { if(suppress) { - e.setAttachment(InputEvent.consumedTag); + e.setAttachment(NEWTEvent.consumedTag); suppress = false; // reset } } @@ -233,7 +246,7 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto } } if(suppress) { - evt.setAttachment(InputEvent.consumedTag); + evt.setAttachment(NEWTEvent.consumedTag); } if(DEBUG) { System.err.println("NewtCanvasAWT.focusKey: XXX: "+ks); @@ -292,16 +305,26 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto final java.awt.Container cont = AWTMisc.getContainer(this); // remove old one if(null != newtChild) { - reparentWindow( false, cont ); + detachNewtChild( cont ); newtChild = null; } // add new one, reparent only if ready newtChild = newChild; - if( isDisplayable() && null != newChild) { - reparentWindow( true, cont ); - } + + updateLayoutSize(); + // will be done later at paint/display/..: attachNewtChild(cont); + return prevChild; } + + private final void updateLayoutSize() { + if( null != newtChild ) { + // use NEWT child's size for min/pref size! + java.awt.Dimension minSize = new java.awt.Dimension(newtChild.getWidth(), newtChild.getHeight()); + setMinimumSize(minSize); + setPreferredSize(minSize); + } + } /** @return the current NEWT child */ public Window getNEWTChild() { @@ -320,149 +343,44 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto return awtWindowClosingProtocol.setDefaultCloseOperation(op); } - /* package */ void configureNewtChild(boolean attach) { - if(null!=awtAdapter) { - awtAdapter.removeFrom(this); - awtAdapter=null; - } - if(null!=awtMouseAdapter) { - awtMouseAdapter.removeFrom(this); - awtMouseAdapter = null; - } - if(null!=awtKeyAdapter) { - awtKeyAdapter.removeFrom(this); - awtKeyAdapter = null; - } - if(null != keyboardFocusManager) { - keyboardFocusManager.removePropertyChangeListener("focusOwner", focusPropertyChangeListener); - keyboardFocusManager = null; - } - - if( null != newtChild ) { - newtChild.setKeyboardFocusHandler(null); - if(attach) { - if(null == jawtWindow.getGraphicsConfiguration()) { - throw new InternalError("XXX"); - } - isOnscreen = jawtWindow.getGraphicsConfiguration().getChosenCapabilities().isOnscreen(); - awtAdapter = new AWTParentWindowAdapter(jawtWindow, newtChild).addTo(this); - newtChild.addWindowListener(clearAWTMenusOnNewtFocus); - newtChild.setFocusAction(focusAction); // enable AWT focus traversal - newtChildCloseOp = newtChild.setDefaultCloseOperation(WindowClosingMode.DO_NOTHING_ON_CLOSE); - awtWindowClosingProtocol.addClosingListenerOneShot(); - keyboardFocusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); - keyboardFocusManager.addPropertyChangeListener("focusOwner", focusPropertyChangeListener); - if(isOnscreen) { - // onscreen newt child needs to fwd AWT focus - newtChild.setKeyboardFocusHandler(newtFocusTraversalKeyListener); - } else { - // offscreen newt child requires AWT to fwd AWT key/mouse event - awtMouseAdapter = new AWTMouseAdapter(newtChild).addTo(this); - awtKeyAdapter = new AWTKeyAdapter(newtChild).addTo(this); - } - } else { - newtChild.removeWindowListener(clearAWTMenusOnNewtFocus); - newtChild.setFocusAction(null); - newtChild.setDefaultCloseOperation(newtChildCloseOp); - awtWindowClosingProtocol.removeClosingListener(); - } - } - } - @Override public void addNotify() { - - // before native peer is valid: X11 - disableBackgroundErase(); - - // creates the native peer - super.addNotify(); - - // after native peer is valid: Windows - disableBackgroundErase(); - - java.awt.Container cont = AWTMisc.getContainer(this); - if(DEBUG) { - // if ( isShowing() == false ) -> Container was not visible yet. - // if ( isShowing() == true ) -> Container is already visible. - System.err.println("NewtCanvasAWT.addNotify: "+newtChild+", "+this+", visible "+isVisible()+", showing "+isShowing()+ - ", displayable "+isDisplayable()+" -> "+cont); + if( Beans.isDesignTime() ) { + super.addNotify(); + } else { + // before native peer is valid: X11 + disableBackgroundErase(); + + // creates the native peer + super.addNotify(); + + // after native peer is valid: Windows + disableBackgroundErase(); + + jawtWindow = NewtFactoryAWT.getNativeWindow(this, newtChild.getRequestedCapabilities()); + jawtWindow.setShallUseOffscreenLayer(shallUseOffscreenLayer); + + if(DEBUG) { + // if ( isShowing() == false ) -> Container was not visible yet. + // if ( isShowing() == true ) -> Container is already visible. + System.err.println("NewtCanvasAWT.addNotify: win "+newtWinHandleToHexString(newtChild)+ + ", comp "+this+", visible "+isVisible()+", showing "+isShowing()+ + ", displayable "+isDisplayable()+", cont "+AWTMisc.getContainer(this)); + } } - reparentWindow(true, cont); + awtWindowClosingProtocol.addClosingListener(); } @Override public void removeNotify() { - java.awt.Container cont = AWTMisc.getContainer(this); - if(DEBUG) { - System.err.println("NewtCanvasAWT.removeNotify: "+newtChild+", from "+cont); - } - final OffscreenLayerSurface ols = NativeWindowFactory.getOffscreenLayerSurface(newtChild, true); - if(null != ols && ols.isSurfaceLayerAttached()) { - ols.detachSurfaceLayer(); - } - reparentWindow(false, cont); + awtWindowClosingProtocol.removeClosingListener(); - if(null != jawtWindow) { - NewtFactoryAWT.destroyNativeWindow(jawtWindow); - jawtWindow=null; + if( Beans.isDesignTime() ) { + super.removeNotify(); + } else { + destroyImpl(true /* removeNotify */, false /* windowClosing */); + super.removeNotify(); } - - super.removeNotify(); - } - - void reparentWindow(boolean add, java.awt.Container cont) { - if(null==newtChild) { - return; // nop - } - if(DEBUG) { - System.err.println("NewtCanvasAWT.reparentWindow.0: add="+add+", win "+newtWinHandleToHexString(newtChild)+", EDTUtil: cur "+newtChild.getScreen().getDisplay().getEDTUtil()); - } - - newtChild.setFocusAction(null); // no AWT focus traversal .. - if(add) { - if(DEBUG) { - System.err.println("NewtCanvasAWT.reparentWindow: newtChild: "+newtChild); - } - if(null == jawtWindow) { - jawtWindow = NewtFactoryAWT.getNativeWindow(this, newtChild.getRequestedCapabilities()); - jawtWindow.setShallUseOffscreenLayer(shallUseOffscreenLayer); - } - final int w; - final int h; - if(isPreferredSizeSet()) { - java.awt.Dimension d = getPreferredSize(); - w = d.width; - h = d.height; - } else { - final java.awt.Dimension min; - if(this.isMinimumSizeSet()) { - min = getMinimumSize(); - } else { - min = new java.awt.Dimension(0, 0); - } - java.awt.Insets ins = cont.getInsets(); - w = Math.max(min.width, cont.getWidth() - ins.left - ins.right); - h = Math.max(min.height, cont.getHeight() - ins.top - ins.bottom); - } - setSize(w, h); - newtChild.setSize(w, h); - newtChild.reparentWindow(jawtWindow); - newtChild.setVisible(true); - configureNewtChild(true); - newtChild.sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); // trigger a resize/relayout to listener - - // force this AWT Canvas to be focus-able, - // since this it is completely covered by the newtChild (z-order). - setFocusable(true); - } else { - configureNewtChild(false); - newtChild.setVisible(false); - newtChild.reparentWindow(null); - } - if(DEBUG) { - System.err.println("NewtCanvasAWT.reparentWindow.X: add="+add+", win "+newtWinHandleToHexString(newtChild)+", EDTUtil: cur "+newtChild.getScreen().getDisplay().getEDTUtil()); - } } /** @@ -472,46 +390,68 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto * <li> Disconnects the NEWT Child from this Canvas NativeWindow, reparent to NULL </li> * <li> Issues <code>destroy()</code> on the NEWT Child</li> * <li> Remove reference to the NEWT Child</li> - * <li> Remove this Canvas from it's parent.</li> * </ul> * @see Window#destroy() */ public final void destroy() { - if(null!=newtChild) { + destroyImpl(false /* removeNotify */, false /* windowClosing */); + } + + private final void destroyImpl(boolean removeNotify, boolean windowClosing) { + if( null !=newtChild ) { java.awt.Container cont = AWTMisc.getContainer(this); if(DEBUG) { - System.err.println("NewtCanvasAWT.destroy(): "+newtChild+", from "+cont); - } - configureNewtChild(false); - if(null!=jawtWindow) { - NewtFactoryAWT.destroyNativeWindow(jawtWindow); - jawtWindow=null; - } - newtChild.setVisible(false); - newtChild.reparentWindow(null); - newtChild.destroy(); - newtChild=null; - if(null!=cont) { - cont.remove(this); + System.err.println("NewtCanvasAWT.destroy(removeNotify "+removeNotify+", windowClosing "+windowClosing+"): nw "+newtWinHandleToHexString(newtChild)+", from "+cont); } + detachNewtChild(cont); + + if( !removeNotify ) { + final Window cWin = newtChild; + final Window dWin = cWin.getDelegatedWindow(); + newtChild=null; + if( windowClosing && dWin instanceof WindowImpl ) { + ((WindowImpl)dWin).windowDestroyNotify(true); + } else { + cWin.destroy(); + } + } } - } - + if( ( removeNotify || windowClosing ) && null!=jawtWindow) { + NewtFactoryAWT.destroyNativeWindow(jawtWindow); + jawtWindow=null; + } + } + @Override public void paint(Graphics g) { - awtWindowClosingProtocol.addClosingListenerOneShot(); - if(null!=newtChild) { + if( validateComponent(true, null) ) { newtChild.windowRepaint(0, 0, getWidth(), getHeight()); } } @Override public void update(Graphics g) { - awtWindowClosingProtocol.addClosingListenerOneShot(); - if(null!=newtChild) { + if( validateComponent(true, null) ) { newtChild.windowRepaint(0, 0, getWidth(), getHeight()); } } + @SuppressWarnings("deprecation") + @Override + public void reshape(int x, int y, int width, int height) { + synchronized (getTreeLock()) { // super.reshape(..) claims tree lock, so we do extend it's lock over reshape + super.reshape(x, y, width, height); + if(DEBUG) { + System.err.println("NewtCanvasAWT.reshape: "+x+"/"+y+" "+width+"x"+height); + } + if( validateComponent(true, null) ) { + // newtChild.setSize(width, height); + if(null != jawtWindow && jawtWindow.isOffscreenLayerSurfaceEnabled() ) { + jawtWindow.layoutSurfaceLayer(); + } + } + } + } + private final void requestFocusNEWTChild() { if(null!=newtChild) { newtChild.setFocusAction(null); @@ -556,6 +496,140 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto return res; } + private final boolean validateComponent(boolean attachNewtChild, java.awt.Container cont) { + if( Beans.isDesignTime() || !isDisplayable() ) { + return false; + } + if ( null == newtChild || null == jawtWindow ) { + return false; + } + if( null == cont ) { + cont = AWTMisc.getContainer(this); + } + if( 0 >= getWidth() || 0 >= getHeight() ) { + return false; + } + + if( attachNewtChild && !newtChildAttached && null != newtChild ) { + attachNewtChild(cont); + } + + return true; + } + + private final void configureNewtChild(boolean attach) { + if(null!=awtAdapter) { + awtAdapter.removeFrom(this); + awtAdapter=null; + } + if(null!=awtMouseAdapter) { + awtMouseAdapter.removeFrom(this); + awtMouseAdapter = null; + } + if(null!=awtKeyAdapter) { + awtKeyAdapter.removeFrom(this); + awtKeyAdapter = null; + } + if(null != keyboardFocusManager) { + keyboardFocusManager.removePropertyChangeListener("focusOwner", focusPropertyChangeListener); + keyboardFocusManager = null; + } + + if( null != newtChild ) { + newtChild.setKeyboardFocusHandler(null); + if(attach) { + if(null == jawtWindow.getGraphicsConfiguration()) { + throw new InternalError("XXX"); + } + isOnscreen = jawtWindow.getGraphicsConfiguration().getChosenCapabilities().isOnscreen(); + awtAdapter = (AWTParentWindowAdapter) new AWTParentWindowAdapter(jawtWindow, newtChild).addTo(this); + awtAdapter.removeWindowClosingFrom(this); // we utilize AWTWindowClosingProtocol triggered destruction! + newtChild.addWindowListener(clearAWTMenusOnNewtFocus); + newtChild.setFocusAction(focusAction); // enable AWT focus traversal + newtChildCloseOp = newtChild.setDefaultCloseOperation(WindowClosingMode.DO_NOTHING_ON_CLOSE); + keyboardFocusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); + keyboardFocusManager.addPropertyChangeListener("focusOwner", focusPropertyChangeListener); + if(isOnscreen) { + // onscreen newt child needs to fwd AWT focus + newtChild.setKeyboardFocusHandler(newtFocusTraversalKeyListener); + } else { + // offscreen newt child requires AWT to fwd AWT key/mouse event + awtMouseAdapter = new AWTMouseAdapter(newtChild).addTo(this); + awtKeyAdapter = new AWTKeyAdapter(newtChild).addTo(this); + } + } else { + newtChild.removeWindowListener(clearAWTMenusOnNewtFocus); + newtChild.setFocusAction(null); + newtChild.setDefaultCloseOperation(newtChildCloseOp); + } + } + } + + private final void attachNewtChild(java.awt.Container cont) { + if( null == newtChild || null == jawtWindow || newtChildAttached ) { + return; // nop + } + if(DEBUG) { + // if ( isShowing() == false ) -> Container was not visible yet. + // if ( isShowing() == true ) -> Container is already visible. + System.err.println("NewtCanvasAWT.attachNewtChild.0: win "+newtWinHandleToHexString(newtChild)+ + ", EDTUtil: cur "+newtChild.getScreen().getDisplay().getEDTUtil()+ + ", comp "+this+", visible "+isVisible()+", showing "+isShowing()+", displayable "+isDisplayable()+ + ", cont "+cont); + } + + newtChildAttached = true; + newtChild.setFocusAction(null); // no AWT focus traversal .. + if(DEBUG) { + System.err.println("NewtCanvasAWT.attachNewtChild.1: newtChild: "+newtChild); + } + final int w = getWidth(); + final int h = getHeight(); + System.err.println("NewtCanvasAWT.attachNewtChild.2: size "+w+"x"+h); + newtChild.setSize(w, h); + newtChild.reparentWindow(jawtWindow); + newtChild.setVisible(true); + configureNewtChild(true); + newtChild.sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); // trigger a resize/relayout to listener + + // force this AWT Canvas to be focus-able, + // since this it is completely covered by the newtChild (z-order). + setFocusable(true); + if(DEBUG) { + System.err.println("NewtCanvasAWT.attachNewtChild.X: win "+newtWinHandleToHexString(newtChild)+", EDTUtil: cur "+newtChild.getScreen().getDisplay().getEDTUtil()+", comp "+this); + } + } + + private final void detachNewtChild(java.awt.Container cont) { + if( null == newtChild || null == jawtWindow || !newtChildAttached ) { + return; // nop + } + if(DEBUG) { + // if ( isShowing() == false ) -> Container was not visible yet. + // if ( isShowing() == true ) -> Container is already visible. + System.err.println("NewtCanvasAWT.detachNewtChild.0: win "+newtWinHandleToHexString(newtChild)+ + ", EDTUtil: cur "+newtChild.getScreen().getDisplay().getEDTUtil()+ + ", comp "+this+", visible "+isVisible()+", showing "+isShowing()+", displayable "+isDisplayable()+ + ", cont "+cont); + } + + newtChildAttached = false; + newtChild.setFocusAction(null); // no AWT focus traversal .. + configureNewtChild(false); + newtChild.setVisible(false); + + // Detach OLS early.. + final OffscreenLayerSurface ols = NativeWindowFactory.getOffscreenLayerSurface(newtChild, true); + if(null != ols && ols.isSurfaceLayerAttached()) { + ols.detachSurfaceLayer(); + } + newtChild.reparentWindow(null); // will destroy context (offscreen -> onscreen) and implicit detachSurfaceLayer (if still attached) + + if(DEBUG) { + System.err.println("NewtCanvasAWT.detachNewtChild.X: win "+newtWinHandleToHexString(newtChild)+", EDTUtil: cur "+newtChild.getScreen().getDisplay().getEDTUtil()+", comp "+this); + } + } + // Disables the AWT's erasing of this Canvas's background on Windows // in Java SE 6. This internal API is not available in previous // releases, but the system property diff --git a/src/newt/classes/com/jogamp/newt/awt/applet/JOGLNewtAppletBase.java b/src/newt/classes/com/jogamp/newt/awt/applet/JOGLNewtAppletBase.java index 07004503e..c3ad51c96 100755 --- a/src/newt/classes/com/jogamp/newt/awt/applet/JOGLNewtAppletBase.java +++ b/src/newt/classes/com/jogamp/newt/awt/applet/JOGLNewtAppletBase.java @@ -300,9 +300,7 @@ public class JOGLNewtAppletBase implements KeyListener, GLEventListener { glWindow.reparentWindow(awtParent); } else { glWindow.reparentWindow(null); - if(glClosable) { - glWindow.setDefaultCloseOperation(WindowClosingMode.DISPOSE_ON_CLOSE); - } + glWindow.setDefaultCloseOperation( glClosable ? WindowClosingMode.DISPOSE_ON_CLOSE : WindowClosingMode.DO_NOTHING_ON_CLOSE ); } } } diff --git a/src/newt/classes/com/jogamp/newt/event/InputEvent.java b/src/newt/classes/com/jogamp/newt/event/InputEvent.java index ad77ec79f..4920b59ea 100644 --- a/src/newt/classes/com/jogamp/newt/event/InputEvent.java +++ b/src/newt/classes/com/jogamp/newt/event/InputEvent.java @@ -81,12 +81,7 @@ public abstract class InputEvent extends NEWTEvent return 0; } - /** Object when attached via {@link #setAttachment(Object)} marks the event consumed, - * ie. stops propagating the event any further to the event listener. - */ - public static final Object consumedTag = new Object(); - - protected InputEvent(int eventType, Object source, long when, int modifiers) { + protected InputEvent(short eventType, Object source, long when, int modifiers) { super(eventType, source, when); this.modifiers=modifiers; } @@ -154,16 +149,16 @@ public abstract class InputEvent extends NEWTEvent * @return Array of pressed mouse buttons [{@link MouseEvent#BUTTON1} .. {@link MouseEvent#BUTTON6}]. * If none is down, the resulting array is of length 0. */ - public final int[] getButtonsDown() { + public final short[] getButtonsDown() { int len = 0; for(int i=1; i<=MouseEvent.BUTTON_NUMBER; i++) { - if(isButtonDown(i)) { len++; } + if( isButtonDown(i) ) { len++; } } - int[] res = new int[len]; + short[] res = new short[len]; int j = 0; for(int i=1; i<=MouseEvent.BUTTON_NUMBER; i++) { - if(isButtonDown(i)) { res[j++] = ( MouseEvent.BUTTON1 - 1 ) + i; } + if( isButtonDown(i) ) { res[j++] = (short) ( ( MouseEvent.BUTTON1 - 1 ) + i ); } } return res; } diff --git a/src/newt/classes/com/jogamp/newt/event/KeyEvent.java b/src/newt/classes/com/jogamp/newt/event/KeyEvent.java index ff67b7f57..f626fec38 100644 --- a/src/newt/classes/com/jogamp/newt/event/KeyEvent.java +++ b/src/newt/classes/com/jogamp/newt/event/KeyEvent.java @@ -36,68 +36,123 @@ package com.jogamp.newt.event; /** * Key events are delivered in the following order: - * <ol> - * <li>{@link #EVENT_KEY_PRESSED}</li> - * <li>{@link #EVENT_KEY_RELEASED}</li> - * <li>{@link #EVENT_KEY_TYPED}</li> - * </ol> + * <p> + * <table border="0"> + * <tr><th>#</th><th>Event Type</th> <th>Constraints</th> <th>Notes</th></tr> + * <tr><td>1</td><td>{@link #EVENT_KEY_PRESSED} </td><td> <i> excluding {@link #isAutoRepeat() auto-repeat} {@link #isModifierKey() modifier} keys</i></td><td></td></tr> + * <tr><td>2</td><td>{@link #EVENT_KEY_RELEASED} </td><td> <i> excluding {@link #isAutoRepeat() auto-repeat} {@link #isModifierKey() modifier} keys</i></td><td></td></tr> + * <tr><td>3</td><td>{@link #EVENT_KEY_TYPED} </td><td> <i>only for {@link #isPrintableKey() printable} and non {@link #isAutoRepeat() auto-repeat} keys</i></td><td><b>Deprecated</b>: Use {@link #EVENT_KEY_RELEASED} and apply constraints.</td></tr> + * </table> + * </p> * In case the native platform does not * deliver keyboard events in the above order or skip events, * the NEWT driver will reorder and inject synthetic events if required. * <p> * Besides regular modifiers like {@link InputEvent#SHIFT_MASK} etc., - * the {@link InputEvent#AUTOREPEAT_MASK} bit is added if repetition is detected. + * the {@link InputEvent#AUTOREPEAT_MASK} bit is added if repetition is detected, following above constraints. * </p> * <p> * Auto-Repeat shall behave as follow: * <pre> - D = pressed, U = released, T = typed + P = pressed, R = released, T = typed 0 = normal, 1 = auto-repeat - D(0), [ U(1), T(1), D(1), U(1) T(1) ..], U(0) T(0) + P(0), [ R(1), P(1), R(1), ..], R(0) T(0) * </pre> * The idea is if you mask out auto-repeat in your event listener - * you just get one long pressed key D/U/T triple. + * or catch {@link #EVENT_KEY_TYPED typed} events only, + * you just get one long pressed P/R/T triple for {@link #isPrintableKey() printable} keys. + * {@link #isActionKey() Action} keys would produce one long pressed P/R tuple in case you mask out auto-repeat . + * </p> + * <p> + * {@link #isActionKey() Action} keys will produce {@link #EVENT_KEY_PRESSED pressed} + * and {@link #EVENT_KEY_RELEASED released} events including {@link #isAutoRepeat() auto-repeat}. + * </p> + * <p> + * {@link #isPrintableKey() Printable} keys will produce {@link #EVENT_KEY_PRESSED pressed}, + * {@link #EVENT_KEY_RELEASED released} and {@link #EVENT_KEY_TYPED typed} events, the latter is excluded for {@link #isAutoRepeat() auto-repeat} events. * </p> * <p> - * {@link #isModifierKey() Modifiers keys} will produce regular events (pressed, released and typed), - * however they will not produce Auto-Repeat events itself. + * {@link #isModifierKey() Modifier} keys will produce {@link #EVENT_KEY_PRESSED pressed} + * and {@link #EVENT_KEY_RELEASED released} events excluding {@link #isAutoRepeat() auto-repeat}. + * They will also influence subsequent event's {@link #getModifiers() modifier} bits while pressed. * </p> */ @SuppressWarnings("serial") public class KeyEvent extends InputEvent { - public KeyEvent(int eventType, Object source, long when, int modifiers, int keyCode, char keyChar) { + public KeyEvent(short eventType, Object source, long when, int modifiers, short keyCode, short keySym, char keyChar) { super(eventType, source, when, modifiers); this.keyCode=keyCode; + this.keySym=keySym; this.keyChar=keyChar; + { // cache modifier and action flags + byte _flags = 0; + if( isModifierKey(keySym) ) { + _flags |= F_MODIFIER_MASK; + } + if( isActionKey(keySym) ) { + _flags |= F_ACTION_MASK; + } + flags = _flags; + } } /** - * Returns the character matching the {@link #getKeyCode() virtual key code}. + * Returns the <i>UTF-16</i> character reflecting the {@link #getKeySymbol() key symbol}. + * @see #getKeySymbol() + * @see #getKeyCode() */ - public char getKeyChar() { + public final char getKeyChar() { return keyChar; } - /** Returns the virtual key code. */ - public int getKeyCode() { + /** + * Returns the virtual <i>key symbol</i> reflecting the current <i>keyboard layout</i>. + * @see #getKeyChar() + * @see #getKeyCode() + */ + public final short getKeySymbol() { + return keySym; + } + + /** + * Returns the virtual <i>key code</i> using a fixed mapping to the <i>US keyboard layout</i>. + * <p> + * In contrast to {@link #getKeySymbol() key symbol}, <i>key code</i> + * uses a fixed <i>US keyboard layout</i> and therefore is keyboard layout independent. + * </p> + * <p> + * E.g. <i>virtual key code</i> {@link #VK_Y} denotes the same physical key + * regardless whether <i>keyboard layout</i> <code>QWERTY</code> or + * <code>QWERTZ</code> is active. The {@link #getKeySymbol() key symbol} of the former is + * {@link #VK_Y}, where the latter produces {@link #VK_Y}. + * </p> + * <p> + * <b>Disclaimer</b>: In case <i>key code</i> is not implemented on your platform (OSX, ..) + * the {@link #getKeySymbol() key symbol} is returned. + * </p> + * @see #getKeyChar() + * @see #getKeySymbol() + */ + public final short getKeyCode() { return keyCode; } - public String toString() { + public final String toString() { return toString(null).toString(); } - public StringBuilder toString(StringBuilder sb) { + public final StringBuilder toString(StringBuilder sb) { if(null == sb) { sb = new StringBuilder(); } - sb.append("KeyEvent[").append(getEventTypeString(getEventType())).append(", code ").append(keyCode).append("(").append(toHexString(keyCode)).append("), char '").append(keyChar).append("' (").append(toHexString((int)keyChar)).append("), isActionKey ").append(isActionKey()).append(", "); + sb.append("KeyEvent[").append(getEventTypeString(getEventType())).append(", code ").append(toHexString(keyCode)).append(", sym ").append(toHexString(keySym)).append(", char '").append(keyChar).append("' (").append(toHexString((short)keyChar)) + .append("), isModifierKey ").append(isModifierKey()).append(", isActionKey ").append(isActionKey()).append(", "); return super.toString(sb).append("]"); } - public static String getEventTypeString(int type) { + public static String getEventTypeString(short type) { switch(type) { case EVENT_KEY_PRESSED: return "EVENT_KEY_PRESSED"; case EVENT_KEY_RELEASED: return "EVENT_KEY_RELEASED"; @@ -107,13 +162,13 @@ public class KeyEvent extends InputEvent } /** - * Returns true if the given <code>keyCode</code> represents a non-printable modifier key. + * Returns <code>true</code> if the given <code>virtualKey</code> represents a modifier key, otherwise <code>false</code>. * <p> * A modifier key is one of {@link #VK_SHIFT}, {@link #VK_CONTROL}, {@link #VK_ALT}, {@link #VK_ALT_GRAPH}, {@link #VK_META}. * </p> */ - public static boolean isModifierKey(int keyCode) { - switch (keyCode) { + public static boolean isModifierKey(short vKey) { + switch (vKey) { case VK_SHIFT: case VK_CONTROL: case VK_ALT: @@ -126,31 +181,36 @@ public class KeyEvent extends InputEvent } /** - * Returns true if {@link #getKeyCode()} represents a non-printable modifier key. + * Returns <code>true</code> if {@link #getKeySymbol() key symbol} represents a modifier key, + * otherwise <code>false</code>. + * <p> + * See {@link #isModifierKey(short)} for details. + * </p> * <p> - * See {@link #isModifierKey(int)} for details. + * Note: Implementation uses a cached value. * </p> */ - public boolean isModifierKey() { - return isModifierKey(keyCode); + public final boolean isModifierKey() { + return 0 != ( F_MODIFIER_MASK & flags ) ; } /** - * Returns true if the given <code>keyCode</code> represents a non-printable action key, which is not a {@link #isModifierKey(int) modifier key}. + * Returns <code>true</code> if the given <code>virtualKey</code> represents a non-printable and + * non-{@link #isModifierKey(short) modifier} action key, otherwise <code>false</code>. * <p> * An action key is one of {@link #VK_HOME}, {@link #VK_END}, {@link #VK_PAGE_UP}, {@link #VK_PAGE_DOWN}, {@link #VK_UP}, {@link #VK_PAGE_DOWN}, * {@link #VK_LEFT}, {@link #VK_RIGHT}, {@link #VK_F1}-{@link #VK_F24}, {@link #VK_PRINTSCREEN}, {@link #VK_CAPS_LOCK}, {@link #VK_PAUSE}, * {@link #VK_INSERT}, {@link #VK_HELP}, {@link #VK_WINDOWS}, etc ... * </p> */ - public static boolean isActionKey(int keyCode) { - if( ( VK_F1 <= keyCode && keyCode <= VK_F24 ) || - ( VK_ALL_CANDIDATES <= keyCode && keyCode <= VK_INPUT_METHOD_ON_OFF ) || - ( VK_CUT <= keyCode && keyCode <= VK_STOP ) ) { + public static boolean isActionKey(short vKey) { + if( ( VK_F1 <= vKey && vKey <= VK_F24 ) || + ( VK_ALL_CANDIDATES <= vKey && vKey <= VK_INPUT_METHOD_ON_OFF ) || + ( VK_CUT <= vKey && vKey <= VK_STOP ) ) { return true; } - switch (keyCode) { + switch (vKey) { case VK_CANCEL: case VK_CLEAR: case VK_PAUSE: @@ -208,600 +268,614 @@ public class KeyEvent extends InputEvent } /** - * Returns true if {@link #getKeyCode() keyCode} represents a non-printable action key, which is not a {@link #isModifierKey(int) modifier key}. + * Returns <code>true</code> if {@link #getKeySymbol() key symbol} represents a non-printable and + * non-{@link #isModifierKey(short) modifier} action key, otherwise <code>false</code>. * <p> - * See {@link #isActionKey(int)} for details. + * See {@link #isActionKey(short)} for details. * </p> */ - public boolean isActionKey() { - return isActionKey(keyCode); + public final boolean isActionKey() { + return 0 != ( F_ACTION_MASK & flags ) ; } /** - * Returns true if given <code>keyKode</code> represents a printable character, which is neither a {@link #isModifierKey(int) modifier key} - * nor an {@link #isActionKey(int) action key}. + * Returns <code>true</code> if given <code>virtualKey</code> represents a printable character, + * i.e. neither a {@link #isModifierKey(short) modifier key} + * nor an {@link #isActionKey(short) action key}. * Otherwise returns <code>false</code>. */ - public static boolean isPrintableKey(int keyCode) { - return !isModifierKey(keyCode) && !isActionKey(keyCode); + public static boolean isPrintableKey(short vKey) { + return !isModifierKey(vKey) && !isActionKey(vKey); } /** - * Returns true if {@link #getKeyCode() keyCode} represents a printable character, which is neither a {@link #isModifierKey(int) modifier key} - * nor an {@link #isActionKey(int) action key}. + * Returns <code>true</code> if {@link #getKeySymbol() key symbol} represents a printable character, + * i.e. neither a {@link #isModifierKey(short) modifier key} + * nor an {@link #isActionKey(short) action key}. * Otherwise returns <code>false</code>. */ - public boolean isPrintableKey() { - return isPrintableKey(keyCode); + public final boolean isPrintableKey() { + return 0 == ( F_NON_PRINT_MASK & flags ) ; } - private final int keyCode; + private final short keyCode; + private final short keySym; private final char keyChar; - - public static final int EVENT_KEY_PRESSED = 300; - public static final int EVENT_KEY_RELEASED= 301; - public static final int EVENT_KEY_TYPED = 302; + private final byte flags; + private static final byte F_MODIFIER_MASK = 1 << 0; + private static final byte F_ACTION_MASK = 1 << 1; + private static final byte F_NON_PRINT_MASK = F_MODIFIER_MASK | F_ACTION_MASK ; + + /** A key has been pressed, excluding {@link #isAutoRepeat() auto-repeat} {@link #isModifierKey() modifier} keys. */ + public static final short EVENT_KEY_PRESSED = 300; + /** A key has been released, excluding {@link #isAutoRepeat() auto-repeat} {@link #isModifierKey() modifier} keys. */ + public static final short EVENT_KEY_RELEASED= 301; + /** + * A {@link #isPrintableKey() printable} key has been typed (pressed and released), excluding {@link #isAutoRepeat() auto-repeat}. + * @deprecated Redundant, will be removed soon. Use {@link #EVENT_KEY_RELEASED} and exclude non {@link #isPrintableKey() printable} keys and {@link #isAutoRepeat() auto-repeat}. + */ + public static final short EVENT_KEY_TYPED = 302; /* Virtual key codes. */ - public static final int VK_CANCEL = 0x03; - public static final int VK_BACK_SPACE = 0x08; // '\b' - public static final int VK_TAB = 0x09; // '\t' - public static final int VK_ENTER = 0x0A; // '\n' - public static final int VK_CLEAR = 0x0C; - public static final int VK_SHIFT = 0x10; - public static final int VK_CONTROL = 0x11; - public static final int VK_ALT = 0x12; - public static final int VK_PAUSE = 0x13; - public static final int VK_CAPS_LOCK = 0x14; - public static final int VK_ESCAPE = 0x1B; - public static final int VK_SPACE = 0x20; - public static final int VK_PAGE_UP = 0x21; - public static final int VK_PAGE_DOWN = 0x22; - public static final int VK_END = 0x23; - public static final int VK_HOME = 0x24; + public static final short VK_CANCEL = (short) 0x03; + public static final short VK_BACK_SPACE = (short) 0x08; // '\b' + public static final short VK_TAB = (short) 0x09; // '\t' + public static final short VK_ENTER = (short) 0x0A; // '\n' + public static final short VK_CLEAR = (short) 0x0C; + public static final short VK_SHIFT = (short) 0x10; + public static final short VK_CONTROL = (short) 0x11; + public static final short VK_ALT = (short) 0x12; + public static final short VK_PAUSE = (short) 0x13; + public static final short VK_CAPS_LOCK = (short) 0x14; + public static final short VK_ESCAPE = (short) 0x1B; + public static final short VK_SPACE = (short) 0x20; + public static final short VK_PAGE_UP = (short) 0x21; + public static final short VK_PAGE_DOWN = (short) 0x22; + public static final short VK_END = (short) 0x23; + public static final short VK_HOME = (short) 0x24; /** * Constant for the non-numpad <b>left</b> arrow key. * @see #VK_KP_LEFT */ - public static final int VK_LEFT = 0x25; + public static final short VK_LEFT = (short) 0x25; /** * Constant for the non-numpad <b>up</b> arrow key. * @see #VK_KP_UP */ - public static final int VK_UP = 0x26; + public static final short VK_UP = (short) 0x26; /** * Constant for the non-numpad <b>right</b> arrow key. * @see #VK_KP_RIGHT */ - public static final int VK_RIGHT = 0x27; + public static final short VK_RIGHT = (short) 0x27; /** * Constant for the non-numpad <b>down</b> arrow key. * @see #VK_KP_DOWN */ - public static final int VK_DOWN = 0x28; + public static final short VK_DOWN = (short) 0x28; /** * Constant for the comma key, "," */ - public static final int VK_COMMA = 0x2C; + public static final short VK_COMMA = (short) 0x2C; /** * Constant for the minus key, "-" * @since 1.2 */ - public static final int VK_MINUS = 0x2D; + public static final short VK_MINUS = (short) 0x2D; /** * Constant for the period key, "." */ - public static final int VK_PERIOD = 0x2E; + public static final short VK_PERIOD = (short) 0x2E; /** * Constant for the forward slash key, "/" */ - public static final int VK_SLASH = 0x2F; + public static final short VK_SLASH = (short) 0x2F; /** VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */ - public static final int VK_0 = 0x30; - public static final int VK_1 = 0x31; - public static final int VK_2 = 0x32; - public static final int VK_3 = 0x33; - public static final int VK_4 = 0x34; - public static final int VK_5 = 0x35; - public static final int VK_6 = 0x36; - public static final int VK_7 = 0x37; - public static final int VK_8 = 0x38; - public static final int VK_9 = 0x39; + public static final short VK_0 = (short) 0x30; + public static final short VK_1 = (short) 0x31; + public static final short VK_2 = (short) 0x32; + public static final short VK_3 = (short) 0x33; + public static final short VK_4 = (short) 0x34; + public static final short VK_5 = (short) 0x35; + public static final short VK_6 = (short) 0x36; + public static final short VK_7 = (short) 0x37; + public static final short VK_8 = (short) 0x38; + public static final short VK_9 = (short) 0x39; /** * Constant for the semicolon key, ";" */ - public static final int VK_SEMICOLON = 0x3B; + public static final short VK_SEMICOLON = (short) 0x3B; /** * Constant for the equals key, "=" */ - public static final int VK_EQUALS = 0x3D; + public static final short VK_EQUALS = (short) 0x3D; /** VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */ - public static final int VK_A = 0x41; - public static final int VK_B = 0x42; - public static final int VK_C = 0x43; - public static final int VK_D = 0x44; - public static final int VK_E = 0x45; - public static final int VK_F = 0x46; - public static final int VK_G = 0x47; - public static final int VK_H = 0x48; - public static final int VK_I = 0x49; - public static final int VK_J = 0x4A; - public static final int VK_K = 0x4B; - public static final int VK_L = 0x4C; - public static final int VK_M = 0x4D; - public static final int VK_N = 0x4E; - public static final int VK_O = 0x4F; - public static final int VK_P = 0x50; - public static final int VK_Q = 0x51; - public static final int VK_R = 0x52; - public static final int VK_S = 0x53; - public static final int VK_T = 0x54; - public static final int VK_U = 0x55; - public static final int VK_V = 0x56; - public static final int VK_W = 0x57; - public static final int VK_X = 0x58; - public static final int VK_Y = 0x59; - public static final int VK_Z = 0x5A; + public static final short VK_A = (short) 0x41; + public static final short VK_B = (short) 0x42; + public static final short VK_C = (short) 0x43; + public static final short VK_D = (short) 0x44; + public static final short VK_E = (short) 0x45; + public static final short VK_F = (short) 0x46; + public static final short VK_G = (short) 0x47; + public static final short VK_H = (short) 0x48; + public static final short VK_I = (short) 0x49; + public static final short VK_J = (short) 0x4A; + public static final short VK_K = (short) 0x4B; + public static final short VK_L = (short) 0x4C; + public static final short VK_M = (short) 0x4D; + public static final short VK_N = (short) 0x4E; + public static final short VK_O = (short) 0x4F; + public static final short VK_P = (short) 0x50; + public static final short VK_Q = (short) 0x51; + public static final short VK_R = (short) 0x52; + public static final short VK_S = (short) 0x53; + public static final short VK_T = (short) 0x54; + public static final short VK_U = (short) 0x55; + public static final short VK_V = (short) 0x56; + public static final short VK_W = (short) 0x57; + public static final short VK_X = (short) 0x58; + public static final short VK_Y = (short) 0x59; + public static final short VK_Z = (short) 0x5A; /** * Constant for the open bracket key, "[" */ - public static final int VK_OPEN_BRACKET = 0x5B; + public static final short VK_OPEN_BRACKET = (short) 0x5B; /** * Constant for the back slash key, "\" */ - public static final int VK_BACK_SLASH = 0x5C; + public static final short VK_BACK_SLASH = (short) 0x5C; /** * Constant for the close bracket key, "]" */ - public static final int VK_CLOSE_BRACKET = 0x5D; - - public static final int VK_NUMPAD0 = 0x60; - public static final int VK_NUMPAD1 = 0x61; - public static final int VK_NUMPAD2 = 0x62; - public static final int VK_NUMPAD3 = 0x63; - public static final int VK_NUMPAD4 = 0x64; - public static final int VK_NUMPAD5 = 0x65; - public static final int VK_NUMPAD6 = 0x66; - public static final int VK_NUMPAD7 = 0x67; - public static final int VK_NUMPAD8 = 0x68; - public static final int VK_NUMPAD9 = 0x69; - public static final int VK_MULTIPLY = 0x6A; - public static final int VK_ADD = 0x6B; + public static final short VK_CLOSE_BRACKET = (short) 0x5D; + + public static final short VK_NUMPAD0 = (short) 0x60; + public static final short VK_NUMPAD1 = (short) 0x61; + public static final short VK_NUMPAD2 = (short) 0x62; + public static final short VK_NUMPAD3 = (short) 0x63; + public static final short VK_NUMPAD4 = (short) 0x64; + public static final short VK_NUMPAD5 = (short) 0x65; + public static final short VK_NUMPAD6 = (short) 0x66; + public static final short VK_NUMPAD7 = (short) 0x67; + public static final short VK_NUMPAD8 = (short) 0x68; + public static final short VK_NUMPAD9 = (short) 0x69; + public static final short VK_MULTIPLY = (short) 0x6A; + public static final short VK_ADD = (short) 0x6B; /** * Constant for the Numpad Separator key. */ - public static final int VK_SEPARATOR = 0x6C; + public static final short VK_SEPARATOR = (short) 0x6C; - public static final int VK_SUBTRACT = 0x6D; - public static final int VK_DECIMAL = 0x6E; - public static final int VK_DIVIDE = 0x6F; - public static final int VK_DELETE = 0x7F; /* ASCII DEL */ - public static final int VK_NUM_LOCK = 0x90; - public static final int VK_SCROLL_LOCK = 0x91; + public static final short VK_SUBTRACT = (short) 0x6D; + public static final short VK_DECIMAL = (short) 0x6E; + public static final short VK_DIVIDE = (short) 0x6F; + public static final short VK_DELETE = (short) 0x7F; /* ASCII DEL */ + public static final short VK_NUM_LOCK = (short) 0x90; + public static final short VK_SCROLL_LOCK = (short) 0x91; /** Constant for the F1 function key. */ - public static final int VK_F1 = 0x70; + public static final short VK_F1 = (short) 0x70; /** Constant for the F2 function key. */ - public static final int VK_F2 = 0x71; + public static final short VK_F2 = (short) 0x71; /** Constant for the F3 function key. */ - public static final int VK_F3 = 0x72; + public static final short VK_F3 = (short) 0x72; /** Constant for the F4 function key. */ - public static final int VK_F4 = 0x73; + public static final short VK_F4 = (short) 0x73; /** Constant for the F5 function key. */ - public static final int VK_F5 = 0x74; + public static final short VK_F5 = (short) 0x74; /** Constant for the F6 function key. */ - public static final int VK_F6 = 0x75; + public static final short VK_F6 = (short) 0x75; /** Constant for the F7 function key. */ - public static final int VK_F7 = 0x76; + public static final short VK_F7 = (short) 0x76; /** Constant for the F8 function key. */ - public static final int VK_F8 = 0x77; + public static final short VK_F8 = (short) 0x77; /** Constant for the F9 function key. */ - public static final int VK_F9 = 0x78; + public static final short VK_F9 = (short) 0x78; /** Constant for the F10 function key. */ - public static final int VK_F10 = 0x79; + public static final short VK_F10 = (short) 0x79; /** Constant for the F11 function key. */ - public static final int VK_F11 = 0x7A; + public static final short VK_F11 = (short) 0x7A; /** Constant for the F12 function key. */ - public static final int VK_F12 = 0x7B; + public static final short VK_F12 = (short) 0x7B; /** * Constant for the F13 function key. * <p>F13 - F24 are used on IBM 3270 keyboard; use random range for constants.</p> */ - public static final int VK_F13 = 0xF000; + public static final short VK_F13 = (short) 0xF000; /** * Constant for the F14 function key. * <p>F13 - F24 are used on IBM 3270 keyboard; use random range for constants.</p> */ - public static final int VK_F14 = 0xF001; + public static final short VK_F14 = (short) 0xF001; /** * Constant for the F15 function key. * <p>F13 - F24 are used on IBM 3270 keyboard; use random range for constants.</p> */ - public static final int VK_F15 = 0xF002; + public static final short VK_F15 = (short) 0xF002; /** * Constant for the F16 function key. * <p>F13 - F24 are used on IBM 3270 keyboard; use random range for constants.</p> */ - public static final int VK_F16 = 0xF003; + public static final short VK_F16 = (short) 0xF003; /** * Constant for the F17 function key. * <p>F13 - F24 are used on IBM 3270 keyboard; use random range for constants.</p> */ - public static final int VK_F17 = 0xF004; + public static final short VK_F17 = (short) 0xF004; /** * Constant for the F18 function key. * <p>F13 - F24 are used on IBM 3270 keyboard; use random range for constants.</p> */ - public static final int VK_F18 = 0xF005; + public static final short VK_F18 = (short) 0xF005; /** * Constant for the F19 function key. * <p>F13 - F24 are used on IBM 3270 keyboard; use random range for constants.</p> */ - public static final int VK_F19 = 0xF006; + public static final short VK_F19 = (short) 0xF006; /** * Constant for the F20 function key. * <p>F13 - F24 are used on IBM 3270 keyboard; use random range for constants.</p> */ - public static final int VK_F20 = 0xF007; + public static final short VK_F20 = (short) 0xF007; /** * Constant for the F21 function key. * <p>F13 - F24 are used on IBM 3270 keyboard; use random range for constants.</p> */ - public static final int VK_F21 = 0xF008; + public static final short VK_F21 = (short) 0xF008; /** * Constant for the F22 function key. * <p>F13 - F24 are used on IBM 3270 keyboard; use random range for constants.</p> */ - public static final int VK_F22 = 0xF009; + public static final short VK_F22 = (short) 0xF009; /** * Constant for the F23 function key. * <p>F13 - F24 are used on IBM 3270 keyboard; use random range for constants.</p> */ - public static final int VK_F23 = 0xF00A; + public static final short VK_F23 = (short) 0xF00A; /** * Constant for the F24 function key. * <p>F13 - F24 are used on IBM 3270 keyboard; use random range for constants.</p> */ - public static final int VK_F24 = 0xF00B; + public static final short VK_F24 = (short) 0xF00B; - public static final int VK_PRINTSCREEN = 0x9A; - public static final int VK_INSERT = 0x9B; - public static final int VK_HELP = 0x9C; - public static final int VK_META = 0x9D; + public static final short VK_PRINTSCREEN = (short) 0x9A; + public static final short VK_INSERT = (short) 0x9B; + public static final short VK_HELP = (short) 0x9C; + public static final short VK_META = (short) 0x9D; - public static final int VK_BACK_QUOTE = 0xC0; - public static final int VK_QUOTE = 0xDE; + public static final short VK_BACK_QUOTE = (short) 0xC0; + public static final short VK_QUOTE = (short) 0xDE; /** * Constant for the numeric keypad <b>up</b> arrow key. * @see #VK_UP */ - public static final int VK_KP_UP = 0xE0; + public static final short VK_KP_UP = (short) 0xE0; /** * Constant for the numeric keypad <b>down</b> arrow key. * @see #VK_DOWN */ - public static final int VK_KP_DOWN = 0xE1; + public static final short VK_KP_DOWN = (short) 0xE1; /** * Constant for the numeric keypad <b>left</b> arrow key. * @see #VK_LEFT */ - public static final int VK_KP_LEFT = 0xE2; + public static final short VK_KP_LEFT = (short) 0xE2; /** * Constant for the numeric keypad <b>right</b> arrow key. * @see #VK_RIGHT */ - public static final int VK_KP_RIGHT = 0xE3; + public static final short VK_KP_RIGHT = (short) 0xE3; /** For European keyboards */ - public static final int VK_DEAD_GRAVE = 0x80; + public static final short VK_DEAD_GRAVE = (short) 0x80; /** For European keyboards */ - public static final int VK_DEAD_ACUTE = 0x81; + public static final short VK_DEAD_ACUTE = (short) 0x81; /** For European keyboards */ - public static final int VK_DEAD_CIRCUMFLEX = 0x82; + public static final short VK_DEAD_CIRCUMFLEX = (short) 0x82; /** For European keyboards */ - public static final int VK_DEAD_TILDE = 0x83; + public static final short VK_DEAD_TILDE = (short) 0x83; /** For European keyboards */ - public static final int VK_DEAD_MACRON = 0x84; + public static final short VK_DEAD_MACRON = (short) 0x84; /** For European keyboards */ - public static final int VK_DEAD_BREVE = 0x85; + public static final short VK_DEAD_BREVE = (short) 0x85; /** For European keyboards */ - public static final int VK_DEAD_ABOVEDOT = 0x86; + public static final short VK_DEAD_ABOVEDOT = (short) 0x86; /** For European keyboards */ - public static final int VK_DEAD_DIAERESIS = 0x87; + public static final short VK_DEAD_DIAERESIS = (short) 0x87; /** For European keyboards */ - public static final int VK_DEAD_ABOVERING = 0x88; + public static final short VK_DEAD_ABOVERING = (short) 0x88; /** For European keyboards */ - public static final int VK_DEAD_DOUBLEACUTE = 0x89; + public static final short VK_DEAD_DOUBLEACUTE = (short) 0x89; /** For European keyboards */ - public static final int VK_DEAD_CARON = 0x8a; + public static final short VK_DEAD_CARON = (short) 0x8a; /** For European keyboards */ - public static final int VK_DEAD_CEDILLA = 0x8b; + public static final short VK_DEAD_CEDILLA = (short) 0x8b; /** For European keyboards */ - public static final int VK_DEAD_OGONEK = 0x8c; + public static final short VK_DEAD_OGONEK = (short) 0x8c; /** For European keyboards */ - public static final int VK_DEAD_IOTA = 0x8d; + public static final short VK_DEAD_IOTA = (short) 0x8d; /** For European keyboards */ - public static final int VK_DEAD_VOICED_SOUND = 0x8e; + public static final short VK_DEAD_VOICED_SOUND = (short) 0x8e; /** For European keyboards */ - public static final int VK_DEAD_SEMIVOICED_SOUND = 0x8f; + public static final short VK_DEAD_SEMIVOICED_SOUND = (short) 0x8f; /** For European keyboards */ - public static final int VK_AMPERSAND = 0x96; + public static final short VK_AMPERSAND = (short) 0x96; /** For European keyboards */ - public static final int VK_ASTERISK = 0x97; + public static final short VK_ASTERISK = (short) 0x97; /** For European keyboards */ - public static final int VK_QUOTEDBL = 0x98; + public static final short VK_QUOTEDBL = (short) 0x98; /** For European keyboards */ - public static final int VK_LESS = 0x99; + public static final short VK_LESS = (short) 0x99; /** For European keyboards */ - public static final int VK_GREATER = 0xa0; + public static final short VK_GREATER = (short) 0xa0; /** For European keyboards */ - public static final int VK_BRACELEFT = 0xa1; + public static final short VK_BRACELEFT = (short) 0xa1; /** For European keyboards */ - public static final int VK_BRACERIGHT = 0xa2; + public static final short VK_BRACERIGHT = (short) 0xa2; /** * Constant for the "@" key. */ - public static final int VK_AT = 0x0200; + public static final short VK_AT = (short) 0x0200; /** * Constant for the ":" key. */ - public static final int VK_COLON = 0x0201; + public static final short VK_COLON = (short) 0x0201; /** * Constant for the "^" key. */ - public static final int VK_CIRCUMFLEX = 0x0202; + public static final short VK_CIRCUMFLEX = (short) 0x0202; /** * Constant for the "$" key. */ - public static final int VK_DOLLAR = 0x0203; + public static final short VK_DOLLAR = (short) 0x0203; /** * Constant for the Euro currency sign key. */ - public static final int VK_EURO_SIGN = 0x0204; + public static final short VK_EURO_SIGN = (short) 0x0204; /** * Constant for the "!" key. */ - public static final int VK_EXCLAMATION_MARK = 0x0205; + public static final short VK_EXCLAMATION_MARK = (short) 0x0205; /** * Constant for the inverted exclamation mark key. */ - public static final int VK_INVERTED_EXCLAMATION_MARK = 0x0206; + public static final short VK_INVERTED_EXCLAMATION_MARK = (short) 0x0206; /** * Constant for the "(" key. */ - public static final int VK_LEFT_PARENTHESIS = 0x0207; + public static final short VK_LEFT_PARENTHESIS = (short) 0x0207; /** * Constant for the "#" key. */ - public static final int VK_NUMBER_SIGN = 0x0208; + public static final short VK_NUMBER_SIGN = (short) 0x0208; /** * Constant for the "+" key. */ - public static final int VK_PLUS = 0x0209; + public static final short VK_PLUS = (short) 0x0209; /** * Constant for the ")" key. */ - public static final int VK_RIGHT_PARENTHESIS = 0x020A; + public static final short VK_RIGHT_PARENTHESIS = (short) 0x020A; /** * Constant for the "_" key. */ - public static final int VK_UNDERSCORE = 0x020B; + public static final short VK_UNDERSCORE = (short) 0x020B; /** * Constant for the Microsoft Windows "Windows" key. * It is used for both the left and right version of the key. */ - public static final int VK_WINDOWS = 0x020C; + public static final short VK_WINDOWS = (short) 0x020C; /** * Constant for the Microsoft Windows Context Menu key. */ - public static final int VK_CONTEXT_MENU = 0x020D; + public static final short VK_CONTEXT_MENU = (short) 0x020D; /* for input method support on Asian Keyboards */ /* not clear what this means - listed in Microsoft Windows API */ - public static final int VK_FINAL = 0x0018; + public static final short VK_FINAL = (short) 0x0018; /** Constant for the Convert function key. */ /* Japanese PC 106 keyboard, Japanese Solaris keyboard: henkan */ - public static final int VK_CONVERT = 0x001C; + public static final short VK_CONVERT = (short) 0x001C; /** Constant for the Don't Convert function key. */ /* Japanese PC 106 keyboard: muhenkan */ - public static final int VK_NONCONVERT = 0x001D; + public static final short VK_NONCONVERT = (short) 0x001D; /** Constant for the Accept or Commit function key. */ /* Japanese Solaris keyboard: kakutei */ - public static final int VK_ACCEPT = 0x001E; + public static final short VK_ACCEPT = (short) 0x001E; /* not clear what this means - listed in Microsoft Windows API */ - public static final int VK_MODECHANGE = 0x001F; + public static final short VK_MODECHANGE = (short) 0x001F; /* replaced by VK_KANA_LOCK for Microsoft Windows and Solaris; might still be used on other platforms */ - public static final int VK_KANA = 0x0015; + public static final short VK_KANA = (short) 0x0015; /* replaced by VK_INPUT_METHOD_ON_OFF for Microsoft Windows and Solaris; might still be used for other platforms */ - public static final int VK_KANJI = 0x0019; + public static final short VK_KANJI = (short) 0x0019; /** * Constant for the Alphanumeric function key. */ /* Japanese PC 106 keyboard: eisuu */ - public static final int VK_ALPHANUMERIC = 0x00F0; + public static final short VK_ALPHANUMERIC = (short) 0x00F0; /** * Constant for the Katakana function key. */ /* Japanese PC 106 keyboard: katakana */ - public static final int VK_KATAKANA = 0x00F1; + public static final short VK_KATAKANA = (short) 0x00F1; /** * Constant for the Hiragana function key. */ /* Japanese PC 106 keyboard: hiragana */ - public static final int VK_HIRAGANA = 0x00F2; + public static final short VK_HIRAGANA = (short) 0x00F2; /** * Constant for the Full-Width Characters function key. */ /* Japanese PC 106 keyboard: zenkaku */ - public static final int VK_FULL_WIDTH = 0x00F3; + public static final short VK_FULL_WIDTH = (short) 0x00F3; /** * Constant for the Half-Width Characters function key. */ /* Japanese PC 106 keyboard: hankaku */ - public static final int VK_HALF_WIDTH = 0x00F4; + public static final short VK_HALF_WIDTH = (short) 0x00F4; /** * Constant for the Roman Characters function key. */ /* Japanese PC 106 keyboard: roumaji */ - public static final int VK_ROMAN_CHARACTERS = 0x00F5; + public static final short VK_ROMAN_CHARACTERS = (short) 0x00F5; /** * Constant for the All Candidates function key. */ /* Japanese PC 106 keyboard - VK_CONVERT + ALT: zenkouho */ - public static final int VK_ALL_CANDIDATES = 0x0100; + public static final short VK_ALL_CANDIDATES = (short) 0x0100; /** * Constant for the Previous Candidate function key. */ /* Japanese PC 106 keyboard - VK_CONVERT + SHIFT: maekouho */ - public static final int VK_PREVIOUS_CANDIDATE = 0x0101; + public static final short VK_PREVIOUS_CANDIDATE = (short) 0x0101; /** * Constant for the Code Input function key. */ /* Japanese PC 106 keyboard - VK_ALPHANUMERIC + ALT: kanji bangou */ - public static final int VK_CODE_INPUT = 0x0102; + public static final short VK_CODE_INPUT = (short) 0x0102; /** * Constant for the Japanese-Katakana function key. * This key switches to a Japanese input method and selects its Katakana input mode. */ /* Japanese Macintosh keyboard - VK_JAPANESE_HIRAGANA + SHIFT */ - public static final int VK_JAPANESE_KATAKANA = 0x0103; + public static final short VK_JAPANESE_KATAKANA = (short) 0x0103; /** * Constant for the Japanese-Hiragana function key. * This key switches to a Japanese input method and selects its Hiragana input mode. */ /* Japanese Macintosh keyboard */ - public static final int VK_JAPANESE_HIRAGANA = 0x0104; + public static final short VK_JAPANESE_HIRAGANA = (short) 0x0104; /** * Constant for the Japanese-Roman function key. * This key switches to a Japanese input method and selects its Roman-Direct input mode. */ /* Japanese Macintosh keyboard */ - public static final int VK_JAPANESE_ROMAN = 0x0105; + public static final short VK_JAPANESE_ROMAN = (short) 0x0105; /** * Constant for the locking Kana function key. * This key locks the keyboard into a Kana layout. */ /* Japanese PC 106 keyboard with special Windows driver - eisuu + Control; Japanese Solaris keyboard: kana */ - public static final int VK_KANA_LOCK = 0x0106; + public static final short VK_KANA_LOCK = (short) 0x0106; /** * Constant for the input method on/off key. */ /* Japanese PC 106 keyboard: kanji. Japanese Solaris keyboard: nihongo */ - public static final int VK_INPUT_METHOD_ON_OFF = 0x0107; + public static final short VK_INPUT_METHOD_ON_OFF = (short) 0x0107; /* for Sun keyboards */ - public static final int VK_CUT = 0xFFD1; - public static final int VK_COPY = 0xFFCD; - public static final int VK_PASTE = 0xFFCF; - public static final int VK_UNDO = 0xFFCB; - public static final int VK_AGAIN = 0xFFC9; - public static final int VK_FIND = 0xFFD0; - public static final int VK_PROPS = 0xFFCA; - public static final int VK_STOP = 0xFFC8; + public static final short VK_CUT = (short) 0xFFD1; + public static final short VK_COPY = (short) 0xFFCD; + public static final short VK_PASTE = (short) 0xFFCF; + public static final short VK_UNDO = (short) 0xFFCB; + public static final short VK_AGAIN = (short) 0xFFC9; + public static final short VK_FIND = (short) 0xFFD0; + public static final short VK_PROPS = (short) 0xFFCA; + public static final short VK_STOP = (short) 0xFFC8; /** * Constant for the Compose function key. */ - public static final int VK_COMPOSE = 0xFF20; + public static final short VK_COMPOSE = (short) 0xFF20; /** * Constant for the AltGraph function key. */ - public static final int VK_ALT_GRAPH = 0xFF7E; + public static final short VK_ALT_GRAPH = (short) 0xFF7E; /** * Constant for the Begin key. */ - public static final int VK_BEGIN = 0xFF58; + public static final short VK_BEGIN = (short) 0xFF58; /** * This value is used to indicate that the keyCode is unknown. * KEY_TYPED events do not have a keyCode value; this value * is used instead. */ - public static final int VK_UNDEFINED = 0x0; + public static final short VK_UNDEFINED = (short) 0x0; } diff --git a/src/newt/classes/com/jogamp/newt/event/KeyListener.java b/src/newt/classes/com/jogamp/newt/event/KeyListener.java index dae343d80..5bca733d3 100644 --- a/src/newt/classes/com/jogamp/newt/event/KeyListener.java +++ b/src/newt/classes/com/jogamp/newt/event/KeyListener.java @@ -34,10 +34,22 @@ package com.jogamp.newt.event; +/** + * Listener for {@link KeyEvent}s. + * + * @see KeyEvent + */ public interface KeyListener extends NEWTEventListener { - public void keyPressed(KeyEvent e); - public void keyReleased(KeyEvent e); - public void keyTyped(KeyEvent e) ; + /** A key has been {@link KeyEvent#EVENT_KEY_PRESSED pressed}, excluding {@link #isAutoRepeat() auto-repeat} {@link #isModifierKey() modifier} keys. See {@link KeyEvent}. */ + public void keyPressed(KeyEvent e); + /** A key has been {@link KeyEvent#EVENT_KEY_RELEASED released}, excluding {@link #isAutoRepeat() auto-repeat} {@link #isModifierKey() modifier} keys. See {@link KeyEvent}. */ + public void keyReleased(KeyEvent e); + + /** + * A {@link #isPrintableKey() printable} key has been {@link KeyEvent#EVENT_KEY_TYPED typed} (pressed and released), excluding {@link #isAutoRepeat() auto-repeat}. See {@link KeyEvent}. + * @deprecated Redundant, will be removed soon. Use {@link #keyReleased(KeyEvent)} and exclude non {@link #isPrintableKey() printable} keys and {@link #isAutoRepeat() auto-repeat}. + */ + public void keyTyped(KeyEvent e) ; } diff --git a/src/newt/classes/com/jogamp/newt/event/MouseEvent.java b/src/newt/classes/com/jogamp/newt/event/MouseEvent.java index e6b3d8a24..23549533e 100644 --- a/src/newt/classes/com/jogamp/newt/event/MouseEvent.java +++ b/src/newt/classes/com/jogamp/newt/event/MouseEvent.java @@ -38,47 +38,47 @@ package com.jogamp.newt.event; public class MouseEvent extends InputEvent { /** ID for button 1, value <code>1</code> */ - public static final int BUTTON1 = 1; + public static final short BUTTON1 = 1; /** ID for button 2, value <code>2</code> */ - public static final int BUTTON2 = 2; + public static final short BUTTON2 = 2; /** ID for button 3, value <code>3</code> */ - public static final int BUTTON3 = 3; + public static final short BUTTON3 = 3; /** ID for button 4, value <code>4</code> */ - public static final int BUTTON4 = 4; + public static final short BUTTON4 = 4; /** ID for button 5, value <code>5</code> */ - public static final int BUTTON5 = 5; + public static final short BUTTON5 = 5; /** ID for button 6, value <code>6</code> */ - public static final int BUTTON6 = 6; + public static final short BUTTON6 = 6; /** ID for button 6, value <code>7</code> */ - public static final int BUTTON7 = 7; + public static final short BUTTON7 = 7; /** ID for button 6, value <code>8</code> */ - public static final int BUTTON8 = 8; + public static final short BUTTON8 = 8; /** ID for button 6, value <code>9</code> */ - public static final int BUTTON9 = 9; + public static final short BUTTON9 = 9; /** Maximum number of buttons, value <code>16</code> */ - public static final int BUTTON_NUMBER = 16; + public static final short BUTTON_NUMBER = 16; - public static final int getClickTimeout() { + public static final short getClickTimeout() { return 300; } - public MouseEvent(int eventType, Object source, long when, - int modifiers, int x, int y, int clickCount, int button, + public MouseEvent(short eventType, Object source, long when, + int modifiers, int x, int y, short clickCount, short button, float rotation) { super(eventType, source, when, modifiers); this.x = new int[]{x}; this.y = new int[]{y}; this.pressure = new float[]{0}; - this.pointerids = new int[]{-1}; + this.pointerids = new short[]{-1}; this.clickCount=clickCount; this.button=button; this.wheelRotation = rotation; } - public MouseEvent(int eventType, Object source, long when, - int modifiers, int[] x, int[] y, float[] pressure, int[] pointerids, int clickCount, int button, + public MouseEvent(short eventType, Object source, long when, + int modifiers, int[] x, int[] y, float[] pressure, short[] pointerids, short clickCount, short button, float rotation) { super(eventType, source, when, modifiers); @@ -107,17 +107,17 @@ public class MouseEvent extends InputEvent * @return the pointer id for the data at index. * return -1 if index not available. */ - public int getPointerId(int index) { + public short getPointerId(int index) { if(index >= pointerids.length) return -1; return pointerids[index]; } - public int getButton() { + public short getButton() { return button; } - public int getClickCount() { + public short getClickCount() { return clickCount; } public int getX() { @@ -208,7 +208,7 @@ public class MouseEvent extends InputEvent return super.toString(sb).append("]"); } - public static String getEventTypeString(int type) { + public static String getEventTypeString(short type) { switch(type) { case EVENT_MOUSE_CLICKED: return "EVENT_MOUSE_CLICKED"; case EVENT_MOUSE_ENTERED: return "EVENT_MOUSE_ENTERED"; @@ -221,17 +221,18 @@ public class MouseEvent extends InputEvent default: return "unknown (" + type + ")"; } } - private final int x[], y[], clickCount, button; + private final int x[], y[];; + private final short clickCount, button; private final float wheelRotation; private final float pressure[]; - private final int pointerids[]; + private final short pointerids[]; - public static final int EVENT_MOUSE_CLICKED = 200; - public static final int EVENT_MOUSE_ENTERED = 201; - public static final int EVENT_MOUSE_EXITED = 202; - public static final int EVENT_MOUSE_PRESSED = 203; - public static final int EVENT_MOUSE_RELEASED = 204; - public static final int EVENT_MOUSE_MOVED = 205; - public static final int EVENT_MOUSE_DRAGGED = 206; - public static final int EVENT_MOUSE_WHEEL_MOVED = 207; + public static final short EVENT_MOUSE_CLICKED = 200; + public static final short EVENT_MOUSE_ENTERED = 201; + public static final short EVENT_MOUSE_EXITED = 202; + public static final short EVENT_MOUSE_PRESSED = 203; + public static final short EVENT_MOUSE_RELEASED = 204; + public static final short EVENT_MOUSE_MOVED = 205; + public static final short EVENT_MOUSE_DRAGGED = 206; + public static final short EVENT_MOUSE_WHEEL_MOVED = 207; } diff --git a/src/newt/classes/com/jogamp/newt/event/NEWTEvent.java b/src/newt/classes/com/jogamp/newt/event/NEWTEvent.java index 9d8d92ff6..6f4561ce6 100644 --- a/src/newt/classes/com/jogamp/newt/event/NEWTEvent.java +++ b/src/newt/classes/com/jogamp/newt/event/NEWTEvent.java @@ -48,81 +48,27 @@ package com.jogamp.newt.event; */ @SuppressWarnings("serial") public class NEWTEvent extends java.util.EventObject { - private final boolean isSystemEvent; - private final int eventType; + /** + * 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. + */ + public static final Object consumedTag = new Object(); + + private final short eventType; private final long when; private Object attachment; static final boolean DEBUG = false; - // 0: NEWTEvent.java - // 1: InputEvent.java - // 2: KeyEvent.java - // 3: com.jogamp.newt.Window - // 3: com.jogamp.newt.event.awt.AWTNewtEventFactory - // 2: MouseEvent.java - // 3: com.jogamp.newt.Window - // 3: com.jogamp.newt.event.awt.AWTNewtEventFactory - // 1: WindowEvent.java - // 2: com.jogamp.newt.Window - // 2: com.jogamp.newt.event.awt.AWTNewtEventFactory - // - // FIXME: verify the isSystemEvent evaluation - // - static final String WindowClazzName = "com.jogamp.newt.Window" ; - static final String AWTNewtEventFactoryClazzName = "com.jogamp.newt.event.awt.AWTNewtEventFactory" ; - - /** - static final boolean evaluateIsSystemEvent(NEWTEvent event, Throwable t) { - StackTraceElement[] stack = t.getStackTrace(); - if(stack.length==0 || null==stack[0]) { - return false; - } - if(DEBUG) { - for (int i = 0; i < stack.length && i<5; i++) { - System.err.println(i+": " + stack[i].getClassName()+ "." + stack[i].getMethodName()); - } - } - - String clazzName = null; - - if( event instanceof com.jogamp.newt.event.WindowEvent ) { - if ( stack.length > 2 ) { - clazzName = stack[2].getClassName(); - } - } else if( (event instanceof com.jogamp.newt.event.MouseEvent) || - (event instanceof com.jogamp.newt.event.KeyEvent) ) { - if ( stack.length > 3 ) { - clazzName = stack[3].getClassName(); - } - } - - boolean res = null!=clazzName && ( - clazzName.equals(WindowClazzName) || - clazzName.equals(AWTNewtEventFactoryClazzName) ) ; - if(DEBUG) { - System.err.println("system: "+res); - } - return res; - } */ - - protected NEWTEvent(int eventType, Object source, long when) { + protected NEWTEvent(short eventType, Object source, long when) { super(source); - // this.isSystemEvent = evaluateIsSystemEvent(this, new Throwable()); - this.isSystemEvent = false; // FIXME: Need a more efficient way to determine system events this.eventType = eventType; this.when = when; this.attachment=null; } - /** Indicates whether this event was produced by the system or - generated by user code. */ - public final boolean isSystemEvent() { - return isSystemEvent; - } - /** Returns the event type of this event. */ - public final int getEventType() { + public final short getEventType() { return eventType; } @@ -158,10 +104,10 @@ public class NEWTEvent extends java.util.EventObject { if(null == sb) { sb = new StringBuilder(); } - return sb.append("NEWTEvent[sys:").append(isSystemEvent()).append(", source:").append(getSource().getClass().getName()).append(", when:").append(getWhen()).append(" d ").append((System.currentTimeMillis()-getWhen())).append("ms]"); + return sb.append("NEWTEvent[source:").append(getSource().getClass().getName()).append(", when:").append(getWhen()).append(" d ").append((System.currentTimeMillis()-getWhen())).append("ms]"); } - static String toHexString(int hex) { - return "0x" + Integer.toHexString(hex); + static String toHexString(short hex) { + return "0x" + Integer.toHexString( (int)hex & 0x0000FFFF ); } } diff --git a/src/newt/classes/com/jogamp/newt/event/WindowEvent.java b/src/newt/classes/com/jogamp/newt/event/WindowEvent.java index 163b51439..24b3b380a 100644 --- a/src/newt/classes/com/jogamp/newt/event/WindowEvent.java +++ b/src/newt/classes/com/jogamp/newt/event/WindowEvent.java @@ -41,19 +41,19 @@ package com.jogamp.newt.event; */ @SuppressWarnings("serial") public class WindowEvent extends NEWTEvent { - public static final int EVENT_WINDOW_RESIZED = 100; - public static final int EVENT_WINDOW_MOVED = 101; - public static final int EVENT_WINDOW_DESTROY_NOTIFY = 102; - public static final int EVENT_WINDOW_GAINED_FOCUS = 103; - public static final int EVENT_WINDOW_LOST_FOCUS = 104; - public static final int EVENT_WINDOW_REPAINT = 105; - public static final int EVENT_WINDOW_DESTROYED = 106; + public static final short EVENT_WINDOW_RESIZED = 100; + public static final short EVENT_WINDOW_MOVED = 101; + public static final short EVENT_WINDOW_DESTROY_NOTIFY = 102; + public static final short EVENT_WINDOW_GAINED_FOCUS = 103; + public static final short EVENT_WINDOW_LOST_FOCUS = 104; + public static final short EVENT_WINDOW_REPAINT = 105; + public static final short EVENT_WINDOW_DESTROYED = 106; - public WindowEvent(int eventType, Object source, long when) { + public WindowEvent(short eventType, Object source, long when) { super(eventType, source, when); } - public static String getEventTypeString(int type) { + public static String getEventTypeString(short type) { switch(type) { case EVENT_WINDOW_RESIZED: return "WINDOW_RESIZED"; case EVENT_WINDOW_MOVED: return "WINDOW_MOVED"; diff --git a/src/newt/classes/com/jogamp/newt/event/WindowListener.java b/src/newt/classes/com/jogamp/newt/event/WindowListener.java index 011e1f654..dde182510 100644 --- a/src/newt/classes/com/jogamp/newt/event/WindowListener.java +++ b/src/newt/classes/com/jogamp/newt/event/WindowListener.java @@ -36,6 +36,7 @@ package com.jogamp.newt.event; import javax.media.nativewindow.WindowClosingProtocol; +/** NEWT {@link WindowEvent} listener. */ public interface WindowListener extends NEWTEventListener { /** Window is resized, your application shall respect the new window dimension. A repaint is recommended. */ public void windowResized(WindowEvent e); @@ -53,7 +54,9 @@ public interface WindowListener extends NEWTEventListener { **/ public void windowDestroyNotify(WindowEvent e); - /** Window has been destroyed.*/ + /** + * Window has been destroyed. + */ public void windowDestroyed(WindowEvent e); /** Window gained focus. */ diff --git a/src/newt/classes/com/jogamp/newt/event/WindowUpdateEvent.java b/src/newt/classes/com/jogamp/newt/event/WindowUpdateEvent.java index e3f0373ec..a0f6e2cb4 100644 --- a/src/newt/classes/com/jogamp/newt/event/WindowUpdateEvent.java +++ b/src/newt/classes/com/jogamp/newt/event/WindowUpdateEvent.java @@ -34,7 +34,7 @@ import javax.media.nativewindow.util.Rectangle; public class WindowUpdateEvent extends WindowEvent { final Rectangle bounds; - public WindowUpdateEvent(int eventType, Object source, long when, Rectangle bounds) + public WindowUpdateEvent(short eventType, Object source, long when, Rectangle bounds) { super(eventType, source, when); this.bounds = bounds; 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 8991203d5..6de2eee45 100644 --- a/src/newt/classes/com/jogamp/newt/event/awt/AWTAdapter.java +++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTAdapter.java @@ -181,8 +181,13 @@ public abstract class AWTAdapter implements java.util.EventListener /** @see #addTo(java.awt.Component) */ public abstract AWTAdapter removeFrom(java.awt.Component awtComponent); + /** + * Enqueues the event to the {@link #getNewtWindow()} is not null. + */ void enqueueEvent(boolean wait, com.jogamp.newt.event.NEWTEvent event) { - newtWindow.enqueueEvent(wait, event); + if( null != newtWindow ) { + newtWindow.enqueueEvent(wait, event); + } } } 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 64071eed6..1edef347b 100644 --- a/src/newt/classes/com/jogamp/newt/event/awt/AWTKeyAdapter.java +++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTKeyAdapter.java @@ -72,14 +72,11 @@ public class AWTKeyAdapter extends AWTAdapter implements java.awt.event.KeyListe @Override public void keyReleased(java.awt.event.KeyEvent e) { com.jogamp.newt.event.KeyEvent keyReleaseEvt = AWTNewtEventFactory.createKeyEvent(com.jogamp.newt.event.KeyEvent.EVENT_KEY_RELEASED, e, newtWindow); - com.jogamp.newt.event.KeyEvent keyTypedEvt = AWTNewtEventFactory.createKeyEvent(com.jogamp.newt.event.KeyEvent.EVENT_KEY_TYPED, e, newtWindow); if(null!=newtListener) { final com.jogamp.newt.event.KeyListener newtKeyListener = (com.jogamp.newt.event.KeyListener)newtListener; newtKeyListener.keyReleased(keyReleaseEvt); - newtKeyListener.keyTyped(keyTypedEvt); } else { enqueueEvent(false, keyReleaseEvt); - enqueueEvent(false, keyTypedEvt); } } 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 2d63ca455..e91bb2f82 100644 --- a/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java +++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java @@ -66,13 +66,18 @@ public class AWTWindowAdapter return this; } - public AWTAdapter removeFrom(java.awt.Component awtComponent) { - awtComponent.removeFocusListener(this); - awtComponent.removeComponentListener(this); + public AWTAdapter removeWindowClosingFrom(java.awt.Component awtComponent) { java.awt.Window win = getWindow(awtComponent); if( null != win && null != windowClosingListener ) { win.removeWindowListener(windowClosingListener); } + return this; + } + + public AWTAdapter removeFrom(java.awt.Component awtComponent) { + awtComponent.removeFocusListener(this); + awtComponent.removeComponentListener(this); + removeWindowClosingFrom(awtComponent); if(awtComponent instanceof java.awt.Window) { ((java.awt.Window)awtComponent).removeWindowListener(this); } @@ -220,9 +225,16 @@ public class AWTWindowAdapter enqueueEvent(true, event); } } + public void windowClosed(java.awt.event.WindowEvent e) { + com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow); + if(null!=newtListener) { + ((com.jogamp.newt.event.WindowListener)newtListener).windowDestroyed(event); + } else { + enqueueEvent(true, event); + } + } public void windowActivated(java.awt.event.WindowEvent e) { } - public void windowClosed(java.awt.event.WindowEvent e) { } public void windowDeactivated(java.awt.event.WindowEvent e) { } public void windowDeiconified(java.awt.event.WindowEvent e) { } public void windowIconified(java.awt.event.WindowEvent e) { } diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java index 7fccb6622..ce50d95dd 100644 --- a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java +++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java @@ -100,7 +100,10 @@ public class GLWindow extends GLAutoDrawableBase implements GLAutoDrawable, Wind protected GLWindow(Window window) { super(null, null, false /* always handle device lifecycle ourselves */); this.window = (WindowImpl) window; - this.window.setHandleDestroyNotify(false); + this.window.setWindowDestroyNotifyAction( new Runnable() { + public void run() { + defaultWindowDestroyNotifyOp(); + } } ); window.addWindowListener(new WindowAdapter() { @Override public void windowRepaint(WindowUpdateEvent e) { @@ -112,10 +115,6 @@ public class GLWindow extends GLAutoDrawableBase implements GLAutoDrawable, Wind defaultWindowResizedOp(getWidth(), getHeight()); } - @Override - public void windowDestroyNotify(WindowEvent e) { - defaultWindowDestroyNotifyOp(); - } }); this.window.setLifecycleHook(new GLLifecycleHook()); } @@ -390,6 +389,11 @@ public class GLWindow extends GLAutoDrawableBase implements GLAutoDrawable, Wind } @Override + public void setWindowDestroyNotifyAction(Runnable r) { + window.setWindowDestroyNotifyAction(r); + } + + @Override public final void setVisible(boolean visible) { window.setVisible(visible); } |