From 7ec58d773535e86e413e3c581a5e5bd734cb1269 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 23 Dec 2012 23:33:19 +0100 Subject: Fix 13168c99ff9e8bf71c83f1be7afee270a3db4074 / 811e3791b98fea0dfa3b7d301cb532c54df8dc82: AWT-NEWT Modifier mapping - part-2 AWTNewtEventFactory: - getAWTButtonMask() -> getAWTButtonDownMask() - using proper _DOWN_MASK values (regression of commit 13168c99ff9e8bf71c83f1be7afee270a3db4074) - com.jogamp.newt.event.MouseEvent.BUTTON_NUMBER buttons - adding 'ModifierMappings.txt' to API doc header - remove obsolete 'int awtModifiers2Newt(int awtMods, boolean mouseHint)' - 'int awtButton2Newt(int awtButton)' 1:1 button name mapping Tests: - rename TestNewtEventModifiers -> BaseNewtEventModifiers to avoid being picked up by our junit testing framework. The latter tests all classes starting w/ 'Test*' --- .../classes/com/jogamp/newt/event/InputEvent.java | 2 +- .../jogamp/newt/awt/event/AWTNewtEventFactory.java | 205 +++--- .../junit/newt/event/BaseNewtEventModifiers.java | 740 ++++++++++++++++++++ .../test/junit/newt/event/ModifierMappings.txt | 37 - .../junit/newt/event/TestNewtEventModifiers.java | 761 --------------------- .../event/TestNewtEventModifiersAWTCanvas.java | 6 +- .../event/TestNewtEventModifiersNewtCanvasAWT.java | 6 +- .../event/TestNewtEventModifiersNewtCanvasSWT.java | 6 +- 8 files changed, 877 insertions(+), 886 deletions(-) create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/event/BaseNewtEventModifiers.java delete mode 100644 src/test/com/jogamp/opengl/test/junit/newt/event/ModifierMappings.txt delete mode 100644 src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiers.java (limited to 'src') diff --git a/src/newt/classes/com/jogamp/newt/event/InputEvent.java b/src/newt/classes/com/jogamp/newt/event/InputEvent.java index 0122bda9a..ad77ec79f 100644 --- a/src/newt/classes/com/jogamp/newt/event/InputEvent.java +++ b/src/newt/classes/com/jogamp/newt/event/InputEvent.java @@ -70,7 +70,7 @@ public abstract class InputEvent extends NEWTEvent * Returns the corresponding button mask for the given button. *

* In case the given button lies outside - * of the valid range [{@link MouseEvent#BUTTON1} .. {@link MouseEvent#BUTTON6}], + * of the valid range [{@link MouseEvent#BUTTON1} .. {@link MouseEvent#BUTTON_NUMBER}], * null is returned. *

*/ diff --git a/src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java b/src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java index 28174f139..665b7b5ee 100644 --- a/src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java +++ b/src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java @@ -29,29 +29,58 @@ package jogamp.newt.awt.event; import com.jogamp.common.util.IntIntHashMap; -import com.jogamp.newt.event.InputEvent; +/** + * + *
AWT Event Modifier Mapping
+ *
+    Modifier       AWT Constant                     AWT Bit  AWT Ex  NEWT Constant              NEWT Bit
+    -------------  -------------------------------  -------  ------  -------------------------  --------
+    Shift          Event.SHIFT_MASK                 0                
+    Ctrl           Event.CTRL_MASK                  1                
+    Meta           Event.META_MASK                  2                
+    Alt            Event.ALT_MASK                   3               
+    Button1        InputEvent.BUTTON1_MASK          4
+    Button2        InputEvent.BUTTON2_MASK          3
+    Button3        InputEvent.BUTTON3_MASK          2
+    Shift Down     InputEvent.SHIFT_DOWN_MASK       6        *       InputEvent.SHIFT_MASK      0
+    Ctrl Down      InputEvent.CTRL_DOWN_MASK        7        *       InputEvent.CTRL_MASK       1
+    Meta Down      InputEvent.META_DOWN_MASK        8        *       InputEvent.META_MASK       2
+    Alt Down       InputEvent.ALT_DOWN_MASK         9        *       InputEvent.ALT_MASK        3
+    Button1 Down   InputEvent.BUTTON1_DOWN_MASK     10       *       InputEvent.BUTTON1_MASK    5
+    Button2 Down   InputEvent.BUTTON2_DOWN_MASK     11       *       InputEvent.BUTTON2_MASK    6
+    Button3 Down   InputEvent.BUTTON3_DOWN_MASK     12       *       InputEvent.BUTTON3_MASK    7
+    AltGraph Down  InputEvent.ALT_GRAPH_DOWN_MASK   13       *       InputEvent.ALT_GRAPH_MASK  4
+    Button4 Down   --                               14       *       InputEvent.BUTTON4_MASK    8
+    Button5 Down   --                               15       *       InputEvent.BUTTON5_MASK    9
+    Button6 Down   --                               16       *       InputEvent.BUTTON6_MASK    10
+    Button7 Down   --                               17       *       InputEvent.BUTTON7_MASK    11
+    Button8 Down   --                               18       *       InputEvent.BUTTON8_MASK    12
+    Button9 Down   --                               19       *       InputEvent.BUTTON9_MASK    13
+    Button10 Down  --                               20       *                                  14
+    Button11 Down  --                               21       *                                  15
+    Button12 Down  --                               22       *                                  16
+    Button13 Down  --                               23       *                                  17
+    Button14 Down  --                               24       *                                  18
+    Button15 Down  --                               25       *                                  19
+    Button16 Down  --                               26       *       InputEvent.BUTTONLAST_MASK 20
+    Button17 Down  --                               27       *
+    Button18 Down  --                               28       *
+    Button19 Down  --                               29       *
+    Button20 Down  --                               30       *
+    Autorepeat     --                               -                InputEvent.AUTOREPEAT_MASK 29
+    Confined       --                               -                InputEvent.CONFINED_MASK   30
+    Invisible      --                               -                InputEvent.INVISIBLE_MASK  31
+ * 
+ * + */ public class AWTNewtEventFactory { protected static final IntIntHashMap eventTypeAWT2NEWT; - // Define the button state masks we'll check based on what - // the AWT says is available. - private static int awtButtonMasks[] ; - private static int newtButtonMasks[] ; - - public static int getAWTButtonMask(int button) { - // return java.awt.event.InputEvent.getMaskForButton(button); // n/a - int m; - switch(button) { - case 1 : m = java.awt.event.InputEvent.BUTTON1_MASK; break; - case 2 : m = java.awt.event.InputEvent.BUTTON2_MASK; break; - case 3 : m = java.awt.event.InputEvent.BUTTON3_MASK; break; - default: m = 0; - } - return m; - } - + /** zero-based AWT button mask array filled by {@link #getAWTButtonDownMask(int)}, allowing fast lookup. */ + private static int awtButtonDownMasks[] ; + static { IntIntHashMap map = new IntIntHashMap(); map.setKeyNotFoundValue(0xFFFFFFFF); @@ -88,66 +117,77 @@ public class AWTNewtEventFactory { eventTypeAWT2NEWT = map; - final int numButtonMasks ; - - // numButtonMasks = java.awt.MouseInfo.getNumberOfButtons() ; - // if (numButtonMasks > com.jogamp.newt.event.MouseEvent.BUTTON_NUMBER) { - // numButtonMasks = com.jogamp.newt.event.MouseEvent.BUTTON_NUMBER ; - // } - numButtonMasks = 3 ; - // There is an assumption in awtModifiers2Newt(int,int,boolean) // that the awtButtonMasks and newtButtonMasks are peers, i.e. // a given index refers to the same button in each array. - awtButtonMasks = new int[numButtonMasks] ; - for (int n = 0 ; n < awtButtonMasks.length ; ++n) { - awtButtonMasks[n] = getAWTButtonMask(n+1); + /* { + Method _getMaskForButtonMethod = null; + try { + _getMaskForButtonMethod = ReflectionUtil.getMethod(java.awt.event.InputEvent.class, "getMaskForButton", int.class); + } catch(Throwable t) {} + getMaskForButtonMethod = _getMaskForButtonMethod; + } */ + + awtButtonDownMasks = new int[com.jogamp.newt.event.MouseEvent.BUTTON_NUMBER] ; // java.awt.MouseInfo.getNumberOfButtons() ; + for (int n = 0 ; n < awtButtonDownMasks.length ; ++n) { + awtButtonDownMasks[n] = getAWTButtonDownMaskImpl(n+1); } - - newtButtonMasks = new int[numButtonMasks] ; - for (int n = 0 ; n < newtButtonMasks.length ; ++n) { - newtButtonMasks[n] = com.jogamp.newt.event.InputEvent.getButtonMask(n+1) ; - } } - + private static int getAWTButtonDownMaskImpl(int button) { + /** + * java.awt.event.InputEvent.getMaskForButton(button); + * + if(null != getMaskForButtonMethod) { + Object r=null; + try { + r = getMaskForButtonMethod.invoke(null, new Integer(button)); + } catch (Throwable t) { } + if(null != r) { + return ((Integer)r).intValue(); + } + } */ + final int m; + switch(button) { + case 0 : m = 0; break; + case 1 : m = java.awt.event.InputEvent.BUTTON1_DOWN_MASK; break; // 1<<10 + case 2 : m = java.awt.event.InputEvent.BUTTON2_DOWN_MASK; break; // 1<<11 + case 3 : m = java.awt.event.InputEvent.BUTTON3_DOWN_MASK; break; // 1<<12 + default: + if( button <= com.jogamp.newt.event.MouseEvent.BUTTON_NUMBER ) { + m = 1 << ( 10 + button ) ; // b4 = 1<<14, b5 = 1<<15, etc + } else { + m = 0; + } + } + return m; + } + /** - * Converts the specified set of AWT event modifiers to the equivalent - * NEWT event modifiers. This method doesn't pay attention to the AWT - * button modifier bits explicitly even though there is a direct - * association in the AWT InputEvent class between BUTTON2_MASK and - * ALT_MASK, and BUTTON3_MASK and META_MASK. Instead the current - * button state is picked up from the bits in the extended modifiers. - * If you need the button bits too, then call - * {@link #awtModifiers2Newt(int,int,boolean)} instead. + *

+ * See AWT event modifier mapping details. + *

* - * @param awtMods - * The AWT event modifiers. - * - * @param mouseHint - * Not used currently. + * @param button + * @return */ - public static final int awtModifiers2Newt(int awtMods, boolean mouseHint) { - int newtMods = 0; - if ((awtMods & java.awt.event.InputEvent.SHIFT_MASK) != 0) newtMods |= com.jogamp.newt.event.InputEvent.SHIFT_MASK; - if ((awtMods & java.awt.event.InputEvent.CTRL_MASK) != 0) newtMods |= com.jogamp.newt.event.InputEvent.CTRL_MASK; - if ((awtMods & java.awt.event.InputEvent.META_MASK) != 0) newtMods |= com.jogamp.newt.event.InputEvent.META_MASK; - if ((awtMods & java.awt.event.InputEvent.ALT_MASK) != 0) newtMods |= com.jogamp.newt.event.InputEvent.ALT_MASK; - if ((awtMods & java.awt.event.InputEvent.ALT_GRAPH_MASK) != 0) newtMods |= com.jogamp.newt.event.InputEvent.ALT_GRAPH_MASK; - - // The BUTTON1_MASK, BUTTON2_MASK, and BUTTON3_MASK bits are - // being ignored intentionally. The AWT docs say that the - // BUTTON1_DOWN_MASK etc bits in the extended modifiers are - // the preferred place to check current button state. - - return newtMods; + public static int getAWTButtonDownMask(int button) { + if( 0 < button && button <= awtButtonDownMasks.length ) { + return awtButtonDownMasks[button-1]; + } else { + return 0; + } } /** * Converts the specified set of AWT event modifiers and extended event * modifiers to the equivalent NEWT event modifiers. * + *

+ * See AWT event modifier mapping details. + *

+ * * @param awtMods * The AWT event modifiers. * @@ -160,33 +200,42 @@ public class AWTNewtEventFactory { */ public static final int awtModifiers2Newt(final int awtMods, final int awtModsEx, final boolean mouseHint) { int newtMods = 0; + + /** Redundant old modifiers .. + if ((awtMods & java.awt.event.InputEvent.SHIFT_MASK) != 0) newtMods |= com.jogamp.newt.event.InputEvent.SHIFT_MASK; + if ((awtMods & java.awt.event.InputEvent.CTRL_MASK) != 0) newtMods |= com.jogamp.newt.event.InputEvent.CTRL_MASK; + if ((awtMods & java.awt.event.InputEvent.META_MASK) != 0) newtMods |= com.jogamp.newt.event.InputEvent.META_MASK; + if ((awtMods & java.awt.event.InputEvent.ALT_MASK) != 0) newtMods |= com.jogamp.newt.event.InputEvent.ALT_MASK; + if ((awtMods & java.awt.event.InputEvent.ALT_GRAPH_MASK) != 0) newtMods |= com.jogamp.newt.event.InputEvent.ALT_GRAPH_MASK; */ + if ((awtModsEx & java.awt.event.InputEvent.SHIFT_DOWN_MASK) != 0) newtMods |= com.jogamp.newt.event.InputEvent.SHIFT_MASK; if ((awtModsEx & java.awt.event.InputEvent.CTRL_DOWN_MASK) != 0) newtMods |= com.jogamp.newt.event.InputEvent.CTRL_MASK; if ((awtModsEx & java.awt.event.InputEvent.META_DOWN_MASK) != 0) newtMods |= com.jogamp.newt.event.InputEvent.META_MASK; if ((awtModsEx & java.awt.event.InputEvent.ALT_DOWN_MASK) != 0) newtMods |= com.jogamp.newt.event.InputEvent.ALT_MASK; if ((awtModsEx & java.awt.event.InputEvent.ALT_GRAPH_DOWN_MASK) != 0) newtMods |= com.jogamp.newt.event.InputEvent.ALT_GRAPH_MASK; - if ((awtModsEx & awtButtonMasks[0]) != 0) newtMods |= newtButtonMasks[0] ; - if ((awtModsEx & awtButtonMasks[1]) != 0) newtMods |= newtButtonMasks[1] ; - if ((awtModsEx & awtButtonMasks[2]) != 0) newtMods |= newtButtonMasks[2] ; - - /** - for (int n = 0 ; n < awtButtonMasks.length ; ++n) { - if ((awtModsEx & awtButtonMasks[n]) != 0) { - newtMods |= newtButtonMasks[n] ; + // The BUTTON1_MASK, BUTTON2_MASK, and BUTTON3_MASK bits are + // being ignored intentionally. The AWT docs say that the + // BUTTON1_DOWN_MASK etc bits in the extended modifiers are + // the preferred place to check current button state. + + if( 0 != awtModsEx ) { + for (int n = 0 ; n < awtButtonDownMasks.length ; ++n) { + if ( (awtModsEx & awtButtonDownMasks[n]) != 0 ) { + newtMods |= com.jogamp.newt.event.InputEvent.getButtonMask(n+1); + } } - } */ + } return newtMods; } public static final int awtButton2Newt(int awtButton) { - switch (awtButton) { - case java.awt.event.MouseEvent.BUTTON1: return com.jogamp.newt.event.MouseEvent.BUTTON1; - case java.awt.event.MouseEvent.BUTTON2: return com.jogamp.newt.event.MouseEvent.BUTTON2; - case java.awt.event.MouseEvent.BUTTON3: return com.jogamp.newt.event.MouseEvent.BUTTON3; + if( 0 < awtButton && awtButton <= com.jogamp.newt.event.MouseEvent.BUTTON_NUMBER ) { + return awtButton; + } else { + return 0; } - return 0; } public static final com.jogamp.newt.event.WindowEvent createWindowEvent(java.awt.event.WindowEvent event, com.jogamp.newt.Window newtSource) { @@ -225,10 +274,10 @@ public class AWTNewtEventFactory { int mods = awtModifiers2Newt(event.getModifiers(), event.getModifiersEx(), true); if(null!=newtSource) { if(newtSource.isPointerConfined()) { - mods |= InputEvent.CONFINED_MASK; + mods |= com.jogamp.newt.event.InputEvent.CONFINED_MASK; } if(!newtSource.isPointerVisible()) { - mods |= InputEvent.INVISIBLE_MASK; + mods |= com.jogamp.newt.event.InputEvent.INVISIBLE_MASK; } } diff --git a/src/test/com/jogamp/opengl/test/junit/newt/event/BaseNewtEventModifiers.java b/src/test/com/jogamp/opengl/test/junit/newt/event/BaseNewtEventModifiers.java new file mode 100644 index 000000000..1dfdc4021 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/event/BaseNewtEventModifiers.java @@ -0,0 +1,740 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.test.junit.newt.event ; + +import java.io.PrintStream ; +import java.util.ArrayList ; + +import javax.media.opengl.GL ; +import javax.media.opengl.GL2 ; +import javax.media.opengl.GLAutoDrawable ; +import javax.media.opengl.GLEventListener ; +import javax.media.opengl.GLProfile ; + +import org.junit.After ; +import org.junit.AfterClass ; +import org.junit.Assert ; +import org.junit.Before ; +import org.junit.BeforeClass ; +import org.junit.Test ; + +import com.jogamp.common.os.Platform; +import com.jogamp.newt.event.MouseEvent; +import com.jogamp.opengl.test.junit.util.UITestCase ; + +/** + * Test whether or not event modifiers are preserved by NEWT. This + * class defines most of the tests, but leaves the type of window + * and canvas up to subclasses. + */ + +public abstract class BaseNewtEventModifiers extends UITestCase { + + static + { + GLProfile.initSingleton() ; + } + + // A class to draw something on a canvas. This is only + // here so we can make sure the GL drawing area has + // filled the window. + + public static class BigGreenXGLEventListener implements GLEventListener + { + public void init( GLAutoDrawable drawable ) + { + GL2 gl = drawable.getGL().getGL2() ; + + gl.glClearColor( 0.0f, 0.0f, 0.0f, 1.0f ) ; + + gl.glEnable( GL.GL_LINE_SMOOTH ) ; + gl.glEnable( GL.GL_BLEND ) ; + gl.glBlendFunc( GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA ) ; + } + + public void reshape( GLAutoDrawable drawable, int x, int y, int width, int height ) + { + GL2 gl = drawable.getGL().getGL2() ; + + gl.glViewport( 0, 0, width, height ) ; + + gl.glMatrixMode( GL2.GL_PROJECTION ) ; + gl.glLoadIdentity() ; + gl.glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 ) ; + + gl.glMatrixMode( GL2.GL_MODELVIEW ) ; + gl.glLoadIdentity() ; + } + + public void display( GLAutoDrawable drawable ) + { + GL2 gl = drawable.getGL().getGL2() ; + + gl.glClear( GL2.GL_COLOR_BUFFER_BIT ) ; + + gl.glColor4f( 0.0f, 1.0f, 0.0f, 1.0f ) ; + + gl.glBegin( GL.GL_LINES ) ; + { + gl.glVertex2f( -1.0f, 1.0f ) ; + gl.glVertex2f( 1.0f, -1.0f ) ; + + gl.glVertex2f( -1.0f, -1.0f ) ; + gl.glVertex2f( 1.0f, 1.0f ) ; + } + gl.glEnd() ; + } + + public void dispose( GLAutoDrawable drawable ) + { + } + } + + //////////////////////////////////////////////////////////////////////////// + + private static class TestMouseListener implements com.jogamp.newt.event.MouseListener + { + private static final String NO_EVENT_DELIVERY = "no event delivery" ; + + private boolean _modifierCheckEnabled ; + private int _expectedModifiers ; + private ArrayList _failures = new ArrayList() ; + + public void setModifierCheckEnabled( boolean value ) { + _modifierCheckEnabled = value ; + } + + public boolean modifierCheckEnabled() { + return _modifierCheckEnabled ; + } + + /** + * Sets the modifiers the listener should expect, and clears + * out any existing accumulated failures. Normally this kind + * of double duty in a setter might be considered evil, but + * in this test code it's probably ok. + */ + + public void setExpectedModifiers( int value ) { + _expectedModifiers = value ; + + // Assume we will have a failure due to no event delivery. + // If an event is delivered and it's good this assumed + // failure will get cleared out. + + _failures.clear() ; + _failures.add( NO_EVENT_DELIVERY ) ; + } + + private void _checkModifiers( com.jogamp.newt.event.MouseEvent event ) { + + if( _debug ) { + _debugPrintStream.print( " received NEWT " ) ; + _debugPrintStream.print( com.jogamp.newt.event.MouseEvent.getEventTypeString( event.getEventType() ) ) ; + } + + if( _modifierCheckEnabled ) { + + if( _debug ) { + _debugPrintStream.println( ", checking modifiers..." ) ; + _debugPrintStream.println( " expected NEWT Modifiers:" ) ; + { + final MouseEvent exp = new MouseEvent(MouseEvent.EVENT_MOUSE_CLICKED, null, 0, _expectedModifiers, 0, 0, 1, 1, 0); + _debugPrintStream.println(" "+exp.getModifiersString(null).toString()); + } + _debugPrintStream.println( " current NEWT Modifiers:" ) ; + _debugPrintStream.println(" "+event.getModifiersString(null).toString()); + } + + _checkModifierMask( event, com.jogamp.newt.event.InputEvent.SHIFT_MASK ) ; + _checkModifierMask( event, com.jogamp.newt.event.InputEvent.CTRL_MASK ) ; + _checkModifierMask( event, com.jogamp.newt.event.InputEvent.META_MASK ) ; + _checkModifierMask( event, com.jogamp.newt.event.InputEvent.ALT_MASK ) ; + _checkModifierMask( event, com.jogamp.newt.event.InputEvent.ALT_GRAPH_MASK ) ; + + for( int n = 0 ; n < _numButtonsToTest ; ++n ) { + _checkModifierMask( event, com.jogamp.newt.event.InputEvent.getButtonMask( n + 1 ) ) ; + } + } else { + if( _debug ) { + _debugPrintStream.println( ", modifier check disabled" ) ; + } + } + } + + private void _checkModifierMask( com.jogamp.newt.event.MouseEvent event, int mask ) { + + // If the "no event delivery" failure is still in the list then + // get rid of it since that obviously isn't true anymore. We + // want to do this whether or not there's an issue with the + // modifiers. + + if( _failures.size() == 1 && _failures.get(0).equals( NO_EVENT_DELIVERY ) ) { + _failures.clear() ; + } + + if( ( event.getModifiers() & mask ) != ( _expectedModifiers & mask ) ) { + StringBuilder sb = new StringBuilder(); + sb.append( com.jogamp.newt.event.MouseEvent.getEventTypeString( event.getEventType() ) ).append(": "); + final MouseEvent exp = new MouseEvent(MouseEvent.EVENT_MOUSE_CLICKED, null, 0, _expectedModifiers, 0, 0, 1, 1, 0); + sb.append("Expected:").append(Platform.NEWLINE); + exp.getModifiersString(sb).append(Platform.NEWLINE); + sb.append(", Have: ").append(Platform.NEWLINE); + event.getModifiersString(sb).append(Platform.NEWLINE); + _failures.add( sb.toString() ) ; + } + } + + public ArrayList getFailures() { + return _failures ; + } + + public void mouseClicked( com.jogamp.newt.event.MouseEvent event ) { + _checkModifiers( event ) ; + } + + public void mousePressed( com.jogamp.newt.event.MouseEvent event ) { + _checkModifiers( event ) ; + } + + public void mouseReleased( com.jogamp.newt.event.MouseEvent event ) { + _checkModifiers( event ) ; + } + + public void mouseEntered( com.jogamp.newt.event.MouseEvent event ) { + _checkModifiers( event ) ; + } + + public void mouseExited( com.jogamp.newt.event.MouseEvent event ) { + _checkModifiers( event ) ; + } + + public void mouseDragged( com.jogamp.newt.event.MouseEvent event ) { + _checkModifiers( event ) ; + } + + public void mouseMoved( com.jogamp.newt.event.MouseEvent event ) { + _checkModifiers( event ) ; + } + + public void mouseWheelMoved( com.jogamp.newt.event.MouseEvent event ) { + _checkModifiers( event ) ; + } + } + + //////////////////////////////////////////////////////////////////////////// + + protected static final int TEST_FRAME_X = 100 ; + protected static final int TEST_FRAME_Y = 100 ; + + protected static final int TEST_FRAME_WIDTH = 400 ; + protected static final int TEST_FRAME_HEIGHT = 400 ; + + private static final int INITIAL_MOUSE_X = TEST_FRAME_X + ( TEST_FRAME_WIDTH / 2 ) ; + private static final int INITIAL_MOUSE_Y = TEST_FRAME_Y + ( TEST_FRAME_HEIGHT / 2 ) ; + + private static final int MS_ROBOT_SHORT_AUTO_DELAY = 50 ; + private static final int MS_ROBOT_LONG_AUTO_DELAY = 500 ; + + private static boolean _debug = true ; + private static PrintStream _debugPrintStream = System.err ; + + //////////////////////////////////////////////////////////////////////////// + + private static int _numButtonsToTest ; + private static int _awtButtonMasks[] ; + + private static java.awt.Robot _robot ; + + protected static TestMouseListener _testMouseListener ; + + //////////////////////////////////////////////////////////////////////////// + + public static int getAWTButtonMask(int button) { + // Java7: java.awt.event.InputEvent.getMaskForButton( n + 1 ) ; -> using InputEvent.BUTTON1_DOWN_MASK .. etc + // Java6: Only use BUTTON1_MASK, .. + int m; + switch(button) { + case 1 : m = java.awt.event.InputEvent.BUTTON1_MASK; break; + case 2 : m = java.awt.event.InputEvent.BUTTON2_MASK; break; + case 3 : m = java.awt.event.InputEvent.BUTTON3_MASK; break; + default: throw new IllegalArgumentException("Only buttons 1-3 have a MASK value, requested button "+button); + } + return m; + } + + @BeforeClass + public static void beforeClass() throws Exception { + + // Who know how many buttons the AWT will say exist on given platform. + // We'll test the smaller of what NEWT supports and what the + // AWT says is available. + /** Java7: + if( java.awt.Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled() ) { + _numButtonsToTest = java.awt.MouseInfo.getNumberOfButtons() ; + } else { + _numButtonsToTest = 3 ; + } */ + _numButtonsToTest = 3 ; + + // Then again, maybe not: + + // FIXME? - for reasons I'm not quite sure of the AWT MouseEvent + // constructor does some strange things for buttons other than + // 1, 2, and 3. Furthermore, while developing this test it + // appeared that events sent by the robot for buttons 9 and + // up weren't even delivered to the listeners. + // + // So... for now we're only going to test 3 buttons since + // that's the common case _and_ Java6 safe. + + _numButtonsToTest = 3 ; + + { + if( _numButtonsToTest > com.jogamp.newt.event.MouseEvent.BUTTON_NUMBER ) { + _numButtonsToTest = com.jogamp.newt.event.MouseEvent.BUTTON_NUMBER ; + } + + // These two arrays are assumed to be peers, i.e. are the same + // size, and a given index references the same button in + // either array. + + _awtButtonMasks = new int[_numButtonsToTest] ; + + for( int n = 0 ; n < _awtButtonMasks.length ; ++n ) { + _awtButtonMasks[n] = getAWTButtonMask( n + 1 ); + } + } + + _robot = new java.awt.Robot() ; + _robot.setAutoWaitForIdle( true ) ; + _robot.setAutoDelay( MS_ROBOT_LONG_AUTO_DELAY ) ; + + _testMouseListener = new TestMouseListener() ; + } + + //////////////////////////////////////////////////////////////////////////// + + @Before + public void before() throws Exception { + + _testMouseListener.setModifierCheckEnabled( false ) ; + _robot.setAutoDelay( MS_ROBOT_SHORT_AUTO_DELAY ) ; + + // Make sure all the buttons and modifier keys are released. + + _releaseModifiers() ; + _escape() ; + + // Move the pointer into the window and click once to + // ensure that the test window has focus. + + if( _debug ) { + _debugPrintStream.println( ">>>> Clicking in the window to get focus." ) ; + } + + _robot.mouseMove( INITIAL_MOUSE_X, INITIAL_MOUSE_Y ) ; + _robot.mousePress( java.awt.event.InputEvent.BUTTON1_DOWN_MASK ) ; + _robot.mouseRelease( java.awt.event.InputEvent.BUTTON1_DOWN_MASK ) ; + + _testMouseListener.setModifierCheckEnabled( true ) ; + _robot.setAutoDelay( MS_ROBOT_LONG_AUTO_DELAY ) ; + + if( _debug ) { + _debugPrintStream.println( ">>>> About to start testing." ) ; + } + } + + //////////////////////////////////////////////////////////////////////////// + + // The approach on all these tests is to tell the test mouse listener what + // modifiers we think it should receive. Then when the events are delivered + // it compares what we told it to expect with what actually showed up and + // complains if there are differences. + // + // As things stand currently the tests below generally work for AWTCanvas + // and fail for everything else. This may point to a flaw in the test + // code, or a flaw in the NEWT stuff; not sure yet. One exception is the + // tests involving ALT and META, which on at least X11 cause the desktop + // to do undesirable stuff while the tests are in progress. So... these + // tests have been commented out for now and probably should be left + // that way. + // + // Due to the fact that a majority of these fail currently for + // everything but AWTCanvas for the time being we probably shouldn't + // run the tests for NewtCanvasAWT and NewtCanvasSWT until we can + // pay more attention to the NEWT event modifier stuff. + + @Test + public void testSingleButtonPressAndRelease() throws Exception { + _doSingleButtonPressAndRelease( 0, 0 ) ; + } + + @Test + public void testSingleButtonPressAndReleaseWithShift() throws Exception { + _doSingleButtonPressAndRelease( java.awt.event.KeyEvent.VK_SHIFT, java.awt.event.InputEvent.SHIFT_DOWN_MASK ) ; + } + + @Test + public void testSingleButtonPressAndReleaseWithCtrl() throws Exception { + _doSingleButtonPressAndRelease( java.awt.event.KeyEvent.VK_CONTROL, java.awt.event.InputEvent.CTRL_DOWN_MASK ) ; + } + + // The META and ALT tests get too tied up with functions of the window system on X11, + // so it's probably best to leave them commented out. + + //@Test + //public void testSingleButtonPressAndReleaseWithMeta() throws Exception { + // _doSingleButtonPressAndRelease( java.awt.event.KeyEvent.VK_META, java.awt.event.InputEvent.META_DOWN_MASK ) ; + //} + + //@Test + //public void testSingleButtonPressAndReleaseWithAlt() throws Exception { + // _doSingleButtonPressAndRelease( java.awt.event.KeyEvent.VK_ALT, java.awt.event.InputEvent.ALT_DOWN_MASK ) ; + //} + + // FIXME - not sure yet what's up with ALT_GRAPH. It appears that this + // modifier didn't make it through, so I had to disable this test else + // it would always fail. + // + // My US keyboard doesn't have an AltGr key, so maybe X is smart + // enough to not let this modifier slip through (?). + + //@Test + //public void testSingleButtonPressAndReleaseWithAltGraph() throws Exception { + // _doSingleButtonPressAndRelease( java.awt.event.KeyEvent.VK_ALT_GRAPH, java.awt.event.InputEvent.ALT_GRAPH_DOWN_MASK ) ; + //} + + //////////////////////////////////////////////////////////////////////////// + + @Test + public void testHoldOneButtonAndPressAnother() throws Exception { + _doHoldOneButtonAndPressAnother( 0, 0 ) ; + } + + @Test + public void testPressAllButtonsInSequence() throws Exception { + _doPressAllButtonsInSequence( 0, 0 ) ; + } + + @Test + public void testSingleButtonClickAndDrag() throws Exception { + _doSingleButtonClickAndDrag( 0, 0 ) ; + } + + //////////////////////////////////////////////////////////////////////////// + + private void _doSingleButtonPressAndRelease( final int keyCode, final int keyModifierMask ) throws Exception { + + if( _debug ) { _debugPrintStream.println( "\n>>>> _doSingleButtonPressAndRelease" ) ; } + + _doKeyPress( keyCode ) ; + + for (int n = 0 ; n < _numButtonsToTest ; ++n) { + + int awtButtonMask = _awtButtonMasks[n] ; + + if( _debug ) { _debugPrintStream.println( "\n pressing button " + ( n + 1 ) ) ; } + _testMouseListener.setExpectedModifiers( _getNewtModifiersForAwtExtendedModifiers( keyModifierMask | awtButtonMask ) ) ; + _robot.mousePress( awtButtonMask ) ; + _checkFailures() ; + + if( _debug ) { _debugPrintStream.println( "\n releasing button " + ( n + 1 ) ) ; } + _testMouseListener.setExpectedModifiers( _getNewtModifiersForAwtExtendedModifiers( keyModifierMask ) ) ; + _robot.mouseRelease( awtButtonMask ) ; + _checkFailures() ; + } + + _doKeyRelease( keyCode ) ; + } + + //////////////////////////////////////////////////////////////////////////// + + private void _doHoldOneButtonAndPressAnother( final int keyCode, final int keyModifierMask ) throws Exception { + + if( _debug ) { _debugPrintStream.println( "\n>>>> _doHoldOneButtonAndPressAnother" ) ; } + + _doKeyPress( keyCode ) ; + + for (int n = 0 ; n < _numButtonsToTest ; ++n) { + + int awtButtonMask = _awtButtonMasks[n] ; + + if( _debug ) { _debugPrintStream.println( "\n pressing button " + ( n + 1 ) ) ; } + _testMouseListener.setExpectedModifiers( _getNewtModifiersForAwtExtendedModifiers( keyModifierMask | awtButtonMask ) ) ; + _robot.mousePress( awtButtonMask ) ; + _checkFailures() ; + + for (int m = 0 ; m < _numButtonsToTest ; ++m) { + + if( n != m ) { + + if( _debug ) { _debugPrintStream.println( "\n pressing additional button " + ( m + 1 ) ) ; } + _testMouseListener.setExpectedModifiers( _getNewtModifiersForAwtExtendedModifiers( keyModifierMask | awtButtonMask | _awtButtonMasks[m] ) ) ; + _robot.mousePress( _awtButtonMasks[m] ) ; + _checkFailures() ; + + if( _debug ) { _debugPrintStream.println( "\n releasing additional button " + ( m + 1 ) ) ; } + _testMouseListener.setExpectedModifiers( _getNewtModifiersForAwtExtendedModifiers( keyModifierMask | awtButtonMask ) ) ; + _robot.mouseRelease( _awtButtonMasks[m] ) ; + _checkFailures() ; + } + } + + if( _debug ) { _debugPrintStream.println( "\n releasing button " + ( n + 1 ) ) ; } + _testMouseListener.setExpectedModifiers( _getNewtModifiersForAwtExtendedModifiers( keyModifierMask ) ) ; + _robot.mouseRelease( awtButtonMask ) ; + _checkFailures() ; + } + + _doKeyRelease( keyCode ) ; + } + + //////////////////////////////////////////////////////////////////////////// + + private void _doPressAllButtonsInSequence( final int keyCode, final int keyModifierMask ) throws Exception { + + if( _debug ) { _debugPrintStream.println( "\n>>>> _doPressAllButtonsInSequence" ) ; } + + _doKeyPress( keyCode ) ; + + { + int cumulativeAwtModifiers = 0 ; + + for (int n = 0 ; n < _numButtonsToTest ; ++n) { + + cumulativeAwtModifiers |= _awtButtonMasks[n] ; + + if( _debug ) { _debugPrintStream.println( "\n pressing button " + ( n + 1 ) ) ; } + _testMouseListener.setExpectedModifiers( _getNewtModifiersForAwtExtendedModifiers( keyModifierMask | cumulativeAwtModifiers ) ) ; + _robot.mousePress( _awtButtonMasks[n] ) ; + _checkFailures() ; + } + + for (int n = _numButtonsToTest - 1 ; n >= 0 ; --n) { + + cumulativeAwtModifiers &= ~_awtButtonMasks[n] ; + + if( _debug ) { _debugPrintStream.println( "\n releasing button " + ( n + 1 ) ) ; } + _testMouseListener.setExpectedModifiers( _getNewtModifiersForAwtExtendedModifiers( keyModifierMask | cumulativeAwtModifiers ) ) ; + _robot.mouseRelease( _awtButtonMasks[n] ) ; + _checkFailures() ; + } + } + + _doKeyRelease( keyCode ) ; + } + + //////////////////////////////////////////////////////////////////////////// + + private void _doSingleButtonClickAndDrag( final int keyCode, final int keyModifierMask ) throws Exception { + + if( _debug ) { _debugPrintStream.println( "\n>>>> _doSingleButtonClickAndDrag" ) ; } + + _doKeyPress( keyCode ) ; + + _testMouseListener.setModifierCheckEnabled( true ) ; + + for (int n = 0 ; n < _numButtonsToTest ; ++n) { + + int awtButtonMask = _awtButtonMasks[n] ; + + if( _debug ) { _debugPrintStream.println( "\n pressing button " + ( n + 1 ) ) ; } + _testMouseListener.setExpectedModifiers( _getNewtModifiersForAwtExtendedModifiers( keyModifierMask | awtButtonMask ) ) ; + _robot.mousePress( awtButtonMask ) ; + _checkFailures() ; + + // To get a drag we only need to move one pixel. + if( _debug ) { _debugPrintStream.println( "\n moving mouse" ) ; } + _robot.mouseMove( INITIAL_MOUSE_X + 1, INITIAL_MOUSE_Y + 1 ) ; + _checkFailures() ; + + if( _debug ) { _debugPrintStream.println( "\n releasing button " + ( n + 1 ) ) ; } + _testMouseListener.setExpectedModifiers( _getNewtModifiersForAwtExtendedModifiers( keyModifierMask ) ) ; + _robot.mouseRelease( awtButtonMask ) ; + _checkFailures() ; + + _testMouseListener.setModifierCheckEnabled( false ) ; + _robot.mouseMove( INITIAL_MOUSE_X, INITIAL_MOUSE_Y ) ; + _testMouseListener.setModifierCheckEnabled( true ) ; + } + + _doKeyRelease( keyCode ) ; + } + + //////////////////////////////////////////////////////////////////////////// + + private void _doKeyPress( int keyCode ) { + if( keyCode != 0 ) { + boolean modifierCheckEnabled = _testMouseListener.modifierCheckEnabled() ; + _testMouseListener.setModifierCheckEnabled( false ) ; + _robot.keyPress( keyCode ) ; + _testMouseListener.setModifierCheckEnabled( modifierCheckEnabled ) ; + } + } + + //////////////////////////////////////////////////////////////////////////// + + private void _doKeyRelease( int keyCode ) { + if( keyCode != 0 ) { + boolean modifierCheckEnabled = _testMouseListener.modifierCheckEnabled() ; + _testMouseListener.setModifierCheckEnabled( false ) ; + _robot.keyRelease( keyCode ) ; + _testMouseListener.setModifierCheckEnabled( modifierCheckEnabled ) ; + } + } + + //////////////////////////////////////////////////////////////////////////// + + private void _checkFailures() { + + ArrayList failures = _testMouseListener.getFailures() ; + + if( _debug ) { + int numFailures = failures.size() ; + if( numFailures == 0 ) { + _debugPrintStream.println( " PASSED" ) ; + } else { + _debugPrintStream.println( " FAILED" ) ; + for( int n = 0 ; n < numFailures ; ++n ) { + _debugPrintStream.print( " " ) ; + _debugPrintStream.println( failures.get(n) ) ; + } + } + } + + Assert.assertTrue( failures.size() == 0 ) ; + } + + //////////////////////////////////////////////////////////////////////////// + + @After + public void after() throws Exception { + + _testMouseListener.setModifierCheckEnabled( false ) ; + + Thread.sleep( 500 ) ; + } + + //////////////////////////////////////////////////////////////////////////// + + @AfterClass + public static void afterClass() throws Exception { + + // Make sure all modifiers are released, otherwise the user's + // desktop can get locked up (ask me how I know this). + + _releaseModifiers() ; + _escape() ; + } + + //////////////////////////////////////////////////////////////////////////// + + private static void _releaseModifiers() { + + if (_robot != null) { + + _robot.setAutoDelay( MS_ROBOT_SHORT_AUTO_DELAY ) ; + + boolean modifierCheckEnabled = _testMouseListener.modifierCheckEnabled() ; + _testMouseListener.setModifierCheckEnabled( false ) ; + + { + _robot.keyRelease( java.awt.event.KeyEvent.VK_SHIFT ) ; + _robot.keyRelease( java.awt.event.KeyEvent.VK_CONTROL ) ; + _robot.keyRelease( java.awt.event.KeyEvent.VK_META ) ; + _robot.keyRelease( java.awt.event.KeyEvent.VK_ALT ) ; + _robot.keyRelease( java.awt.event.KeyEvent.VK_ALT_GRAPH ) ; + + for (int n = 0 ; n < _awtButtonMasks.length ; ++n) { + _robot.mouseRelease( _awtButtonMasks[n] ) ; + } + } + + _testMouseListener.setModifierCheckEnabled( modifierCheckEnabled ) ; + + _robot.setAutoDelay( MS_ROBOT_LONG_AUTO_DELAY ) ; + } + } + + private static void _escape() { + if (_robot != null) { + _robot.keyPress( java.awt.event.KeyEvent.VK_ESCAPE ) ; + _robot.keyRelease( java.awt.event.KeyEvent.VK_ESCAPE ) ; + } + } + + //////////////////////////////////////////////////////////////////////////// + + /** + * Brute force method to return the NEWT event modifiers equivalent + * to the specified AWT event extended modifiers. + * + * @param awtExtendedModifiers + * The AWT extended modifiers. + * + * @return + * The equivalent NEWT modifiers. + */ + + private int _getNewtModifiersForAwtExtendedModifiers( int awtExtendedModifiers ) { + + int mask = 0 ; + + if( ( awtExtendedModifiers & java.awt.event.InputEvent.SHIFT_DOWN_MASK ) != 0 ) { + mask |= com.jogamp.newt.event.InputEvent.SHIFT_MASK ; + } + + if( ( awtExtendedModifiers & java.awt.event.InputEvent.CTRL_DOWN_MASK ) != 0 ) { + mask |= com.jogamp.newt.event.InputEvent.CTRL_MASK ; + } + + if( ( awtExtendedModifiers & java.awt.event.InputEvent.META_DOWN_MASK ) != 0 ) { + mask |= com.jogamp.newt.event.InputEvent.META_MASK ; + } + + if( ( awtExtendedModifiers & java.awt.event.InputEvent.ALT_DOWN_MASK ) != 0 ) { + mask |= com.jogamp.newt.event.InputEvent.ALT_MASK ; + } + + if( ( awtExtendedModifiers & java.awt.event.InputEvent.ALT_GRAPH_DOWN_MASK ) != 0 ) { + mask |= com.jogamp.newt.event.InputEvent.ALT_GRAPH_MASK ; + } + + for (int n = 0 ; n < _numButtonsToTest ; ++n) { + if ((awtExtendedModifiers & getAWTButtonMask(n+1)) != 0) { + mask |= com.jogamp.newt.event.InputEvent.getButtonMask(n+1) ; + } + } + + return mask ; + } + + //////////////////////////////////////////////////////////////////////////// +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/event/ModifierMappings.txt b/src/test/com/jogamp/opengl/test/junit/newt/event/ModifierMappings.txt deleted file mode 100644 index 1bd9102b5..000000000 --- a/src/test/com/jogamp/opengl/test/junit/newt/event/ModifierMappings.txt +++ /dev/null @@ -1,37 +0,0 @@ -Modifier AWT Constant AWT Bit AWT Ex NEWT Constant NEWT Bit -------------- ------------------------------- ------- ------ ------------------------- -------- -Shift Event.SHIFT_MASK 0 -Ctrl Event.CTRL_MASK 1 -Meta Event.META_MASK 2 -Alt Event.ALT_MASK 3 -Button1 InputEvent.BUTTON1_MASK 4 -Button2 InputEvent.BUTTON2_MASK 3 -Button3 InputEvent.BUTTON3_MASK 2 -Shift Down InputEvent.SHIFT_DOWN_MASK 6 * InputEvent.SHIFT_MASK 0 -Ctrl Down InputEvent.CTRL_DOWN_MASK 7 * InputEvent.CTRL_MASK 1 -Meta Down InputEvent.META_DOWN_MASK 8 * InputEvent.META_MASK 2 -Alt Down InputEvent.ALT_DOWN_MASK 9 * InputEvent.ALT_MASK 3 -Button1 Down InputEvent.BUTTON1_DOWN_MASK 10 * InputEvent.BUTTON1_MASK 5 -Button2 Down InputEvent.BUTTON2_DOWN_MASK 11 * InputEvent.BUTTON2_MASK 6 -Button3 Down InputEvent.BUTTON3_DOWN_MASK 12 * InputEvent.BUTTON3_MASK 7 -AltGraph Down InputEvent.ALT_GRAPH_DOWN_MASK 13 * InputEvent.ALT_GRAPH_MASK 4 -Button4 Down -- 14 * InputEvent.BUTTON4_MASK 8 -Button5 Down -- 15 * InputEvent.BUTTON5_MASK 9 -Button6 Down -- 16 * InputEvent.BUTTON6_MASK 10 -Button7 Down -- 17 * InputEvent.BUTTON7_MASK 11 -Button8 Down -- 18 * InputEvent.BUTTON8_MASK 12 -Button9 Down -- 19 * InputEvent.BUTTON9_MASK 13 -Button10 Down -- 20 * -Button11 Down -- 21 * -Button12 Down -- 22 * -Button13 Down -- 23 * -Button14 Down -- 24 * -Button15 Down -- 25 * -Button16 Down -- 26 * InputEvent.BUTTONLAST_MASK 20 -Button17 Down -- 27 * -Button18 Down -- 28 * -Button19 Down -- 29 * -Button20 Down -- 30 * -Autorepeat -- - InputEvent.AUTOREPEAT_MASK 29 -Confined -- - InputEvent.CONFINED_MASK 30 -Invisible -- - InputEvent.INVISIBLE_MASK 31 diff --git a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiers.java b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiers.java deleted file mode 100644 index 81e1939b9..000000000 --- a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiers.java +++ /dev/null @@ -1,761 +0,0 @@ -/** - * Copyright 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ - -package com.jogamp.opengl.test.junit.newt.event ; - -import java.io.PrintStream ; -import java.util.ArrayList ; - -import javax.media.opengl.GL ; -import javax.media.opengl.GL2 ; -import javax.media.opengl.GLAutoDrawable ; -import javax.media.opengl.GLEventListener ; -import javax.media.opengl.GLProfile ; - -import org.junit.After ; -import org.junit.AfterClass ; -import org.junit.Assert ; -import org.junit.Before ; -import org.junit.BeforeClass ; -import org.junit.Test ; - -import com.jogamp.opengl.test.junit.util.UITestCase ; - -/** - * Test whether or not event modifiers are preserved by NEWT. This - * class defines most of the tests, but leaves the type of window - * and canvas up to subclasses. - */ - -public abstract class TestNewtEventModifiers extends UITestCase { - - static - { - GLProfile.initSingleton() ; - } - - // A class to draw something on a canvas. This is only - // here so we can make sure the GL drawing area has - // filled the window. - - public static class BigGreenXGLEventListener implements GLEventListener - { - public void init( GLAutoDrawable drawable ) - { - GL2 gl = drawable.getGL().getGL2() ; - - gl.glClearColor( 0.0f, 0.0f, 0.0f, 1.0f ) ; - - gl.glEnable( GL.GL_LINE_SMOOTH ) ; - gl.glEnable( GL.GL_BLEND ) ; - gl.glBlendFunc( GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA ) ; - } - - public void reshape( GLAutoDrawable drawable, int x, int y, int width, int height ) - { - GL2 gl = drawable.getGL().getGL2() ; - - gl.glViewport( 0, 0, width, height ) ; - - gl.glMatrixMode( GL2.GL_PROJECTION ) ; - gl.glLoadIdentity() ; - gl.glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 ) ; - - gl.glMatrixMode( GL2.GL_MODELVIEW ) ; - gl.glLoadIdentity() ; - } - - public void display( GLAutoDrawable drawable ) - { - GL2 gl = drawable.getGL().getGL2() ; - - gl.glClear( GL2.GL_COLOR_BUFFER_BIT ) ; - - gl.glColor4f( 0.0f, 1.0f, 0.0f, 1.0f ) ; - - gl.glBegin( GL.GL_LINES ) ; - { - gl.glVertex2f( -1.0f, 1.0f ) ; - gl.glVertex2f( 1.0f, -1.0f ) ; - - gl.glVertex2f( -1.0f, -1.0f ) ; - gl.glVertex2f( 1.0f, 1.0f ) ; - } - gl.glEnd() ; - } - - public void dispose( GLAutoDrawable drawable ) - { - } - } - - //////////////////////////////////////////////////////////////////////////// - - private static class TestMouseListener implements com.jogamp.newt.event.MouseListener - { - private static final String NO_EVENT_DELIVERY = "no event delivery" ; - - private boolean _modifierCheckEnabled ; - private int _expectedModifiers ; - private ArrayList _failures = new ArrayList() ; - - public void setModifierCheckEnabled( boolean value ) { - _modifierCheckEnabled = value ; - } - - public boolean modifierCheckEnabled() { - return _modifierCheckEnabled ; - } - - /** - * Sets the modifiers the listener should expect, and clears - * out any existing accumulated failures. Normally this kind - * of double duty in a setter might be considered evil, but - * in this test code it's probably ok. - */ - - public void setExpectedModifiers( int value ) { - _expectedModifiers = value ; - - // Assume we will have a failure due to no event delivery. - // If an event is delivered and it's good this assumed - // failure will get cleared out. - - _failures.clear() ; - _failures.add( NO_EVENT_DELIVERY ) ; - } - - private void _checkModifiers( com.jogamp.newt.event.MouseEvent event ) { - - if( _debug ) { - _debugPrintStream.print( " received NEWT " ) ; - _debugPrintStream.print( com.jogamp.newt.event.MouseEvent.getEventTypeString( event.getEventType() ) ) ; - } - - if( _modifierCheckEnabled ) { - - if( _debug ) { - _debugPrintStream.println( ", checking modifiers..." ) ; - _debugPrintStream.println( " expected NEWT Modifiers:" ) ; - _printModifiers( _expectedModifiers ) ; - _debugPrintStream.println( " current NEWT Modifiers:" ) ; - _printModifiers( event.getModifiers() ) ; - } - - _checkModifierMask( event, com.jogamp.newt.event.InputEvent.SHIFT_MASK ) ; - _checkModifierMask( event, com.jogamp.newt.event.InputEvent.CTRL_MASK ) ; - _checkModifierMask( event, com.jogamp.newt.event.InputEvent.META_MASK ) ; - _checkModifierMask( event, com.jogamp.newt.event.InputEvent.ALT_MASK ) ; - _checkModifierMask( event, com.jogamp.newt.event.InputEvent.ALT_GRAPH_MASK ) ; - - for( int n = 0 ; n < _numButtonsToTest ; ++n ) { - _checkModifierMask( event, com.jogamp.newt.event.InputEvent.getButtonMask( n + 1 ) ) ; - } - } else { - if( _debug ) { - _debugPrintStream.println( ", modifier check disabled" ) ; - } - } - } - - private void _checkModifierMask( com.jogamp.newt.event.MouseEvent event, int mask ) { - - // If the "no event delivery" failure is still in the list then - // get rid of it since that obviously isn't true anymore. We - // want to do this whether or not there's an issue with the - // modifiers. - - if( _failures.size() == 1 && _failures.get(0).equals( NO_EVENT_DELIVERY ) ) { - _failures.clear() ; - } - - if( ( event.getModifiers() & mask ) != ( _expectedModifiers & mask ) ) { - _failures.add( com.jogamp.newt.event.MouseEvent.getEventTypeString( event.getEventType() ) ) ; - } - } - - private void _printModifiers( int modifiers ) { - if( ( modifiers & com.jogamp.newt.event.InputEvent.SHIFT_MASK ) != 0 ) { _debugPrintStream.println( " SHIFT" ) ; } - if( ( modifiers & com.jogamp.newt.event.InputEvent.CTRL_MASK ) != 0 ) { _debugPrintStream.println( " CTRL" ) ; } - if( ( modifiers & com.jogamp.newt.event.InputEvent.META_MASK ) != 0 ) { _debugPrintStream.println( " META" ) ; } - if( ( modifiers & com.jogamp.newt.event.InputEvent.ALT_MASK ) != 0 ) { _debugPrintStream.println( " ALT" ) ; } - if( ( modifiers & com.jogamp.newt.event.InputEvent.ALT_GRAPH_MASK ) != 0 ) { _debugPrintStream.println( " ALT_GRAPH" ) ; } - if( ( modifiers & com.jogamp.newt.event.InputEvent.BUTTON1_MASK ) != 0 ) { _debugPrintStream.println( " BUTTON1" ) ; } - if( ( modifiers & com.jogamp.newt.event.InputEvent.BUTTON2_MASK ) != 0 ) { _debugPrintStream.println( " BUTTON2" ) ; } - if( ( modifiers & com.jogamp.newt.event.InputEvent.BUTTON3_MASK ) != 0 ) { _debugPrintStream.println( " BUTTON3" ) ; } - if( ( modifiers & com.jogamp.newt.event.InputEvent.BUTTON4_MASK ) != 0 ) { _debugPrintStream.println( " BUTTON4" ) ; } - if( ( modifiers & com.jogamp.newt.event.InputEvent.BUTTON5_MASK ) != 0 ) { _debugPrintStream.println( " BUTTON5" ) ; } - if( ( modifiers & com.jogamp.newt.event.InputEvent.BUTTON6_MASK ) != 0 ) { _debugPrintStream.println( " BUTTON6" ) ; } - if( ( modifiers & com.jogamp.newt.event.InputEvent.BUTTON7_MASK ) != 0 ) { _debugPrintStream.println( " BUTTON7" ) ; } - if( ( modifiers & com.jogamp.newt.event.InputEvent.BUTTON8_MASK ) != 0 ) { _debugPrintStream.println( " BUTTON8" ) ; } - if( ( modifiers & com.jogamp.newt.event.InputEvent.BUTTON9_MASK ) != 0 ) { _debugPrintStream.println( " BUTTON9" ) ; } - } - - private static void _printAwtModifiers( int awtMods, int awtModsEx ) { - if( ( awtMods & java.awt.event.InputEvent.SHIFT_MASK ) != 0 ) { System.err.println( "SHIFT" ) ; } - if( ( awtMods & java.awt.event.InputEvent.CTRL_MASK ) != 0 ) { System.err.println( "CTRL" ) ; } - if( ( awtMods & java.awt.event.InputEvent.META_MASK ) != 0 ) { System.err.println( "META" ) ; } - if( ( awtMods & java.awt.event.InputEvent.ALT_MASK ) != 0 ) { System.err.println( "ALT" ) ; } - if( ( awtMods & java.awt.event.InputEvent.ALT_GRAPH_MASK ) != 0 ) { System.err.println( "ALT_GRAPH" ) ; } - - if( ( awtModsEx & java.awt.event.InputEvent.SHIFT_DOWN_MASK ) != 0 ) { System.err.println( "SHIFT Ex" ) ; } - if( ( awtModsEx & java.awt.event.InputEvent.CTRL_DOWN_MASK ) != 0 ) { System.err.println( "CTRL Ex" ) ; } - if( ( awtModsEx & java.awt.event.InputEvent.META_DOWN_MASK ) != 0 ) { System.err.println( "META Ex" ) ; } - if( ( awtModsEx & java.awt.event.InputEvent.ALT_DOWN_MASK ) != 0 ) { System.err.println( "ALT Ex" ) ; } - if( ( awtModsEx & java.awt.event.InputEvent.ALT_GRAPH_DOWN_MASK ) != 0 ) { System.err.println( "ALT_GRAPH Ex" ) ; } - if( ( awtModsEx & java.awt.event.InputEvent.BUTTON1_DOWN_MASK ) != 0 ) { System.err.println( "BUTTON1" ) ; } - if( ( awtModsEx & java.awt.event.InputEvent.BUTTON2_DOWN_MASK ) != 0 ) { System.err.println( "BUTTON2" ) ; } - if( ( awtModsEx & java.awt.event.InputEvent.BUTTON3_DOWN_MASK ) != 0 ) { System.err.println( "BUTTON3" ) ; } - } - - public ArrayList getFailures() { - return _failures ; - } - - public void mouseClicked( com.jogamp.newt.event.MouseEvent event ) { - _checkModifiers( event ) ; - } - - public void mousePressed( com.jogamp.newt.event.MouseEvent event ) { - _checkModifiers( event ) ; - } - - public void mouseReleased( com.jogamp.newt.event.MouseEvent event ) { - _checkModifiers( event ) ; - } - - public void mouseEntered( com.jogamp.newt.event.MouseEvent event ) { - _checkModifiers( event ) ; - } - - public void mouseExited( com.jogamp.newt.event.MouseEvent event ) { - _checkModifiers( event ) ; - } - - public void mouseDragged( com.jogamp.newt.event.MouseEvent event ) { - _checkModifiers( event ) ; - } - - public void mouseMoved( com.jogamp.newt.event.MouseEvent event ) { - _checkModifiers( event ) ; - } - - public void mouseWheelMoved( com.jogamp.newt.event.MouseEvent event ) { - _checkModifiers( event ) ; - } - } - - //////////////////////////////////////////////////////////////////////////// - - protected static final int TEST_FRAME_X = 100 ; - protected static final int TEST_FRAME_Y = 100 ; - - protected static final int TEST_FRAME_WIDTH = 400 ; - protected static final int TEST_FRAME_HEIGHT = 400 ; - - private static final int INITIAL_MOUSE_X = TEST_FRAME_X + ( TEST_FRAME_WIDTH / 2 ) ; - private static final int INITIAL_MOUSE_Y = TEST_FRAME_Y + ( TEST_FRAME_HEIGHT / 2 ) ; - - private static final int MS_ROBOT_SHORT_AUTO_DELAY = 50 ; - private static final int MS_ROBOT_LONG_AUTO_DELAY = 500 ; - - private static boolean _debug = true ; - private static PrintStream _debugPrintStream = System.err ; - - //////////////////////////////////////////////////////////////////////////// - - private static int _numButtonsToTest ; - private static int _awtButtonMasks[] ; - private static int _newtButtonMasks[] ; - - private static java.awt.Robot _robot ; - - protected static TestMouseListener _testMouseListener ; - - //////////////////////////////////////////////////////////////////////////// - - public static int getAWTButtonMask(int button) { - int m; - switch(button) { - case 1 : m = java.awt.event.InputEvent.BUTTON1_MASK; break; - case 2 : m = java.awt.event.InputEvent.BUTTON2_MASK; break; - case 3 : m = java.awt.event.InputEvent.BUTTON3_MASK; break; - default: throw new IllegalArgumentException("Only buttons 1-3 have a MASK value, requested button "+button); - } - return m; - } - - @BeforeClass - public static void beforeClass() throws Exception { - - // Who know how many buttons the AWT will say exist on given platform. - // We'll test the smaller of what NEWT supports and what the - // AWT says is available. - // _numButtonsToTest = java.awt.MouseInfo.getNumberOfButtons() ; - - // Then again, maybe not: - - // FIXME? - for reasons I'm not quite sure of the AWT MouseEvent - // constructor does some strange things for buttons other than - // 1, 2, and 3. Furthermore, while developing this test it - // appeared that events sent by the robot for buttons 9 and - // up weren't even delivered to the listeners. - // - // So... for now we're only going to test 3 buttons since - // that's the common case. - - _numButtonsToTest = 3 ; - - { - if( _numButtonsToTest > com.jogamp.newt.event.MouseEvent.BUTTON_NUMBER ) { - _numButtonsToTest = com.jogamp.newt.event.MouseEvent.BUTTON_NUMBER ; - } - - // These two arrays are assumed to be peers, i.e. are the same - // size, and a given index references the same button in - // either array. - - _awtButtonMasks = new int[_numButtonsToTest] ; - - for( int n = 0 ; n < _awtButtonMasks.length ; ++n ) { - _awtButtonMasks[n] = getAWTButtonMask( n + 1 ); - } - - _newtButtonMasks = new int[_numButtonsToTest] ; - - for( int n = 0 ; n < _newtButtonMasks.length ; ++n ) { - _newtButtonMasks[n] = com.jogamp.newt.event.InputEvent.getButtonMask( n + 1 ) ; - } - } - - _robot = new java.awt.Robot() ; - _robot.setAutoWaitForIdle( true ) ; - _robot.setAutoDelay( MS_ROBOT_LONG_AUTO_DELAY ) ; - - _testMouseListener = new TestMouseListener() ; - } - - //////////////////////////////////////////////////////////////////////////// - - @Before - public void before() throws Exception { - - _testMouseListener.setModifierCheckEnabled( false ) ; - _robot.setAutoDelay( MS_ROBOT_SHORT_AUTO_DELAY ) ; - - // Make sure all the buttons and modifier keys are released. - - _releaseModifiers() ; - _escape() ; - - // Move the pointer into the window and click once to - // ensure that the test window has focus. - - if( _debug ) { - _debugPrintStream.println( ">>>> Clicking in the window to get focus." ) ; - } - - _robot.mouseMove( INITIAL_MOUSE_X, INITIAL_MOUSE_Y ) ; - _robot.mousePress( java.awt.event.InputEvent.BUTTON1_DOWN_MASK ) ; - _robot.mouseRelease( java.awt.event.InputEvent.BUTTON1_DOWN_MASK ) ; - - _testMouseListener.setModifierCheckEnabled( true ) ; - _robot.setAutoDelay( MS_ROBOT_LONG_AUTO_DELAY ) ; - - if( _debug ) { - _debugPrintStream.println( ">>>> About to start testing." ) ; - } - } - - //////////////////////////////////////////////////////////////////////////// - - // The approach on all these tests is to tell the test mouse listener what - // modifiers we think it should receive. Then when the events are delivered - // it compares what we told it to expect with what actually showed up and - // complains if there are differences. - // - // As things stand currently the tests below generally work for AWTCanvas - // and fail for everything else. This may point to a flaw in the test - // code, or a flaw in the NEWT stuff; not sure yet. One exception is the - // tests involving ALT and META, which on at least X11 cause the desktop - // to do undesirable stuff while the tests are in progress. So... these - // tests have been commented out for now and probably should be left - // that way. - // - // Due to the fact that a majority of these fail currently for - // everything but AWTCanvas for the time being we probably shouldn't - // run the tests for NewtCanvasAWT and NewtCanvasSWT until we can - // pay more attention to the NEWT event modifier stuff. - - @Test - public void testSingleButtonPressAndRelease() throws Exception { - _doSingleButtonPressAndRelease( 0, 0 ) ; - } - - @Test - public void testSingleButtonPressAndReleaseWithShift() throws Exception { - _doSingleButtonPressAndRelease( java.awt.event.KeyEvent.VK_SHIFT, java.awt.event.InputEvent.SHIFT_DOWN_MASK ) ; - } - - @Test - public void testSingleButtonPressAndReleaseWithCtrl() throws Exception { - _doSingleButtonPressAndRelease( java.awt.event.KeyEvent.VK_CONTROL, java.awt.event.InputEvent.CTRL_DOWN_MASK ) ; - } - - // The META and ALT tests get too tied up with functions of the window system on X11, - // so it's probably best to leave them commented out. - - //@Test - //public void testSingleButtonPressAndReleaseWithMeta() throws Exception { - // _doSingleButtonPressAndRelease( java.awt.event.KeyEvent.VK_META, java.awt.event.InputEvent.META_DOWN_MASK ) ; - //} - - //@Test - //public void testSingleButtonPressAndReleaseWithAlt() throws Exception { - // _doSingleButtonPressAndRelease( java.awt.event.KeyEvent.VK_ALT, java.awt.event.InputEvent.ALT_DOWN_MASK ) ; - //} - - // FIXME - not sure yet what's up with ALT_GRAPH. It appears that this - // modifier didn't make it through, so I had to disable this test else - // it would always fail. - // - // My US keyboard doesn't have an AltGr key, so maybe X is smart - // enough to not let this modifier slip through (?). - - //@Test - //public void testSingleButtonPressAndReleaseWithAltGraph() throws Exception { - // _doSingleButtonPressAndRelease( java.awt.event.KeyEvent.VK_ALT_GRAPH, java.awt.event.InputEvent.ALT_GRAPH_DOWN_MASK ) ; - //} - - //////////////////////////////////////////////////////////////////////////// - - @Test - public void testHoldOneButtonAndPressAnother() throws Exception { - _doHoldOneButtonAndPressAnother( 0, 0 ) ; - } - - @Test - public void testPressAllButtonsInSequence() throws Exception { - _doPressAllButtonsInSequence( 0, 0 ) ; - } - - @Test - public void testSingleButtonClickAndDrag() throws Exception { - _doSingleButtonClickAndDrag( 0, 0 ) ; - } - - //////////////////////////////////////////////////////////////////////////// - - private void _doSingleButtonPressAndRelease( final int keyCode, final int keyModifierMask ) throws Exception { - - if( _debug ) { _debugPrintStream.println( "\n>>>> _doSingleButtonPressAndRelease" ) ; } - - _doKeyPress( keyCode ) ; - - for (int n = 0 ; n < _numButtonsToTest ; ++n) { - - int awtButtonMask = _awtButtonMasks[n] ; - - if( _debug ) { _debugPrintStream.println( "\n pressing button " + ( n + 1 ) ) ; } - _testMouseListener.setExpectedModifiers( _getNewtModifiersForAwtExtendedModifiers( keyModifierMask | awtButtonMask ) ) ; - _robot.mousePress( awtButtonMask ) ; - _checkFailures() ; - - if( _debug ) { _debugPrintStream.println( "\n releasing button " + ( n + 1 ) ) ; } - _testMouseListener.setExpectedModifiers( _getNewtModifiersForAwtExtendedModifiers( keyModifierMask ) ) ; - _robot.mouseRelease( awtButtonMask ) ; - _checkFailures() ; - } - - _doKeyRelease( keyCode ) ; - } - - //////////////////////////////////////////////////////////////////////////// - - private void _doHoldOneButtonAndPressAnother( final int keyCode, final int keyModifierMask ) throws Exception { - - if( _debug ) { _debugPrintStream.println( "\n>>>> _doHoldOneButtonAndPressAnother" ) ; } - - _doKeyPress( keyCode ) ; - - for (int n = 0 ; n < _numButtonsToTest ; ++n) { - - int awtButtonMask = _awtButtonMasks[n] ; - - if( _debug ) { _debugPrintStream.println( "\n pressing button " + ( n + 1 ) ) ; } - _testMouseListener.setExpectedModifiers( _getNewtModifiersForAwtExtendedModifiers( keyModifierMask | awtButtonMask ) ) ; - _robot.mousePress( awtButtonMask ) ; - _checkFailures() ; - - for (int m = 0 ; m < _numButtonsToTest ; ++m) { - - if( n != m ) { - - if( _debug ) { _debugPrintStream.println( "\n pressing additional button " + ( m + 1 ) ) ; } - _testMouseListener.setExpectedModifiers( _getNewtModifiersForAwtExtendedModifiers( keyModifierMask | awtButtonMask | _awtButtonMasks[m] ) ) ; - _robot.mousePress( _awtButtonMasks[m] ) ; - _checkFailures() ; - - if( _debug ) { _debugPrintStream.println( "\n releasing additional button " + ( m + 1 ) ) ; } - _testMouseListener.setExpectedModifiers( _getNewtModifiersForAwtExtendedModifiers( keyModifierMask | awtButtonMask ) ) ; - _robot.mouseRelease( _awtButtonMasks[m] ) ; - _checkFailures() ; - } - } - - if( _debug ) { _debugPrintStream.println( "\n releasing button " + ( n + 1 ) ) ; } - _testMouseListener.setExpectedModifiers( _getNewtModifiersForAwtExtendedModifiers( keyModifierMask ) ) ; - _robot.mouseRelease( awtButtonMask ) ; - _checkFailures() ; - } - - _doKeyRelease( keyCode ) ; - } - - //////////////////////////////////////////////////////////////////////////// - - private void _doPressAllButtonsInSequence( final int keyCode, final int keyModifierMask ) throws Exception { - - if( _debug ) { _debugPrintStream.println( "\n>>>> _doPressAllButtonsInSequence" ) ; } - - _doKeyPress( keyCode ) ; - - { - int cumulativeAwtModifiers = 0 ; - - for (int n = 0 ; n < _numButtonsToTest ; ++n) { - - cumulativeAwtModifiers |= _awtButtonMasks[n] ; - - if( _debug ) { _debugPrintStream.println( "\n pressing button " + ( n + 1 ) ) ; } - _testMouseListener.setExpectedModifiers( _getNewtModifiersForAwtExtendedModifiers( keyModifierMask | cumulativeAwtModifiers ) ) ; - _robot.mousePress( _awtButtonMasks[n] ) ; - _checkFailures() ; - } - - for (int n = _numButtonsToTest - 1 ; n >= 0 ; --n) { - - cumulativeAwtModifiers &= ~_awtButtonMasks[n] ; - - if( _debug ) { _debugPrintStream.println( "\n releasing button " + ( n + 1 ) ) ; } - _testMouseListener.setExpectedModifiers( _getNewtModifiersForAwtExtendedModifiers( keyModifierMask | cumulativeAwtModifiers ) ) ; - _robot.mouseRelease( _awtButtonMasks[n] ) ; - _checkFailures() ; - } - } - - _doKeyRelease( keyCode ) ; - } - - //////////////////////////////////////////////////////////////////////////// - - private void _doSingleButtonClickAndDrag( final int keyCode, final int keyModifierMask ) throws Exception { - - if( _debug ) { _debugPrintStream.println( "\n>>>> _doSingleButtonClickAndDrag" ) ; } - - _doKeyPress( keyCode ) ; - - _testMouseListener.setModifierCheckEnabled( true ) ; - - for (int n = 0 ; n < _numButtonsToTest ; ++n) { - - int awtButtonMask = _awtButtonMasks[n] ; - - if( _debug ) { _debugPrintStream.println( "\n pressing button " + ( n + 1 ) ) ; } - _testMouseListener.setExpectedModifiers( _getNewtModifiersForAwtExtendedModifiers( keyModifierMask | awtButtonMask ) ) ; - _robot.mousePress( awtButtonMask ) ; - _checkFailures() ; - - // To get a drag we only need to move one pixel. - if( _debug ) { _debugPrintStream.println( "\n moving mouse" ) ; } - _robot.mouseMove( INITIAL_MOUSE_X + 1, INITIAL_MOUSE_Y + 1 ) ; - _checkFailures() ; - - if( _debug ) { _debugPrintStream.println( "\n releasing button " + ( n + 1 ) ) ; } - _testMouseListener.setExpectedModifiers( _getNewtModifiersForAwtExtendedModifiers( keyModifierMask ) ) ; - _robot.mouseRelease( awtButtonMask ) ; - _checkFailures() ; - - _testMouseListener.setModifierCheckEnabled( false ) ; - _robot.mouseMove( INITIAL_MOUSE_X, INITIAL_MOUSE_Y ) ; - _testMouseListener.setModifierCheckEnabled( true ) ; - } - - _doKeyRelease( keyCode ) ; - } - - //////////////////////////////////////////////////////////////////////////// - - private void _doKeyPress( int keyCode ) { - if( keyCode != 0 ) { - boolean modifierCheckEnabled = _testMouseListener.modifierCheckEnabled() ; - _testMouseListener.setModifierCheckEnabled( false ) ; - _robot.keyPress( keyCode ) ; - _testMouseListener.setModifierCheckEnabled( modifierCheckEnabled ) ; - } - } - - //////////////////////////////////////////////////////////////////////////// - - private void _doKeyRelease( int keyCode ) { - if( keyCode != 0 ) { - boolean modifierCheckEnabled = _testMouseListener.modifierCheckEnabled() ; - _testMouseListener.setModifierCheckEnabled( false ) ; - _robot.keyRelease( keyCode ) ; - _testMouseListener.setModifierCheckEnabled( modifierCheckEnabled ) ; - } - } - - //////////////////////////////////////////////////////////////////////////// - - private void _checkFailures() { - - ArrayList failures = _testMouseListener.getFailures() ; - - if( _debug ) { - int numFailures = failures.size() ; - if( numFailures == 0 ) { - _debugPrintStream.println( " PASSED" ) ; - } else { - _debugPrintStream.println( " FAILED" ) ; - for( int n = 0 ; n < numFailures ; ++n ) { - _debugPrintStream.print( " " ) ; - _debugPrintStream.println( failures.get(n) ) ; - } - } - } - - Assert.assertTrue( failures.size() == 0 ) ; - } - - //////////////////////////////////////////////////////////////////////////// - - @After - public void after() throws Exception { - - _testMouseListener.setModifierCheckEnabled( false ) ; - - Thread.sleep( 500 ) ; - } - - //////////////////////////////////////////////////////////////////////////// - - @AfterClass - public static void afterClass() throws Exception { - - // Make sure all modifiers are released, otherwise the user's - // desktop can get locked up (ask me how I know this). - - _releaseModifiers() ; - _escape() ; - } - - //////////////////////////////////////////////////////////////////////////// - - private static void _releaseModifiers() { - - if (_robot != null) { - - _robot.setAutoDelay( MS_ROBOT_SHORT_AUTO_DELAY ) ; - - boolean modifierCheckEnabled = _testMouseListener.modifierCheckEnabled() ; - _testMouseListener.setModifierCheckEnabled( false ) ; - - { - _robot.keyRelease( java.awt.event.KeyEvent.VK_SHIFT ) ; - _robot.keyRelease( java.awt.event.KeyEvent.VK_CONTROL ) ; - _robot.keyRelease( java.awt.event.KeyEvent.VK_META ) ; - _robot.keyRelease( java.awt.event.KeyEvent.VK_ALT ) ; - _robot.keyRelease( java.awt.event.KeyEvent.VK_ALT_GRAPH ) ; - - for (int n = 0 ; n < _awtButtonMasks.length ; ++n) { - _robot.mouseRelease( _awtButtonMasks[n] ) ; - } - } - - _testMouseListener.setModifierCheckEnabled( modifierCheckEnabled ) ; - - _robot.setAutoDelay( MS_ROBOT_LONG_AUTO_DELAY ) ; - } - } - - private static void _escape() { - if (_robot != null) { - _robot.keyPress( java.awt.event.KeyEvent.VK_ESCAPE ) ; - _robot.keyRelease( java.awt.event.KeyEvent.VK_ESCAPE ) ; - } - } - - //////////////////////////////////////////////////////////////////////////// - - /** - * Brute force method to return the NEWT event modifiers equivalent - * to the specified AWT event extended modifiers. - * - * @param awtExtendedModifiers - * The AWT extended modifiers. - * - * @return - * The equivalent NEWT modifiers. - */ - - private int _getNewtModifiersForAwtExtendedModifiers( int awtExtendedModifiers ) { - - int mask = 0 ; - - if( ( awtExtendedModifiers & java.awt.event.InputEvent.SHIFT_DOWN_MASK ) != 0 ) { - mask |= com.jogamp.newt.event.InputEvent.SHIFT_MASK ; - } - - if( ( awtExtendedModifiers & java.awt.event.InputEvent.CTRL_DOWN_MASK ) != 0 ) { - mask |= com.jogamp.newt.event.InputEvent.CTRL_MASK ; - } - - if( ( awtExtendedModifiers & java.awt.event.InputEvent.META_DOWN_MASK ) != 0 ) { - mask |= com.jogamp.newt.event.InputEvent.META_MASK ; - } - - if( ( awtExtendedModifiers & java.awt.event.InputEvent.ALT_DOWN_MASK ) != 0 ) { - mask |= com.jogamp.newt.event.InputEvent.ALT_MASK ; - } - - if( ( awtExtendedModifiers & java.awt.event.InputEvent.ALT_GRAPH_DOWN_MASK ) != 0 ) { - mask |= com.jogamp.newt.event.InputEvent.ALT_GRAPH_MASK ; - } - - for (int n = 0 ; n < _numButtonsToTest ; ++n) { - if ((awtExtendedModifiers & getAWTButtonMask(n+1)) != 0) { - mask |= com.jogamp.newt.event.InputEvent.getButtonMask(n+1) ; - } - } - - return mask ; - } - - //////////////////////////////////////////////////////////////////////////// -} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersAWTCanvas.java b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersAWTCanvas.java index 3aa016d56..fd68ace73 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersAWTCanvas.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersAWTCanvas.java @@ -44,7 +44,7 @@ import com.jogamp.newt.event.awt.AWTMouseAdapter ; * the source is an AWT canvas. */ -public class TestNewtEventModifiersAWTCanvas extends TestNewtEventModifiers { +public class TestNewtEventModifiersAWTCanvas extends BaseNewtEventModifiers { private static JFrame _testFrame ; @@ -53,7 +53,7 @@ public class TestNewtEventModifiersAWTCanvas extends TestNewtEventModifiers { @BeforeClass public static void beforeClass() throws Exception { - TestNewtEventModifiers.beforeClass() ; + BaseNewtEventModifiers.beforeClass() ; final GLCanvas canvas = new GLCanvas() ; canvas.addGLEventListener( new BigGreenXGLEventListener() ) ; @@ -76,7 +76,7 @@ public class TestNewtEventModifiersAWTCanvas extends TestNewtEventModifiers { @AfterClass public static void afterClass() throws Exception { - TestNewtEventModifiers.afterClass() ; + BaseNewtEventModifiers.afterClass() ; SwingUtilities.invokeAndWait(new Runnable() { public void run() { diff --git a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNewtCanvasAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNewtCanvasAWT.java index a2c1d3364..44f116ea1 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNewtCanvasAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNewtCanvasAWT.java @@ -48,7 +48,7 @@ import com.jogamp.newt.opengl.GLWindow ; * the canvas is a NewtCanvasAWT. */ -public class TestNewtEventModifiersNewtCanvasAWT extends TestNewtEventModifiers { +public class TestNewtEventModifiersNewtCanvasAWT extends BaseNewtEventModifiers { private static JFrame _testFrame ; private static GLWindow _glWindow ; @@ -58,7 +58,7 @@ public class TestNewtEventModifiersNewtCanvasAWT extends TestNewtEventModifiers @BeforeClass public static void beforeClass() throws Exception { - TestNewtEventModifiers.beforeClass() ; + BaseNewtEventModifiers.beforeClass() ; SwingUtilities.invokeAndWait( new Runnable() { public void run() { @@ -89,7 +89,7 @@ public class TestNewtEventModifiersNewtCanvasAWT extends TestNewtEventModifiers @AfterClass public static void afterClass() throws Exception { - TestNewtEventModifiers.afterClass() ; + BaseNewtEventModifiers.afterClass() ; SwingUtilities.invokeAndWait( new Runnable() { public void run() { diff --git a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNewtCanvasSWT.java b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNewtCanvasSWT.java index e6139bb37..501e0d1bd 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNewtCanvasSWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNewtCanvasSWT.java @@ -47,7 +47,7 @@ import com.jogamp.newt.swt.NewtCanvasSWT ; * the canvas is a NewtCanvasSWT. */ -public class TestNewtEventModifiersNewtCanvasSWT extends TestNewtEventModifiers { +public class TestNewtEventModifiersNewtCanvasSWT extends BaseNewtEventModifiers { private static Shell _testShell ; private static GLWindow _glWindow ; @@ -87,7 +87,7 @@ public class TestNewtEventModifiersNewtCanvasSWT extends TestNewtEventModifiers @BeforeClass public static void beforeClass() throws Exception { - TestNewtEventModifiers.beforeClass() ; + BaseNewtEventModifiers.beforeClass() ; _displayThread = new DisplayThread() ; _displayThread.start() ; @@ -127,7 +127,7 @@ public class TestNewtEventModifiersNewtCanvasSWT extends TestNewtEventModifiers @AfterClass public static void afterClass() throws Exception { - TestNewtEventModifiers.afterClass() ; + BaseNewtEventModifiers.afterClass() ; _glWindow.destroy() ; -- cgit v1.2.3