From 4d79797fecfb7bfc725dfea26573b15b9b365181 Mon Sep 17 00:00:00 2001
From: Sven Gothel
Date: Sun, 10 Nov 2013 10:03:30 +0100
Subject: Tests: Align NEWT parenting focus tests (package and class names)
using NewtCanvasAWT
---
make/scripts/tests-win.bat | 9 +-
make/scripts/tests.sh | 14 +-
.../test/junit/newt/TestFocus01SwingAWTRobot.java | 245 --------------
.../test/junit/newt/TestFocus02SwingAWTRobot.java | 318 -------------------
.../TestParentingFocus01SwingAWTRobot.java | 245 ++++++++++++++
.../TestParentingFocus02SwingAWTRobot.java | 318 +++++++++++++++++++
.../TestParentingFocus03KeyTraversalAWT.java | 351 +++++++++++++++++++++
.../TestParentingFocusTraversal01AWT.java | 345 --------------------
8 files changed, 927 insertions(+), 918 deletions(-)
delete mode 100644 src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java
delete mode 100644 src/test/com/jogamp/opengl/test/junit/newt/TestFocus02SwingAWTRobot.java
create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingFocus01SwingAWTRobot.java
create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingFocus02SwingAWTRobot.java
create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingFocus03KeyTraversalAWT.java
delete mode 100644 src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingFocusTraversal01AWT.java
diff --git a/make/scripts/tests-win.bat b/make/scripts/tests-win.bat
index f8a0b4ead..023e7dc6e 100755
--- a/make/scripts/tests-win.bat
+++ b/make/scripts/tests-win.bat
@@ -89,7 +89,7 @@ REM scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.acore.ect.TestExclusi
REM scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.acore.ect.TestExclusiveContext11VSyncAnimNEWT %*
REM scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.acore.ect.TestExclusiveContext12FPSAnimNEWT %*
-scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.acore.anim.TestAnimatorGLWindow01NEWT %*
+REM scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.acore.anim.TestAnimatorGLWindow01NEWT %*
REM scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.acore.anim.TestAnimatorGLJPanel01AWT %*
REM scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.acore.anim.TestAnimatorGLCanvas01AWT %*
REM scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.acore.anim.TestAWTCardLayoutAnimatorStartStopBug532 %*
@@ -130,7 +130,6 @@ REM scripts\java-win.bat com.jogamp.opengl.test.junit.newt.parenting.TestParenti
REM scripts\java-win.bat com.jogamp.opengl.test.junit.newt.parenting.TestParenting01cAWT -time 50000
REM scripts\java-win.bat com.jogamp.opengl.test.junit.newt.parenting.TestParenting03AWT %*
REM scripts\java-win.bat com.jogamp.opengl.test.junit.newt.parenting.TestParenting03bAWT -time 100000
-REM scripts\java-win.bat com.jogamp.opengl.test.junit.newt.parenting.TestParentingFocusTraversal01AWT %*
REM scripts\java-win.bat com.jogamp.opengl.test.junit.newt.parenting.TestParentingOffscreenLayer01AWT %*
REM scripts\java-win.bat com.jogamp.opengl.test.junit.newt.parenting.TestParenting01aSWT %*
REM scripts\java-win.bat com.jogamp.opengl.test.junit.newt.parenting.TestParenting04AWT %*
@@ -138,6 +137,10 @@ REM scripts\java-win.bat com.jogamp.opengl.test.junit.newt.parenting.TestParenti
REM scripts\java-win.bat com.jogamp.opengl.test.junit.newt.parenting.TestTranslucentParentingAWT %*
REM scripts\java-win.bat com.jogamp.opengl.test.junit.newt.parenting.TestTranslucentChildWindowBug632NEWT %*
+REM scripts\java-win.bat com.jogamp.opengl.test.junit.newt.parenting.TestParentingFocus01SwingAWTRobot %*
+scripts\java-win.bat com.jogamp.opengl.test.junit.newt.parenting.TestParentingFocus02SwingAWTRobot %*
+REM scripts\java-win.bat com.jogamp.opengl.test.junit.newt.parenting.TestParentingFocus03KeyTraversalAWT %*
+
REM scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.swt.TestSWTAccessor03AWTGLn %*
REM scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.swt.TestSWTJOGLGLCanvas01GLn %*
REM scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.swt.TestNewtCanvasSWTGLn %*
@@ -149,8 +152,6 @@ REM scripts\java-win.bat com.jogamp.opengl.test.junit.newt.TestWindows01NEWT
REM scripts\java-win.bat com.jogamp.opengl.test.junit.newt.TestGLWindows01NEWT
REM scripts\java-win.bat com.jogamp.opengl.test.junit.newt.TestGLWindows02NEWTAnimated
REM scripts\java-win.bat com.jogamp.opengl.test.junit.newt.TestGLWindowInvisiblePointer01NEWT %*
-REM scripts\java-win.bat com.jogamp.opengl.test.junit.newt.TestFocus01SwingAWTRobot %*
-REM scripts\java-win.bat com.jogamp.opengl.test.junit.newt.TestFocus02SwingAWTRobot %*
REM scripts\java-win.bat com.jogamp.opengl.test.junit.nativewindow.TestRecursiveToolkitLockCORE
REM scripts\java-win.bat com.jogamp.opengl.test.junit.newt.mm.TestScreenMode00aNEWT %*
diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh
index 468672325..08505aea1 100644
--- a/make/scripts/tests.sh
+++ b/make/scripts/tests.sh
@@ -462,7 +462,7 @@ function testawtswt() {
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestNEWTCloseX11DisplayBug565 $*
#testawt com.jogamp.opengl.test.junit.jogl.acore.TestAWTCloseX11DisplayBug565 $*
-testnoawt com.jogamp.opengl.test.junit.jogl.acore.anim.TestAnimatorGLWindow01NEWT $*
+#testnoawt com.jogamp.opengl.test.junit.jogl.acore.anim.TestAnimatorGLWindow01NEWT $*
#testawt com.jogamp.opengl.test.junit.jogl.acore.anim.TestAnimatorGLJPanel01AWT $*
#testawt com.jogamp.opengl.test.junit.jogl.acore.anim.TestAWTCardLayoutAnimatorStartStopBug532 $*
#testawt com.jogamp.opengl.test.junit.jogl.acore.anim.Bug898AnimatorFromEDTAWT $*
@@ -556,8 +556,6 @@ testnoawt com.jogamp.opengl.test.junit.jogl.acore.anim.TestAnimatorGLWindow01NEW
#
#testawt com.jogamp.opengl.test.junit.jogl.newt.TestSwingAWTRobotUsageBeforeJOGLInitBug411 $*
#testawt com.jogamp.opengl.test.junit.newt.TestEventSourceNotAWTBug
-#testawt com.jogamp.opengl.test.junit.newt.TestFocus01SwingAWTRobot $*
-#testawt com.jogamp.opengl.test.junit.newt.TestFocus02SwingAWTRobot $*
#testawt com.jogamp.opengl.test.junit.newt.event.TestNewtKeyEventOrderAWT $*
#testawt com.jogamp.opengl.test.junit.newt.event.TestNewtKeyEventAutoRepeatAWT $*
#testawt com.jogamp.opengl.test.junit.newt.event.TestNewtKeyPressReleaseUnmaskRepeatAWT $*
@@ -595,7 +593,6 @@ testnoawt com.jogamp.opengl.test.junit.jogl.acore.anim.TestAnimatorGLWindow01NEW
#
#testnoawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting01NEWT $*
#testnoawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting02NEWT $*
-#testawt com.jogamp.opengl.test.junit.newt.parenting.TestParentingFocusTraversal01AWT $*
#testawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting01cSwingAWT $*
#testawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting01aAWT $*
#testawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting01bAWT $*
@@ -608,6 +605,10 @@ testnoawt com.jogamp.opengl.test.junit.jogl.acore.anim.TestAnimatorGLWindow01NEW
#testawt com.jogamp.opengl.test.junit.newt.parenting.TestTranslucentParentingAWT $*
#testnoawt com.jogamp.opengl.test.junit.newt.parenting.TestTranslucentChildWindowBug632NEWT $*
+#testawt com.jogamp.opengl.test.junit.newt.parenting.TestParentingFocus01SwingAWTRobot $*
+testawt com.jogamp.opengl.test.junit.newt.parenting.TestParentingFocus02SwingAWTRobot $*
+#testawt com.jogamp.opengl.test.junit.newt.parenting.TestParentingFocus03KeyTraversalAWT $*
+
#
# Misc Utils
#
@@ -665,8 +666,9 @@ testnoawt com.jogamp.opengl.test.junit.jogl.acore.anim.TestAnimatorGLWindow01NEW
#
# OSX bugs
#
-#testawt com.jogamp.opengl.test.junit.newt.TestFocus02SwingAWTRobot $*
-#testawt com.jogamp.opengl.test.junit.newt.parenting.TestParentingFocusTraversal01AWT $*
+
+#testawt com.jogamp.opengl.test.junit.newt.parenting.TestParentingFocus02SwingAWTRobot $*
+#testawt com.jogamp.opengl.test.junit.newt.parenting.TestParentingFocus03KeyTraversalAWT $*
# test rotation change
#testnoawt com.jogamp.opengl.test.junit.newt.mm.TestScreenMode02aNEWT
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java b/src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java
deleted file mode 100644
index 5f3702340..000000000
--- a/src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java
+++ /dev/null
@@ -1,245 +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;
-
-import org.junit.Assert;
-import org.junit.AfterClass;
-import org.junit.Assume;
-
-import java.awt.AWTException;
-import java.awt.BorderLayout;
-import java.awt.Button;
-import java.awt.Container;
-import java.awt.Robot;
-import java.lang.reflect.InvocationTargetException;
-
-import javax.media.opengl.GLCapabilities;
-import javax.media.opengl.GLEventListener;
-import javax.swing.JFrame;
-
-import java.util.ArrayList;
-import java.io.IOException;
-
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.FixMethodOrder;
-import org.junit.runners.MethodSorters;
-
-import com.jogamp.newt.awt.NewtCanvasAWT;
-import com.jogamp.newt.opengl.GLWindow;
-import com.jogamp.opengl.util.Animator;
-import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
-
-import com.jogamp.opengl.test.junit.util.*;
-
-/**
- * Testing focus traversal of an AWT component tree with {@link NewtCanvasAWT} attached.
- *
- * {@link JFrame} . {@link Container}+ . {@link NewtCanvasAWT} . {@link GLWindow}
- *
- *
- * + Container is the JFrame's implicit root content pane
- *
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class TestFocus01SwingAWTRobot extends UITestCase {
- static int width, height;
- static long durationPerTest = 10;
- static long awtWaitTimeout = 1000;
-
- static GLCapabilities glCaps;
-
- @BeforeClass
- public static void initClass() {
- width = 640;
- height = 480;
- glCaps = new GLCapabilities(null);
- }
-
- @AfterClass
- public static void release() {
- }
-
- @Test
- public void testFocus01ProgrFocus() throws AWTException, InterruptedException, InvocationTargetException {
- testFocus01ProgrFocusImpl(null);
- }
-
- @Test
- public void testFocus02RobotFocus() throws AWTException, InterruptedException, InvocationTargetException {
- Robot robot = new Robot();
- robot.setAutoWaitForIdle(true);
- testFocus01ProgrFocusImpl(robot);
- }
-
- private void testFocus01ProgrFocusImpl(Robot robot) throws AWTException,
- InvocationTargetException, InterruptedException {
- ArrayList eventCountAdapters = new ArrayList();
-
- // Create a window.
- GLWindow glWindow1 = GLWindow.create(glCaps);
- glWindow1.setTitle("testNewtChildFocus");
- GLEventListener demo1 = new RedSquareES2();
- TestListenerCom01AWT.setDemoFields(demo1, glWindow1, false);
- glWindow1.addGLEventListener(demo1);
- NEWTFocusAdapter glWindow1FA = new NEWTFocusAdapter("GLWindow1");
- glWindow1.addWindowListener(glWindow1FA);
-
- // Monitor NEWT focus and keyboard events.
- NEWTKeyAdapter glWindow1KA = new NEWTKeyAdapter("GLWindow1");
- eventCountAdapters.add(glWindow1KA);
- glWindow1.addKeyListener(glWindow1KA);
-
- // Wrap the window in a canvas.
- final NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);
- // newtCanvasAWT.setShallUseOffscreenLayer(true);
-
- // Monitor AWT focus and keyboard events.
- AWTKeyAdapter newtCanvasAWTKA = new AWTKeyAdapter("NewtCanvasAWT");
- newtCanvasAWT.addKeyListener(newtCanvasAWTKA);
- eventCountAdapters.add(newtCanvasAWTKA);
- AWTFocusAdapter newtCanvasAWTFA = new AWTFocusAdapter("NewtCanvasAWT");
- newtCanvasAWT.addFocusListener(newtCanvasAWTFA);
-
- // Add the canvas to a frame, and make it all visible.
- final JFrame frame1 = new JFrame("Swing AWT Parent Frame: "
- + glWindow1.getTitle());
- frame1.getContentPane().add(newtCanvasAWT, BorderLayout.CENTER);
- final Button button = new Button("Click me ..");
- AWTFocusAdapter buttonFA = new AWTFocusAdapter("Button");
- button.addFocusListener(buttonFA);
- AWTKeyAdapter buttonKA = new AWTKeyAdapter("Button");
- button.addKeyListener(buttonKA);
- eventCountAdapters.add(buttonKA);
- AWTMouseAdapter buttonMA = new AWTMouseAdapter("Button");
- button.addMouseListener(buttonMA);
- eventCountAdapters.add(buttonMA);
-
- frame1.getContentPane().add(button, BorderLayout.NORTH);
- frame1.setSize(width, height);
- javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
- public void run() {
- frame1.setVisible(true);
- } } );
- Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame1, true));
- Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glWindow1, true));
- AWTRobotUtil.clearAWTFocus(robot);
- Assert.assertTrue(AWTRobotUtil.toFrontAndRequestFocus(robot, frame1));
-
- Thread.sleep(durationPerTest); // manual testing
-
- int wait=0;
- while(wait
- * {@link JFrame} . {@link JPanel}+ . {@link Container} . {@link NewtCanvasAWT} . {@link GLWindow}
- *
- *
- * + JPanel is set as JFrame's root content pane
- *
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class TestFocus02SwingAWTRobot extends UITestCase {
- static int width, height;
- static long durationPerTest = 10;
- static long awtWaitTimeout = 1000;
- static GLCapabilities glCaps;
-
- @BeforeClass
- public static void initClass() throws AWTException, InterruptedException, InvocationTargetException {
- width = 640;
- height = 480;
-
- final JFrame f = new JFrame();
- javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
- public void run() {
- f.setSize(100,100);
- f.setVisible(true);
- } } );
- javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
- public void run() {
- f.dispose();
- } } );
-
- glCaps = new GLCapabilities(null);
- }
-
- @AfterClass
- public static void release() {
- }
-
- private void testFocus01ProgrFocusImpl(Robot robot)
- throws AWTException, InterruptedException, InvocationTargetException {
-
- ArrayList eventCountAdapters = new ArrayList();
-
- GLWindow glWindow1 = GLWindow.create(glCaps);
- glWindow1.setTitle("testWindowParenting01CreateVisibleDestroy");
- GLEventListener demo1 = new GearsES2();
- glWindow1.addGLEventListener(demo1);
- NEWTFocusAdapter glWindow1FA = new NEWTFocusAdapter("GLWindow1");
- glWindow1.addWindowListener(glWindow1FA);
- NEWTKeyAdapter glWindow1KA = new NEWTKeyAdapter("GLWindow1");
- glWindow1.addKeyListener(glWindow1KA);
- eventCountAdapters.add(glWindow1KA);
- NEWTMouseAdapter glWindow1MA = new NEWTMouseAdapter("GLWindow1");
- glWindow1.addMouseListener(glWindow1MA);
- eventCountAdapters.add(glWindow1MA);
-
- NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);
- AWTFocusAdapter newtCanvasAWTFA = new AWTFocusAdapter("NewtCanvasAWT");
- newtCanvasAWT.addFocusListener(newtCanvasAWTFA);
- AWTKeyAdapter newtCanvasAWTKA = new AWTKeyAdapter("NewtCanvasAWT");
- newtCanvasAWT.addKeyListener(newtCanvasAWTKA);
- eventCountAdapters.add(newtCanvasAWTKA);
- AWTMouseAdapter newtCanvasAWTMA = new AWTMouseAdapter("NewtCanvasAWT");
- newtCanvasAWT.addMouseListener(newtCanvasAWTMA);
- eventCountAdapters.add(newtCanvasAWTMA);
-
- Button buttonNorthInner = new Button("north");
- AWTFocusAdapter buttonNorthInnerFA = new AWTFocusAdapter("ButtonNorthInner");
- buttonNorthInner.addFocusListener(buttonNorthInnerFA);
- AWTKeyAdapter buttonNorthInnerKA = new AWTKeyAdapter("ButtonNorthInner");
- buttonNorthInner.addKeyListener(buttonNorthInnerKA);
- eventCountAdapters.add(buttonNorthInnerKA);
- AWTMouseAdapter buttonNorthInnerMA = new AWTMouseAdapter("ButtonNorthInner");
- buttonNorthInner.addMouseListener(buttonNorthInnerMA);
- eventCountAdapters.add(buttonNorthInnerMA);
- final Container container1 = new Container();
- container1.setLayout(new BorderLayout());
- container1.add(buttonNorthInner, BorderLayout.NORTH);
- container1.add(new Button("south"), BorderLayout.SOUTH);
- container1.add(new Button("east"), BorderLayout.EAST);
- container1.add(new Button("west"), BorderLayout.WEST);
- container1.add(newtCanvasAWT, BorderLayout.CENTER);
-
- Button buttonNorthOuter = new Button("north");
- AWTFocusAdapter buttonNorthOuterFA = new AWTFocusAdapter("ButtonNorthOuter");
- buttonNorthOuter.addFocusListener(buttonNorthOuterFA);
- AWTKeyAdapter buttonNorthOuterKA = new AWTKeyAdapter("ButtonNorthOuter");
- buttonNorthOuter.addKeyListener(buttonNorthOuterKA);
- eventCountAdapters.add(buttonNorthOuterKA);
- AWTMouseAdapter buttonNorthOuterMA = new AWTMouseAdapter("ButtonNorthOuter");
- buttonNorthOuter.addMouseListener(buttonNorthOuterMA);
- eventCountAdapters.add(buttonNorthOuterMA);
- final JPanel jPanel1 = new JPanel();
- jPanel1.setLayout(new BorderLayout());
- jPanel1.add(buttonNorthOuter, BorderLayout.NORTH);
- jPanel1.add(new Button("south"), BorderLayout.SOUTH);
- jPanel1.add(new Button("east"), BorderLayout.EAST);
- jPanel1.add(new Button("west"), BorderLayout.WEST);
- jPanel1.add(container1, BorderLayout.CENTER);
-
- final JFrame jFrame1 = new JFrame("Swing Parent JFrame");
- // jFrame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- jFrame1.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // equivalent to Frame, use windowClosing event!
- jFrame1.setContentPane(jPanel1);
- jFrame1.setSize(width, height);
- javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
- public void run() {
- jFrame1.setVisible(true);
- } } );
- Assert.assertEquals(true, AWTRobotUtil.waitForVisible(jFrame1, true));
- Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glWindow1, true));
- AWTRobotUtil.clearAWTFocus(robot);
- Assert.assertTrue(AWTRobotUtil.toFrontAndRequestFocus(robot, jFrame1));
-
- int wait=0;
- while(waitmouse-click and programmatic traversal of an AWT component tree with {@link NewtCanvasAWT} attached.
+ *
+ * {@link JFrame} . {@link Container}+ [ Button*, {@link NewtCanvasAWT} . {@link GLWindow} ]
+ *
+ *
+ * + Container is the JFrame's implicit root content pane
+ *
+ */
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestParentingFocus01SwingAWTRobot extends UITestCase {
+ static int width, height;
+ static long durationPerTest = 10;
+ static long awtWaitTimeout = 1000;
+
+ static GLCapabilities glCaps;
+
+ @BeforeClass
+ public static void initClass() {
+ width = 640;
+ height = 480;
+ glCaps = new GLCapabilities(null);
+ }
+
+ @AfterClass
+ public static void release() {
+ }
+
+ @Test
+ public void testFocus01ProgrFocus() throws AWTException, InterruptedException, InvocationTargetException {
+ testFocus01ProgrFocusImpl(null);
+ }
+
+ @Test
+ public void testFocus02RobotFocus() throws AWTException, InterruptedException, InvocationTargetException {
+ Robot robot = new Robot();
+ robot.setAutoWaitForIdle(true);
+ testFocus01ProgrFocusImpl(robot);
+ }
+
+ private void testFocus01ProgrFocusImpl(Robot robot) throws AWTException,
+ InvocationTargetException, InterruptedException {
+ ArrayList eventCountAdapters = new ArrayList();
+
+ // Create a window.
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ glWindow1.setTitle("testNewtChildFocus");
+ GLEventListener demo1 = new RedSquareES2();
+ TestListenerCom01AWT.setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+ NEWTFocusAdapter glWindow1FA = new NEWTFocusAdapter("GLWindow1");
+ glWindow1.addWindowListener(glWindow1FA);
+
+ // Monitor NEWT focus and keyboard events.
+ NEWTKeyAdapter glWindow1KA = new NEWTKeyAdapter("GLWindow1");
+ eventCountAdapters.add(glWindow1KA);
+ glWindow1.addKeyListener(glWindow1KA);
+
+ // Wrap the window in a canvas.
+ final NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);
+ // newtCanvasAWT.setShallUseOffscreenLayer(true);
+
+ // Monitor AWT focus and keyboard events.
+ AWTKeyAdapter newtCanvasAWTKA = new AWTKeyAdapter("NewtCanvasAWT");
+ newtCanvasAWT.addKeyListener(newtCanvasAWTKA);
+ eventCountAdapters.add(newtCanvasAWTKA);
+ AWTFocusAdapter newtCanvasAWTFA = new AWTFocusAdapter("NewtCanvasAWT");
+ newtCanvasAWT.addFocusListener(newtCanvasAWTFA);
+
+ // Add the canvas to a frame, and make it all visible.
+ final JFrame frame1 = new JFrame("Swing AWT Parent Frame: "
+ + glWindow1.getTitle());
+ frame1.getContentPane().add(newtCanvasAWT, BorderLayout.CENTER);
+ final Button button = new Button("Click me ..");
+ AWTFocusAdapter buttonFA = new AWTFocusAdapter("Button");
+ button.addFocusListener(buttonFA);
+ AWTKeyAdapter buttonKA = new AWTKeyAdapter("Button");
+ button.addKeyListener(buttonKA);
+ eventCountAdapters.add(buttonKA);
+ AWTMouseAdapter buttonMA = new AWTMouseAdapter("Button");
+ button.addMouseListener(buttonMA);
+ eventCountAdapters.add(buttonMA);
+
+ frame1.getContentPane().add(button, BorderLayout.NORTH);
+ frame1.setSize(width, height);
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame1.setVisible(true);
+ } } );
+ Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame1, true));
+ Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glWindow1, true));
+ AWTRobotUtil.clearAWTFocus(robot);
+ Assert.assertTrue(AWTRobotUtil.toFrontAndRequestFocus(robot, frame1));
+
+ Thread.sleep(durationPerTest); // manual testing
+
+ int wait=0;
+ while(waitmouse-click and programmatic traversal of an AWT component tree with {@link NewtCanvasAWT} attached.
+ *
+ * {@link JFrame} . {@link JPanel}+ . {@link Container} [ Button*, {@link NewtCanvasAWT} . {@link GLWindow} ]
+ *
+ *
+ * + JPanel is set as JFrame's root content pane
+ *
+ */
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestParentingFocus02SwingAWTRobot extends UITestCase {
+ static int width, height;
+ static long durationPerTest = 10;
+ static long awtWaitTimeout = 1000;
+ static GLCapabilities glCaps;
+
+ @BeforeClass
+ public static void initClass() throws AWTException, InterruptedException, InvocationTargetException {
+ width = 640;
+ height = 480;
+
+ final JFrame f = new JFrame();
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ f.setSize(100,100);
+ f.setVisible(true);
+ } } );
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ f.dispose();
+ } } );
+
+ glCaps = new GLCapabilities(null);
+ }
+
+ @AfterClass
+ public static void release() {
+ }
+
+ private void testFocus01ProgrFocusImpl(Robot robot)
+ throws AWTException, InterruptedException, InvocationTargetException {
+
+ ArrayList eventCountAdapters = new ArrayList();
+
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ glWindow1.setTitle("testWindowParenting01CreateVisibleDestroy");
+ GLEventListener demo1 = new GearsES2();
+ glWindow1.addGLEventListener(demo1);
+ NEWTFocusAdapter glWindow1FA = new NEWTFocusAdapter("GLWindow1");
+ glWindow1.addWindowListener(glWindow1FA);
+ NEWTKeyAdapter glWindow1KA = new NEWTKeyAdapter("GLWindow1");
+ glWindow1.addKeyListener(glWindow1KA);
+ eventCountAdapters.add(glWindow1KA);
+ NEWTMouseAdapter glWindow1MA = new NEWTMouseAdapter("GLWindow1");
+ glWindow1.addMouseListener(glWindow1MA);
+ eventCountAdapters.add(glWindow1MA);
+
+ NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);
+ AWTFocusAdapter newtCanvasAWTFA = new AWTFocusAdapter("NewtCanvasAWT");
+ newtCanvasAWT.addFocusListener(newtCanvasAWTFA);
+ AWTKeyAdapter newtCanvasAWTKA = new AWTKeyAdapter("NewtCanvasAWT");
+ newtCanvasAWT.addKeyListener(newtCanvasAWTKA);
+ eventCountAdapters.add(newtCanvasAWTKA);
+ AWTMouseAdapter newtCanvasAWTMA = new AWTMouseAdapter("NewtCanvasAWT");
+ newtCanvasAWT.addMouseListener(newtCanvasAWTMA);
+ eventCountAdapters.add(newtCanvasAWTMA);
+
+ Button buttonNorthInner = new Button("north");
+ AWTFocusAdapter buttonNorthInnerFA = new AWTFocusAdapter("ButtonNorthInner");
+ buttonNorthInner.addFocusListener(buttonNorthInnerFA);
+ AWTKeyAdapter buttonNorthInnerKA = new AWTKeyAdapter("ButtonNorthInner");
+ buttonNorthInner.addKeyListener(buttonNorthInnerKA);
+ eventCountAdapters.add(buttonNorthInnerKA);
+ AWTMouseAdapter buttonNorthInnerMA = new AWTMouseAdapter("ButtonNorthInner");
+ buttonNorthInner.addMouseListener(buttonNorthInnerMA);
+ eventCountAdapters.add(buttonNorthInnerMA);
+ final Container container1 = new Container();
+ container1.setLayout(new BorderLayout());
+ container1.add(buttonNorthInner, BorderLayout.NORTH);
+ container1.add(new Button("south"), BorderLayout.SOUTH);
+ container1.add(new Button("east"), BorderLayout.EAST);
+ container1.add(new Button("west"), BorderLayout.WEST);
+ container1.add(newtCanvasAWT, BorderLayout.CENTER);
+
+ Button buttonNorthOuter = new Button("north");
+ AWTFocusAdapter buttonNorthOuterFA = new AWTFocusAdapter("ButtonNorthOuter");
+ buttonNorthOuter.addFocusListener(buttonNorthOuterFA);
+ AWTKeyAdapter buttonNorthOuterKA = new AWTKeyAdapter("ButtonNorthOuter");
+ buttonNorthOuter.addKeyListener(buttonNorthOuterKA);
+ eventCountAdapters.add(buttonNorthOuterKA);
+ AWTMouseAdapter buttonNorthOuterMA = new AWTMouseAdapter("ButtonNorthOuter");
+ buttonNorthOuter.addMouseListener(buttonNorthOuterMA);
+ eventCountAdapters.add(buttonNorthOuterMA);
+ final JPanel jPanel1 = new JPanel();
+ jPanel1.setLayout(new BorderLayout());
+ jPanel1.add(buttonNorthOuter, BorderLayout.NORTH);
+ jPanel1.add(new Button("south"), BorderLayout.SOUTH);
+ jPanel1.add(new Button("east"), BorderLayout.EAST);
+ jPanel1.add(new Button("west"), BorderLayout.WEST);
+ jPanel1.add(container1, BorderLayout.CENTER);
+
+ final JFrame jFrame1 = new JFrame("Swing Parent JFrame");
+ // jFrame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ jFrame1.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // equivalent to Frame, use windowClosing event!
+ jFrame1.setContentPane(jPanel1);
+ jFrame1.setSize(width, height);
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ jFrame1.setVisible(true);
+ } } );
+ Assert.assertEquals(true, AWTRobotUtil.waitForVisible(jFrame1, true));
+ Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glWindow1, true));
+ AWTRobotUtil.clearAWTFocus(robot);
+ Assert.assertTrue(AWTRobotUtil.toFrontAndRequestFocus(robot, jFrame1));
+
+ int wait=0;
+ while(waitkey traversal of an AWT component tree with {@link NewtCanvasAWT} attached.
+ *
+ * {@link Frame} [ Button*, {@link NewtCanvasAWT} . {@link GLWindow} ]
+ *
+ */
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestParentingFocus03KeyTraversalAWT extends UITestCase {
+ static Dimension glSize, fSize;
+ static int numFocus = 8;
+ static long durationPerTest = numFocus * 200;
+ static GLCapabilities glCaps;
+ static boolean manual = false;
+ static boolean forceGL3 = false;
+
+ @BeforeClass
+ public static void initClass() {
+ glSize = new Dimension(200,200);
+ fSize = new Dimension(300,300);
+ glCaps = new GLCapabilities( forceGL3 ? GLProfile.get(GLProfile.GL3) : null );
+ }
+
+ @Test
+ public void testWindowParentingAWTFocusTraversal01Onscreen() throws InterruptedException, InvocationTargetException, AWTException {
+ testWindowParentingAWTFocusTraversal(true);
+ }
+
+ @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
+ // Bug 6463168 - http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6463168
+ {
+ final KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
+ final Set bwdKeys = kfm.getDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
+ final AWTKeyStroke newBack = AWTKeyStroke.getAWTKeyStroke(java.awt.event.KeyEvent.VK_BACK_SPACE, 0, false);
+ Assert.assertNotNull(newBack);
+ final Set bwdKeys2 = new HashSet(bwdKeys);
+ bwdKeys2.add(newBack);
+ kfm.setDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, bwdKeys2);
+ }
+ {
+ final KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
+ final Set fwdKeys = kfm.getDefaultFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
+ final Set bwdKeys = kfm.getDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
+ Iterator iter;
+ for(iter = fwdKeys.iterator(); iter.hasNext(); ) {
+ System.err.println("FTKL.fwd-keys: "+iter.next());
+ }
+ for(iter = bwdKeys.iterator(); iter.hasNext(); ) {
+ System.err.println("FTKL.bwd-keys: "+iter.next());
+ }
+ }
+
+ final Frame frame1 = new Frame("AWT Parent Frame");
+ 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");
+ cWest.addFocusListener(bWestFA);
+ AWTFocusAdapter bEastFA = new AWTFocusAdapter("EAST");
+ cEast.addFocusListener(bEastFA);
+
+ // Test KeyAdapter
+ NEWTKeyAdapter glWindow1KA = new NEWTKeyAdapter("GLWindow1");
+ glWindow1.addKeyListener(glWindow1KA);
+ 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, null));
+ glWindow1.addKeyListener(new KeyAdapter() {
+ public void keyReleased(KeyEvent e) {
+ if( !e.isPrintableKey() || e.isAutoRepeat() ) {
+ return;
+ }
+ 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(cWest, BorderLayout.WEST);
+ frame1.add(newtCanvasAWT1, BorderLayout.CENTER);
+ frame1.add(cEast, BorderLayout.EAST);
+
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame1.setLocation(0, 0);
+ frame1.setSize(fSize);
+ frame1.validate();
+ frame1.setVisible(true);
+ }});
+ Assert.assertEquals(true, AWTRobotUtil.waitForVisible(glWindow1, true));
+ Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glWindow1, true));
+ Assert.assertEquals(newtCanvasAWT1.getNativeWindow(),glWindow1.getParent());
+ AWTRobotUtil.clearAWTFocus(robot);
+ Assert.assertTrue(AWTRobotUtil.toFrontAndRequestFocus(robot, frame1));
+
+ Assert.assertEquals(true, animator1.isAnimating());
+ // Assert.assertEquals(false, animator1.isPaused());
+ Assert.assertNotNull(animator1.getThread());
+
+ if(manual) {
+ Thread.sleep(durationPerTest);
+ } else {
+ //
+ // initial focus on bWest
+ //
+ AWTRobotUtil.assertRequestFocusAndWait(robot, cWest, cWest, bWestFA, null);
+ Thread.sleep(durationPerTest/numFocus);
+
+ //
+ // forth
+ //
+
+ // bWest -> glWin
+ 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());
+ Thread.sleep(durationPerTest/numFocus);
+
+ // glWin -> bEast
+ AWTRobotUtil.keyType(0, robot, java.awt.event.KeyEvent.VK_TAB, glWindow1, null);
+ 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);
+
+ //
+ // back (using custom back traversal key 'backspace')
+ //
+ // bEast -> glWin
+ 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(cWest, bWestFA, glWindow1FA));
+ Assert.assertEquals(true, bWestFA.focusGained());
+ Assert.assertEquals(true, glWindow1FA.focusLost());
+ Thread.sleep(durationPerTest/numFocus);
+
+ System.err.println("Test: Direct NewtCanvasAWT 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);
+
+ System.err.println("Test: Direct AWT Button-West 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);
+
+ System.err.println("Test: Direct NEWT-Child request focus");
+ 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();
+ Assert.assertEquals(false, animator1.isAnimating());
+ Assert.assertEquals(false, animator1.isPaused());
+ Assert.assertEquals(null, animator1.getThread());
+
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame1.dispose();
+ } } );
+ glWindow1.destroy();
+ }
+
+ public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) {
+ Assert.assertNotNull(demo);
+ Assert.assertNotNull(glWindow);
+ Window window = glWindow.getDelegatedWindow();
+ if(debug) {
+ MiscUtils.setFieldIfExists(demo, "glDebug", true);
+ MiscUtils.setFieldIfExists(demo, "glTrace", true);
+ }
+ if(!MiscUtils.setFieldIfExists(demo, "window", window)) {
+ MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
+ }
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i bwdKeys = kfm.getDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
- final AWTKeyStroke newBack = AWTKeyStroke.getAWTKeyStroke(java.awt.event.KeyEvent.VK_BACK_SPACE, 0, false);
- Assert.assertNotNull(newBack);
- final Set bwdKeys2 = new HashSet(bwdKeys);
- bwdKeys2.add(newBack);
- kfm.setDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, bwdKeys2);
- }
- {
- final KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
- final Set fwdKeys = kfm.getDefaultFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
- final Set bwdKeys = kfm.getDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
- Iterator iter;
- for(iter = fwdKeys.iterator(); iter.hasNext(); ) {
- System.err.println("FTKL.fwd-keys: "+iter.next());
- }
- for(iter = bwdKeys.iterator(); iter.hasNext(); ) {
- System.err.println("FTKL.bwd-keys: "+iter.next());
- }
- }
-
- final Frame frame1 = new Frame("AWT Parent Frame");
- 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");
- cWest.addFocusListener(bWestFA);
- AWTFocusAdapter bEastFA = new AWTFocusAdapter("EAST");
- cEast.addFocusListener(bEastFA);
-
- // Test KeyAdapter
- NEWTKeyAdapter glWindow1KA = new NEWTKeyAdapter("GLWindow1");
- glWindow1.addKeyListener(glWindow1KA);
- 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, null));
- glWindow1.addKeyListener(new KeyAdapter() {
- public void keyReleased(KeyEvent e) {
- if( !e.isPrintableKey() || e.isAutoRepeat() ) {
- return;
- }
- 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(cWest, BorderLayout.WEST);
- frame1.add(newtCanvasAWT1, BorderLayout.CENTER);
- frame1.add(cEast, BorderLayout.EAST);
-
- javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
- public void run() {
- frame1.setLocation(0, 0);
- frame1.setSize(fSize);
- frame1.validate();
- frame1.setVisible(true);
- }});
- Assert.assertEquals(true, AWTRobotUtil.waitForVisible(glWindow1, true));
- Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glWindow1, true));
- Assert.assertEquals(newtCanvasAWT1.getNativeWindow(),glWindow1.getParent());
- AWTRobotUtil.clearAWTFocus(robot);
- Assert.assertTrue(AWTRobotUtil.toFrontAndRequestFocus(robot, frame1));
-
- Assert.assertEquals(true, animator1.isAnimating());
- // Assert.assertEquals(false, animator1.isPaused());
- Assert.assertNotNull(animator1.getThread());
-
- if(manual) {
- Thread.sleep(durationPerTest);
- } else {
- //
- // initial focus on bWest
- //
- AWTRobotUtil.assertRequestFocusAndWait(robot, cWest, cWest, bWestFA, null);
- Thread.sleep(durationPerTest/numFocus);
-
- //
- // forth
- //
-
- // bWest -> glWin
- 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());
- Thread.sleep(durationPerTest/numFocus);
-
- // glWin -> bEast
- AWTRobotUtil.keyType(0, robot, java.awt.event.KeyEvent.VK_TAB, glWindow1, null);
- 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);
-
- //
- // back (using custom back traversal key 'backspace')
- //
- // bEast -> glWin
- 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(cWest, bWestFA, glWindow1FA));
- Assert.assertEquals(true, bWestFA.focusGained());
- Assert.assertEquals(true, glWindow1FA.focusLost());
- Thread.sleep(durationPerTest/numFocus);
-
- System.err.println("Test: Direct NewtCanvasAWT 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);
-
- System.err.println("Test: Direct AWT Button-West 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);
-
- System.err.println("Test: Direct NEWT-Child request focus");
- 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();
- Assert.assertEquals(false, animator1.isAnimating());
- Assert.assertEquals(false, animator1.isPaused());
- Assert.assertEquals(null, animator1.getThread());
-
- javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
- public void run() {
- frame1.dispose();
- } } );
- glWindow1.destroy();
- }
-
- public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) {
- Assert.assertNotNull(demo);
- Assert.assertNotNull(glWindow);
- Window window = glWindow.getDelegatedWindow();
- if(debug) {
- MiscUtils.setFieldIfExists(demo, "glDebug", true);
- MiscUtils.setFieldIfExists(demo, "glTrace", true);
- }
- if(!MiscUtils.setFieldIfExists(demo, "window", window)) {
- MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
- }
- }
-
- static int atoi(String a) {
- int i=0;
- try {
- i = Integer.parseInt(a);
- } catch (Exception ex) { ex.printStackTrace(); }
- return i;
- }
-
- public static void main(String args[]) throws IOException {
- for(int i=0; i