summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java8
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/TestFocus02SwingAWTRobot.java7
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java7
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/AWTWindowFocusAdapter.java71
4 files changed, 87 insertions, 6 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java b/src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java
index be1b7a4e9..fe7fef09f 100644
--- a/src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java
+++ b/src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java
@@ -35,6 +35,7 @@ import org.junit.Assume;
import java.awt.AWTException;
import java.awt.BorderLayout;
import java.awt.Button;
+import java.awt.Color;
import java.awt.Robot;
import java.lang.reflect.InvocationTargetException;
@@ -119,7 +120,7 @@ public class TestFocus01SwingAWTRobot extends UITestCase {
AWTFocusAdapter frame1FA = new AWTFocusAdapter("frame1");
frame1.addFocusListener(frame1FA);
frame1.getContentPane().add(newtCanvasAWT, BorderLayout.CENTER);
- Button button = new Button("Click me ..");
+ final Button button = new Button("Click me ..");
AWTFocusAdapter buttonFA = new AWTFocusAdapter("Button");
button.addFocusListener(buttonFA);
AWTKeyAdapter buttonKA = new AWTKeyAdapter("Button");
@@ -127,7 +128,10 @@ public class TestFocus01SwingAWTRobot extends UITestCase {
eventCountAdapters.add(buttonKA);
frame1.getContentPane().add(button, BorderLayout.NORTH);
frame1.setSize(width, height);
- frame1.setVisible(true);
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame1.setVisible(true);
+ } } );
Assert.assertTrue(AWTRobotUtil.toFront(robot, frame1));
Thread.sleep(durationPerTest); // manual testing
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestFocus02SwingAWTRobot.java b/src/test/com/jogamp/opengl/test/junit/newt/TestFocus02SwingAWTRobot.java
index fb71c4ba0..b9eb748b7 100644
--- a/src/test/com/jogamp/opengl/test/junit/newt/TestFocus02SwingAWTRobot.java
+++ b/src/test/com/jogamp/opengl/test/junit/newt/TestFocus02SwingAWTRobot.java
@@ -145,14 +145,17 @@ public class TestFocus02SwingAWTRobot extends UITestCase {
jPanel1.add(new Button("west"), BorderLayout.WEST);
jPanel1.add(container1, BorderLayout.CENTER);
- JFrame jFrame1 = new JFrame("Swing Parent JFrame");
+ final JFrame jFrame1 = new JFrame("Swing Parent JFrame");
AWTFocusAdapter jFrame1FA = new AWTFocusAdapter("JFrame1");
jFrame1.addFocusListener(jFrame1FA);
// 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);
- jFrame1.setVisible(true); // from here on, we need to run modifications on EDT
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ jFrame1.setVisible(true);
+ } } );
Assert.assertTrue(AWTRobotUtil.toFront(robot, jFrame1));
int wait=0;
diff --git a/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java b/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java
index 131e3a714..a27bdd7a2 100644
--- a/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java
+++ b/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java
@@ -102,6 +102,9 @@ public class AWTRobotUtil {
public static boolean toFront(Robot robot, final java.awt.Window window)
throws AWTException, InterruptedException, InvocationTargetException {
+ AWTWindowFocusAdapter winFA = new AWTWindowFocusAdapter("window");
+ window.addWindowFocusListener(winFA);
+
if(null == robot) {
robot = new Robot();
robot.setAutoWaitForIdle(true);
@@ -119,11 +122,11 @@ public class AWTRobotUtil {
}});
robot.delay(ROBOT_DELAY);
- KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
int wait;
- for (wait=0; wait<POLL_DIVIDER && window != kfm.getFocusedWindow(); wait++) {
+ for (wait=0; wait<POLL_DIVIDER && !winFA.focusGained(); wait++) {
Thread.sleep(TIME_SLICE);
}
+ window.removeWindowFocusListener(winFA);
return wait<POLL_DIVIDER;
}
diff --git a/src/test/com/jogamp/opengl/test/junit/util/AWTWindowFocusAdapter.java b/src/test/com/jogamp/opengl/test/junit/util/AWTWindowFocusAdapter.java
new file mode 100644
index 000000000..16aacd2fd
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/util/AWTWindowFocusAdapter.java
@@ -0,0 +1,71 @@
+/**
+ * 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.util;
+
+import java.awt.event.WindowEvent;
+import java.awt.event.WindowFocusListener;
+
+public class AWTWindowFocusAdapter implements FocusEventCountAdapter, WindowFocusListener {
+
+ String prefix;
+ int focusCount;
+
+ public AWTWindowFocusAdapter(String prefix) {
+ this.prefix = prefix;
+ reset();
+ }
+
+ public boolean focusLost() {
+ return focusCount<0;
+ }
+
+ public boolean focusGained() {
+ return focusCount>0;
+ }
+
+ public void reset() {
+ focusCount = 0;
+ }
+
+ /* @Override */
+ public void windowGainedFocus(WindowEvent e) {
+ if(focusCount<0) { focusCount=0; }
+ focusCount++;
+ System.err.println("FOCUS AWT GAINED (Window) [fc "+focusCount+"]: "+prefix+", "+e);
+ }
+
+ /* @Override */
+ public void windowLostFocus(WindowEvent e) {
+ if(focusCount>0) { focusCount=0; }
+ focusCount--;
+ System.err.println("FOCUS AWT LOST (Window) [fc "+focusCount+"]: "+prefix+", "+e);
+ }
+
+ public String toString() { return prefix+"[focusCount "+focusCount +"]"; }
+}