diff options
author | Sven Gothel <[email protected]> | 2011-11-19 19:32:00 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-11-19 19:32:00 +0100 |
commit | 8a985f8652151684063853f61e479d75d8203f07 (patch) | |
tree | 14acfc1230a974397e52803eefd6785f73be92c9 /src/test | |
parent | 2641d1cffebff214c4b37d7291627f76cc3bbe3f (diff) |
NEWT/AWT Focus traversal enhancement/fix (incl. OS X fixes)
- MacWindow/OffscreeSurface
- Exclude native NEWT window calls in case it's an offscreen surface
- MacWindow/DriverClearFocus
- Introduce driver detail DriverClearFocus interface
- OS X needs to clear the focus, before another TK (eg. AWT) can claim it's (native parent window focus)
- MacWindow/KeyCode:
- Move OS X keyCode utils to MacKeyUtil
- MacKeyUtil now uses OS X virtual key codes first, before matching keyChar -> keyCode
- NewtCanvasAWT
- Issue all AWT 'requestFocus()' on current thread,
Newt-EDT -> AWT-EDT may freeze Window's native peer requestFocus() impl.
- FocusAction directly issue action on Newt-EDT,
also request AWT focus if not having it (proper AWT traversal)
- Add an FocusPropertyChangeListener, detecting focus lost
to issue DriverClearFocus's clearFocus() if available.
- merge configureNewtChildInputEventHandler() code into configureNewtChild()
to simplify call tree.
- WindowImplAccess: Use getDelegatedWindow()
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingFocusTraversal01AWT.java | 117 | ||||
-rw-r--r-- | src/test/jogamp/newt/WindowImplAccess.java | 16 |
2 files changed, 98 insertions, 35 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingFocusTraversal01AWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingFocusTraversal01AWT.java index cb94d8f02..75b94f203 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingFocusTraversal01AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingFocusTraversal01AWT.java @@ -52,15 +52,19 @@ import com.jogamp.opengl.util.Animator; import com.jogamp.newt.*; import com.jogamp.newt.opengl.*; import com.jogamp.newt.awt.NewtCanvasAWT; +import com.jogamp.newt.event.KeyAdapter; +import com.jogamp.newt.event.KeyEvent; import java.io.IOException; +import jogamp.newt.driver.DriverClearFocus; + import com.jogamp.opengl.test.junit.util.*; import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; public class TestParentingFocusTraversal01AWT extends UITestCase { static Dimension glSize, fSize; - static int numFocus = 5; + static int numFocus = 8; static long durationPerTest = numFocus * 100; static GLCapabilities glCaps; static boolean manual = false; @@ -73,11 +77,16 @@ public class TestParentingFocusTraversal01AWT extends UITestCase { } @Test - public void testWindowParentingAWTFocusTraversal01() throws InterruptedException, InvocationTargetException, AWTException { - testWindowParentingAWTFocusTraversal(); + public void testWindowParentingAWTFocusTraversal01Onscreen() throws InterruptedException, InvocationTargetException, AWTException { + testWindowParentingAWTFocusTraversal(true); } - public void testWindowParentingAWTFocusTraversal() throws InterruptedException, InvocationTargetException, AWTException { + @Test + public void testWindowParentingAWTFocusTraversal02Offscreen() throws InterruptedException, InvocationTargetException, AWTException { + testWindowParentingAWTFocusTraversal(false); + } + + public void testWindowParentingAWTFocusTraversal(boolean onscreen) throws InterruptedException, InvocationTargetException, AWTException { Robot robot = new Robot(); // Bug 4908075 - http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4908075 @@ -105,43 +114,73 @@ public class TestParentingFocusTraversal01AWT extends UITestCase { } final Frame frame1 = new Frame("AWT Parent Frame"); - final Button bWest = new Button("WEST"); - final Button bEast = new Button("EAST"); - GLWindow glWindow1 = GLWindow.create(glCaps); + final Button cWest = new Button("WEST"); + final Button cEast = new Button("EAST"); + final GLWindow glWindow1 = GLWindow.create(glCaps); glWindow1.setUpdateFPSFrames(1, null); final NewtCanvasAWT newtCanvasAWT1 = new NewtCanvasAWT(glWindow1); newtCanvasAWT1.setPreferredSize(glSize); + newtCanvasAWT1.setShallUseOffscreenLayer(!onscreen); + newtCanvasAWT1.setFocusable(true); // Test FocusAdapter NEWTFocusAdapter glWindow1FA = new NEWTFocusAdapter("GLWindow1"); glWindow1.addWindowListener(glWindow1FA); AWTFocusAdapter bWestFA = new AWTFocusAdapter("WEST"); - bWest.addFocusListener(bWestFA); + cWest.addFocusListener(bWestFA); AWTFocusAdapter bEastFA = new AWTFocusAdapter("EAST"); - bEast.addFocusListener(bEastFA); + cEast.addFocusListener(bEastFA); // Test KeyAdapter NEWTKeyAdapter glWindow1KA = new NEWTKeyAdapter("GLWindow1"); glWindow1.addKeyListener(glWindow1KA); - AWTKeyAdapter bWestKA = new AWTKeyAdapter("bWest"); - bWest.addKeyListener(bWestKA); - AWTKeyAdapter bEastKA = new AWTKeyAdapter("bEast"); - bEast.addKeyListener(bEastKA); + AWTKeyAdapter bWestKA = new AWTKeyAdapter("West"); + cWest.addKeyListener(bWestKA); + AWTKeyAdapter bEastKA = new AWTKeyAdapter("East"); + cEast.addKeyListener(bEastKA); // demo .. GLEventListener demo1 = new GearsES2(1); setDemoFields(demo1, glWindow1, false); glWindow1.addGLEventListener(demo1); glWindow1.addKeyListener(new NewtAWTReparentingKeyAdapter(frame1, newtCanvasAWT1, glWindow1)); + glWindow1.addKeyListener(new KeyAdapter() { + public void keyTyped(KeyEvent e) { + if(e.getKeyChar()=='c') { + System.err.println("Focus Clear"); + if(glWindow1.getDelegatedWindow() instanceof DriverClearFocus) { + ((DriverClearFocus)glWindow1.getDelegatedWindow()).clearFocus(); + } + } else if(e.getKeyChar()=='e') { + System.err.println("Focus East"); + try { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + cEast.requestFocusInWindow(); + } + }); + } catch (Exception ex) { ex.printStackTrace(); } + } else if(e.getKeyChar()=='w') { + System.err.println("Focus West"); + try { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + cWest.requestFocusInWindow(); + } + }); + } catch (Exception ex) { ex.printStackTrace(); } + } + } + }); GLAnimatorControl animator1 = new Animator(glWindow1); animator1.start(); // make frame frame1.setLayout(new BorderLayout()); frame1.setLayout(new BorderLayout()); - frame1.add(bWest, BorderLayout.WEST); + frame1.add(cWest, BorderLayout.WEST); frame1.add(newtCanvasAWT1, BorderLayout.CENTER); - frame1.add(bEast, BorderLayout.EAST); + frame1.add(cEast, BorderLayout.EAST); frame1.setLocation(0, 0); frame1.setSize(fSize); @@ -163,7 +202,7 @@ public class TestParentingFocusTraversal01AWT extends UITestCase { // // initial focus on bWest // - AWTRobotUtil.assertRequestFocusAndWait(robot, bWest, bWest, bWestFA, null); + AWTRobotUtil.assertRequestFocusAndWait(robot, cWest, cWest, bWestFA, null); Assert.assertEquals(true, bWestFA.focusGained()); Thread.sleep(durationPerTest/numFocus); @@ -172,7 +211,7 @@ public class TestParentingFocusTraversal01AWT extends UITestCase { // // bWest -> glWin - AWTRobotUtil.keyType(0, robot, java.awt.event.KeyEvent.VK_TAB, bWest, null); + AWTRobotUtil.keyType(0, robot, java.awt.event.KeyEvent.VK_TAB, cWest, null); Assert.assertTrue("Did not gain focus", AWTRobotUtil.waitForFocus(glWindow1, glWindow1FA, bWestFA)); Assert.assertEquals(true, glWindow1FA.focusGained()); Assert.assertEquals(true, bWestFA.focusLost()); @@ -180,7 +219,7 @@ public class TestParentingFocusTraversal01AWT extends UITestCase { // glWin -> bEast AWTRobotUtil.keyType(0, robot, java.awt.event.KeyEvent.VK_TAB, glWindow1, null); - Assert.assertTrue("Did not gain focus", AWTRobotUtil.waitForFocus(bEast, bEastFA, glWindow1FA)); + Assert.assertTrue("Did not gain focus", AWTRobotUtil.waitForFocus(cEast, bEastFA, glWindow1FA)); Assert.assertEquals(true, bEastFA.focusGained()); Assert.assertEquals(true, glWindow1FA.focusLost()); Thread.sleep(durationPerTest/numFocus); @@ -189,17 +228,51 @@ public class TestParentingFocusTraversal01AWT extends UITestCase { // back (using custom back traversal key 'backspace') // // bEast -> glWin - AWTRobotUtil.keyType(0, robot, java.awt.event.KeyEvent.VK_BACK_SPACE, bEast, null); + AWTRobotUtil.keyType(0, robot, java.awt.event.KeyEvent.VK_BACK_SPACE, cEast, null); Assert.assertTrue("Did not gain focus", AWTRobotUtil.waitForFocus(glWindow1, glWindow1FA, bEastFA)); Assert.assertEquals(true, glWindow1FA.focusGained()); Assert.assertEquals(true, bEastFA.focusLost()); Thread.sleep(durationPerTest/numFocus); AWTRobotUtil.keyType(0, robot, java.awt.event.KeyEvent.VK_BACK_SPACE, glWindow1, null); - Assert.assertTrue("Did not gain focus", AWTRobotUtil.waitForFocus(bWest, bWestFA, glWindow1FA)); + Assert.assertTrue("Did not gain focus", AWTRobotUtil.waitForFocus(cWest, bWestFA, glWindow1FA)); Assert.assertEquals(true, bWestFA.focusGained()); Assert.assertEquals(true, glWindow1FA.focusLost()); - Thread.sleep(durationPerTest/numFocus); + Thread.sleep(durationPerTest/numFocus); + + // direct AWT request focus + try { + java.awt.EventQueue.invokeAndWait(new Runnable() { + public void run() { + newtCanvasAWT1.requestFocus(); + } + }); + } catch (Exception ex) { ex.printStackTrace(); } + Assert.assertTrue("Did not gain focus", AWTRobotUtil.waitForFocus(glWindow1, glWindow1FA, bWestFA)); + Assert.assertEquals(true, glWindow1FA.focusGained()); + Assert.assertEquals(true, bWestFA.focusLost()); + Thread.sleep(durationPerTest/numFocus); + + // direct AWT request focus + try { + java.awt.EventQueue.invokeAndWait(new Runnable() { + public void run() { + cWest.requestFocus(); + } + }); + } catch (Exception ex) { ex.printStackTrace(); } + Assert.assertTrue("Did not gain focus", AWTRobotUtil.waitForFocus(cWest, bWestFA, glWindow1FA)); + Assert.assertEquals(true, bWestFA.focusGained()); + Assert.assertEquals(true, glWindow1FA.focusLost()); + Thread.sleep(durationPerTest/numFocus); + + // direct NEWT request focus + System.err.println("AAAAAAAAAAAAAA"); + glWindow1.requestFocus(); + Assert.assertTrue("Did not gain focus", AWTRobotUtil.waitForFocus(glWindow1, glWindow1FA, bWestFA)); + Assert.assertEquals(true, glWindow1FA.focusGained()); + Assert.assertEquals(true, bWestFA.focusLost()); + Thread.sleep(durationPerTest/numFocus); } animator1.stop(); @@ -217,7 +290,7 @@ public class TestParentingFocusTraversal01AWT extends UITestCase { public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) { Assert.assertNotNull(demo); Assert.assertNotNull(glWindow); - Window window = glWindow.getWindow(); + Window window = glWindow.getDelegatedWindow(); if(debug) { MiscUtils.setFieldIfExists(demo, "glDebug", true); MiscUtils.setFieldIfExists(demo, "glTrace", true); diff --git a/src/test/jogamp/newt/WindowImplAccess.java b/src/test/jogamp/newt/WindowImplAccess.java index 76d0dc050..e8be5f68a 100644 --- a/src/test/jogamp/newt/WindowImplAccess.java +++ b/src/test/jogamp/newt/WindowImplAccess.java @@ -29,26 +29,16 @@ package jogamp.newt; import com.jogamp.newt.Window; -import com.jogamp.newt.opengl.GLWindow; /** * Allows access to protected methods of WindowImpl */ public class WindowImplAccess { public static final void windowDestroyNotify(Window win) { - WindowImpl winImpl = null; - if(win instanceof GLWindow) { - GLWindow glwin = (GLWindow) win; - winImpl = (WindowImpl) glwin.getWindow(); - } else if(win instanceof WindowImpl) { - winImpl = (WindowImpl) win; - } else { - throw new RuntimeException("Given Window not a GLWindow, not WindowImpl, but "+win.getClass()); - } - final WindowImpl winImplF = winImpl; - winImplF.runOnEDTIfAvail(true, new Runnable() { + final WindowImpl winImpl = (WindowImpl) win.getDelegatedWindow(); + winImpl.runOnEDTIfAvail(true, new Runnable() { public void run() { - winImplF.windowDestroyNotify(); + winImpl.windowDestroyNotify(); } }); } |