diff options
-rw-r--r-- | src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java | 90 | ||||
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiers.java | 39 |
2 files changed, 66 insertions, 63 deletions
diff --git a/src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java b/src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java index b8ab3176a..28174f139 100644 --- a/src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java +++ b/src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java @@ -34,7 +34,24 @@ import com.jogamp.newt.event.InputEvent; 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; + } + static { IntIntHashMap map = new IntIntHashMap(); map.setKeyNotFoundValue(0xFFFFFFFF); @@ -70,27 +87,14 @@ public class AWTNewtEventFactory { map.put(java.awt.event.KeyEvent.KEY_TYPED, com.jogamp.newt.event.KeyEvent.EVENT_KEY_TYPED); eventTypeAWT2NEWT = map; - } - - // Define the button state masks we'll check based on what - // the AWT says is available. - - private static int awtButtonMasks[] ; - private static int newtButtonMasks[] ; - - static { + + final int numButtonMasks ; - int numButtonMasks ; - - if (java.awt.Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled()) { - numButtonMasks = java.awt.MouseInfo.getNumberOfButtons() ; - } else { - numButtonMasks = 3 ; - } - - if (numButtonMasks > com.jogamp.newt.event.MouseEvent.BUTTON_NUMBER) { - numButtonMasks = com.jogamp.newt.event.MouseEvent.BUTTON_NUMBER ; - } + // 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. @@ -98,15 +102,16 @@ public class AWTNewtEventFactory { awtButtonMasks = new int[numButtonMasks] ; for (int n = 0 ; n < awtButtonMasks.length ; ++n) { - awtButtonMasks[n] = java.awt.event.InputEvent.getMaskForButton(n+1) ; + awtButtonMasks[n] = getAWTButtonMask(n+1); } newtButtonMasks = new int[numButtonMasks] ; for (int n = 0 ; n < newtButtonMasks.length ; ++n) { newtButtonMasks[n] = com.jogamp.newt.event.InputEvent.getButtonMask(n+1) ; - } + } } + /** * Converts the specified set of AWT event modifiers to the equivalent * NEWT event modifiers. This method doesn't pay attention to the AWT @@ -123,7 +128,6 @@ public class AWTNewtEventFactory { * @param mouseHint * Not used currently. */ - 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; @@ -149,57 +153,33 @@ public class AWTNewtEventFactory { * * @param awtModsEx * The AWT extended event modifiers. + * AWT passes mouse button specific bits here and are the preferred way check the mouse button state. * * @param mouseHint * Not used currently. */ - public static final int awtModifiers2Newt(final int awtMods, final int awtModsEx, final boolean mouseHint) { int newtMods = 0; - - //System.err.println( ">>>> AWT modifiers:") ; - //_printAwtModifiers( awtMods, awtModsEx ) ; - //System.err.println( ">>>> END AWT modifiers") ; - - // Bug 629: - // - // AWT defines the notion of "extended modifiers". They put other bits there - // specific to the mouse buttons and say that these are the preferred bits to - // check for mouse button state. This seems to hint that at some point they - // may be the only way to get this info. - 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] ; } - } + } */ return newtMods; } -/* - 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 static final int awtButton2Newt(int awtButton) { switch (awtButton) { case java.awt.event.MouseEvent.BUTTON1: return com.jogamp.newt.event.MouseEvent.BUTTON1; 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 index 36185f8ce..81e1939b9 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiers.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiers.java @@ -216,6 +216,23 @@ public abstract class TestNewtEventModifiers extends UITestCase { 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<String> getFailures() { return _failures ; } @@ -282,18 +299,24 @@ public abstract class TestNewtEventModifiers extends UITestCase { //////////////////////////////////////////////////////////////////////////// + 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. - - if( java.awt.Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled() ) { - _numButtonsToTest = java.awt.MouseInfo.getNumberOfButtons() ; - } else { - _numButtonsToTest = 3 ; - } + // _numButtonsToTest = java.awt.MouseInfo.getNumberOfButtons() ; // Then again, maybe not: @@ -320,7 +343,7 @@ public abstract class TestNewtEventModifiers extends UITestCase { _awtButtonMasks = new int[_numButtonsToTest] ; for( int n = 0 ; n < _awtButtonMasks.length ; ++n ) { - _awtButtonMasks[n] = java.awt.event.InputEvent.getMaskForButton( n + 1 ) ; + _awtButtonMasks[n] = getAWTButtonMask( n + 1 ); } _newtButtonMasks = new int[_numButtonsToTest] ; @@ -726,7 +749,7 @@ public abstract class TestNewtEventModifiers extends UITestCase { } for (int n = 0 ; n < _numButtonsToTest ; ++n) { - if ((awtExtendedModifiers & java.awt.event.InputEvent.getMaskForButton(n+1)) != 0) { + if ((awtExtendedModifiers & getAWTButtonMask(n+1)) != 0) { mask |= com.jogamp.newt.event.InputEvent.getButtonMask(n+1) ; } } |