summaryrefslogtreecommitdiffstats
path: root/src/test/com/jogamp
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/com/jogamp')
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java22
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/TestFocus02SwingAWTRobot.java54
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/AWTFocusAdapter.java24
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java12
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/FocusEventCountAdapter.java3
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/NEWTFocusAdapter.java24
6 files changed, 79 insertions, 60 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 173cae12b..2afe2ebd2 100644
--- a/src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java
+++ b/src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java
@@ -43,9 +43,7 @@ import javax.media.opengl.GLEventListener;
import javax.swing.JFrame;
import java.util.ArrayList;
-import java.io.BufferedReader;
import java.io.IOException;
-import java.io.InputStreamReader;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -98,7 +96,6 @@ public class TestFocus01SwingAWTRobot extends UITestCase {
TestListenerCom01AWT.setDemoFields(demo1, glWindow1, false);
glWindow1.addGLEventListener(demo1);
NEWTFocusAdapter glWindow1FA = new NEWTFocusAdapter("GLWindow1");
- eventCountAdapters.add(glWindow1FA);
glWindow1.addWindowListener(glWindow1FA);
// Monitor NEWT focus and keyboard events.
@@ -115,7 +112,6 @@ public class TestFocus01SwingAWTRobot extends UITestCase {
eventCountAdapters.add(newtCanvasAWTKA);
AWTFocusAdapter newtCanvasAWTFA = new AWTFocusAdapter("NewtCanvasAWT");
newtCanvasAWT.addFocusListener(newtCanvasAWTFA);
- eventCountAdapters.add(newtCanvasAWTFA);
// Add the canvas to a frame, and make it all visible.
final JFrame frame1 = new JFrame("Swing AWT Parent Frame: "
@@ -126,7 +122,6 @@ public class TestFocus01SwingAWTRobot extends UITestCase {
Button button = new Button("Click me ..");
AWTFocusAdapter buttonFA = new AWTFocusAdapter("Button");
button.addFocusListener(buttonFA);
- eventCountAdapters.add(buttonFA);
AWTKeyAdapter buttonKA = new AWTKeyAdapter("Button");
button.addKeyListener(buttonKA);
eventCountAdapters.add(buttonKA);
@@ -151,10 +146,12 @@ public class TestFocus01SwingAWTRobot extends UITestCase {
System.err.println("FOCUS AWT Button request");
EventCountAdapterUtil.reset(eventCountAdapters);
- AWTRobotUtil.assertRequestFocusAndWait(robot, button, button, buttonFA, null);
- Assert.assertEquals(true, buttonFA.hasFocus());
- Assert.assertEquals(false, glWindow1FA.hasFocus());
- Assert.assertEquals(false, newtCanvasAWTFA.hasFocus());
+ AWTRobotUtil.assertRequestFocusAndWait(robot, button, button, buttonFA, frame1FA);
+ Assert.assertEquals(true, buttonFA.focusGained());
+ Assert.assertEquals(false, frame1FA.focusGained());
+ Assert.assertEquals(true, frame1FA.focusLost());
+ Assert.assertEquals(false, glWindow1FA.focusGained());
+ Assert.assertEquals(false, newtCanvasAWTFA.focusGained());
System.err.println("FOCUS AWT Button sync");
AWTRobotUtil.assertKeyType(robot, java.awt.event.KeyEvent.VK_A, 2, button, buttonKA);
@@ -164,9 +161,10 @@ public class TestFocus01SwingAWTRobot extends UITestCase {
EventCountAdapterUtil.reset(eventCountAdapters);
AWTRobotUtil.assertRequestFocusAndWait(robot, newtCanvasAWT, newtCanvasAWT.getNEWTChild(), glWindow1FA, buttonFA);
Assert.assertTrue(AWTRobotUtil.waitForFocusCount(false, newtCanvasAWTFA));
- Assert.assertEquals(true, glWindow1FA.hasFocus());
- Assert.assertEquals(false, newtCanvasAWTFA.hasFocus());
- Assert.assertEquals(false, buttonFA.hasFocus());
+ Assert.assertEquals(true, glWindow1FA.focusGained());
+ Assert.assertEquals(false, buttonFA.focusGained());
+ Assert.assertEquals(true, buttonFA.focusLost());
+ Assert.assertEquals(false, newtCanvasAWTFA.focusGained());
System.err.println("FOCUS NEWT Canvas/GLWindow sync");
AWTRobotUtil.assertKeyType(robot, java.awt.event.KeyEvent.VK_A, 2, glWindow1, glWindow1KA);
Assert.assertEquals("AWT parent canvas received keyboard events", 0, newtCanvasAWTKA.getCount());
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 78f2f4574..3d2cdc84c 100644
--- a/src/test/com/jogamp/opengl/test/junit/newt/TestFocus02SwingAWTRobot.java
+++ b/src/test/com/jogamp/opengl/test/junit/newt/TestFocus02SwingAWTRobot.java
@@ -93,7 +93,6 @@ public class TestFocus02SwingAWTRobot extends UITestCase {
glWindow1.addGLEventListener(demo1);
NEWTFocusAdapter glWindow1FA = new NEWTFocusAdapter("GLWindow1");
glWindow1.addWindowListener(glWindow1FA);
- eventCountAdapters.add(glWindow1FA);
NEWTKeyAdapter glWindow1KA = new NEWTKeyAdapter("GLWindow1");
glWindow1.addKeyListener(glWindow1KA);
eventCountAdapters.add(glWindow1KA);
@@ -104,7 +103,6 @@ public class TestFocus02SwingAWTRobot extends UITestCase {
NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);
AWTFocusAdapter newtCanvasAWTFA = new AWTFocusAdapter("NewtCanvasAWT");
newtCanvasAWT.addFocusListener(newtCanvasAWTFA);
- eventCountAdapters.add(newtCanvasAWTFA);
AWTKeyAdapter newtCanvasAWTKA = new AWTKeyAdapter("NewtCanvasAWT");
newtCanvasAWT.addKeyListener(newtCanvasAWTKA);
eventCountAdapters.add(newtCanvasAWTKA);
@@ -115,7 +113,6 @@ public class TestFocus02SwingAWTRobot extends UITestCase {
Button buttonNorthInner = new Button("north");
AWTFocusAdapter buttonNorthInnerFA = new AWTFocusAdapter("ButtonNorthInner");
buttonNorthInner.addFocusListener(buttonNorthInnerFA);
- eventCountAdapters.add(buttonNorthInnerFA);
AWTKeyAdapter buttonNorthInnerKA = new AWTKeyAdapter("ButtonNorthInner");
buttonNorthInner.addKeyListener(buttonNorthInnerKA);
eventCountAdapters.add(buttonNorthInnerKA);
@@ -133,7 +130,6 @@ public class TestFocus02SwingAWTRobot extends UITestCase {
Button buttonNorthOuter = new Button("north");
AWTFocusAdapter buttonNorthOuterFA = new AWTFocusAdapter("ButtonNorthOuter");
buttonNorthOuter.addFocusListener(buttonNorthOuterFA);
- eventCountAdapters.add(buttonNorthOuterFA);
AWTKeyAdapter buttonNorthOuterKA = new AWTKeyAdapter("ButtonNorthOuter");
buttonNorthOuter.addKeyListener(buttonNorthOuterKA);
eventCountAdapters.add(buttonNorthOuterKA);
@@ -173,18 +169,20 @@ public class TestFocus02SwingAWTRobot extends UITestCase {
Thread.sleep(100); // allow event sync
System.err.println("FOCUS AWT Button Outer request");
EventCountAdapterUtil.reset(eventCountAdapters);
- AWTRobotUtil.assertRequestFocusAndWait(robot, buttonNorthOuter, buttonNorthOuter, buttonNorthOuterFA, null);
- Assert.assertEquals(true, buttonNorthOuterFA.hasFocus());
- Assert.assertEquals(false, glWindow1FA.hasFocus());
- Assert.assertEquals(false, newtCanvasAWTFA.hasFocus());
- Assert.assertEquals(false, buttonNorthInnerFA.hasFocus());
- Assert.assertEquals(false, jFrame1FA.hasFocus());
+ AWTRobotUtil.assertRequestFocusAndWait(robot, buttonNorthOuter, buttonNorthOuter, buttonNorthOuterFA, jFrame1FA);
+ Assert.assertEquals(true, buttonNorthOuterFA.focusGained());
+ Assert.assertEquals(false, jFrame1FA.focusGained());
+ Assert.assertEquals(true, jFrame1FA.focusLost());
+ Assert.assertEquals(false, glWindow1FA.focusGained());
+ Assert.assertEquals(false, newtCanvasAWTFA.focusGained());
+ Assert.assertEquals(false, buttonNorthInnerFA.focusGained());
+ Assert.assertEquals(false, jFrame1FA.focusGained());
System.err.println("FOCUS AWT Button Outer sync");
AWTRobotUtil.assertKeyType(robot, java.awt.event.KeyEvent.VK_A, 2, buttonNorthOuter, buttonNorthOuterKA);
AWTRobotUtil.assertMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 1,
buttonNorthOuter, buttonNorthOuterMA);
AWTRobotUtil.assertMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 2,
- buttonNorthOuter, buttonNorthOuterMA);
+ buttonNorthOuter, buttonNorthOuterMA);
// NEWT Focus
Thread.sleep(100); // allow event sync
@@ -192,11 +190,13 @@ public class TestFocus02SwingAWTRobot extends UITestCase {
EventCountAdapterUtil.reset(eventCountAdapters);
AWTRobotUtil.assertRequestFocusAndWait(robot, newtCanvasAWT, newtCanvasAWT.getNEWTChild(), glWindow1FA, buttonNorthOuterFA);
Assert.assertTrue(AWTRobotUtil.waitForFocusCount(false, newtCanvasAWTFA));
- Assert.assertEquals(true, glWindow1FA.hasFocus());
- Assert.assertEquals(false, newtCanvasAWTFA.hasFocus());
- Assert.assertEquals(false, buttonNorthInnerFA.hasFocus());
- Assert.assertEquals(false, buttonNorthOuterFA.hasFocus());
- Assert.assertEquals(false, jFrame1FA.hasFocus());
+ Assert.assertEquals(true, glWindow1FA.focusGained());
+ Assert.assertEquals(false, buttonNorthOuterFA.focusGained());
+ Assert.assertEquals(true, buttonNorthOuterFA.focusLost());
+ Assert.assertEquals(false, newtCanvasAWTFA.focusGained());
+ Assert.assertEquals(false, buttonNorthInnerFA.focusGained());
+ Assert.assertEquals(false, buttonNorthOuterFA.focusGained());
+ Assert.assertEquals(false, jFrame1FA.focusGained());
System.err.println("FOCUS NEWT Canvas/GLWindow sync");
AWTRobotUtil.assertKeyType(robot, java.awt.event.KeyEvent.VK_A, 2, glWindow1, glWindow1KA);
Assert.assertEquals("AWT parent canvas received keyboard events", 0, newtCanvasAWTKA.getCount());
@@ -211,11 +211,12 @@ public class TestFocus02SwingAWTRobot extends UITestCase {
System.err.println("FOCUS AWT Button request");
EventCountAdapterUtil.reset(eventCountAdapters);
AWTRobotUtil.assertRequestFocusAndWait(robot, buttonNorthInner, buttonNorthInner, buttonNorthInnerFA, glWindow1FA);
- Assert.assertEquals(true, buttonNorthInnerFA.hasFocus());
- Assert.assertEquals(false, glWindow1FA.hasFocus());
- Assert.assertEquals(false, newtCanvasAWTFA.hasFocus());
- Assert.assertEquals(false, buttonNorthOuterFA.hasFocus());
- Assert.assertEquals(false, jFrame1FA.hasFocus());
+ Assert.assertEquals(true, buttonNorthInnerFA.focusGained());
+ Assert.assertEquals(false, glWindow1FA.focusGained());
+ Assert.assertEquals(true, glWindow1FA.focusLost());
+ Assert.assertEquals(false, newtCanvasAWTFA.focusGained());
+ Assert.assertEquals(false, buttonNorthOuterFA.focusGained());
+ Assert.assertEquals(false, jFrame1FA.focusGained());
System.err.println("FOCUS AWT Button sync");
AWTRobotUtil.assertKeyType(robot, java.awt.event.KeyEvent.VK_A, 2, buttonNorthInner, buttonNorthInnerKA);
AWTRobotUtil.assertMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 1,
@@ -229,11 +230,12 @@ public class TestFocus02SwingAWTRobot extends UITestCase {
EventCountAdapterUtil.reset(eventCountAdapters);
AWTRobotUtil.assertRequestFocusAndWait(robot, newtCanvasAWT, newtCanvasAWT.getNEWTChild(), glWindow1FA, buttonNorthInnerFA);
Assert.assertTrue(AWTRobotUtil.waitForFocusCount(false, newtCanvasAWTFA));
- Assert.assertEquals(true, glWindow1FA.hasFocus());
- Assert.assertEquals(false, newtCanvasAWTFA.hasFocus());
- Assert.assertEquals(false, buttonNorthInnerFA.hasFocus());
- Assert.assertEquals(false, buttonNorthOuterFA.hasFocus());
- Assert.assertEquals(false, jFrame1FA.hasFocus());
+ Assert.assertEquals(true, glWindow1FA.focusGained());
+ Assert.assertEquals(false, buttonNorthInnerFA.focusGained());
+ Assert.assertEquals(true, buttonNorthInnerFA.focusLost());
+ Assert.assertEquals(false, newtCanvasAWTFA.focusGained());
+ Assert.assertEquals(false, buttonNorthOuterFA.focusGained());
+ Assert.assertEquals(false, jFrame1FA.focusGained());
System.err.println("FOCUS NEWT Canvas/GLWindow sync");
AWTRobotUtil.assertKeyType(robot, java.awt.event.KeyEvent.VK_A, 2, glWindow1, glWindow1KA);
Assert.assertEquals("AWT parent canvas received keyboard events", 0, newtCanvasAWTKA.getCount());
diff --git a/src/test/com/jogamp/opengl/test/junit/util/AWTFocusAdapter.java b/src/test/com/jogamp/opengl/test/junit/util/AWTFocusAdapter.java
index d0fbf0788..fe0f2acc0 100644
--- a/src/test/com/jogamp/opengl/test/junit/util/AWTFocusAdapter.java
+++ b/src/test/com/jogamp/opengl/test/junit/util/AWTFocusAdapter.java
@@ -34,7 +34,7 @@ import java.awt.event.FocusListener;
public class AWTFocusAdapter implements FocusEventCountAdapter, FocusListener {
String prefix;
- boolean focusGained;
+ int focusCount;
boolean wasTemporary;
public AWTFocusAdapter(String prefix) {
@@ -42,12 +42,16 @@ public class AWTFocusAdapter implements FocusEventCountAdapter, FocusListener {
reset();
}
- public boolean hasFocus() {
- return focusGained;
+ public boolean focusLost() {
+ return focusCount<0;
}
+ public boolean focusGained() {
+ return focusCount>0;
+ }
+
public void reset() {
- focusGained = false;
+ focusCount = 0;
wasTemporary = false;
}
@@ -58,17 +62,19 @@ public class AWTFocusAdapter implements FocusEventCountAdapter, FocusListener {
/* @Override */
public void focusGained(FocusEvent e) {
- focusGained = true;
+ if(focusCount<0) { focusCount=0; }
+ focusCount++;
wasTemporary = e.isTemporary();
- System.err.println("FOCUS AWT GAINED "+(wasTemporary?"TEMP":"PERM")+" ["+focusGained+"]: "+prefix+", "+e);
+ System.err.println("FOCUS AWT GAINED "+(wasTemporary?"TEMP":"PERM")+" [fc "+focusCount+"]: "+prefix+", "+e);
}
/* @Override */
public void focusLost(FocusEvent e) {
- focusGained = false;
+ if(focusCount>0) { focusCount=0; }
+ focusCount--;
wasTemporary = e.isTemporary();
- System.err.println("FOCUS AWT LOST "+(wasTemporary?"TEMP":"PERM")+" ["+focusGained+"]: "+prefix+", "+e);
+ System.err.println("FOCUS AWT LOST "+(wasTemporary?"TEMP":"PERM")+" [fc "+focusCount+"]: "+prefix+", "+e);
}
- public String toString() { return prefix+"[gained "+focusGained +", temp "+wasTemporary+"]"; }
+ public String toString() { return prefix+"[focusCount "+focusCount +", temp "+wasTemporary+"]"; }
}
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 661d58bb1..a07c3046f 100644
--- a/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java
+++ b/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java
@@ -174,7 +174,7 @@ public class AWTRobotUtil {
final Component comp;
final com.jogamp.newt.Window win;
- KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
+ // KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
if(obj instanceof com.jogamp.newt.Window) {
win = (com.jogamp.newt.Window) obj;
@@ -246,7 +246,7 @@ public class AWTRobotUtil {
int wait;
for (wait=0; wait<POLL_DIVIDER; wait++) {
- if( ( null == lost || !lost.hasFocus() ) && gain.hasFocus() ) {
+ if( ( null == lost || lost.focusLost() ) && gain.focusGained() ) {
return true;
}
Thread.sleep(TIME_SLICE);
@@ -265,6 +265,12 @@ public class AWTRobotUtil {
requestFocus(robot, requestFocus);
hasFocus = waitForFocus(waitForFocus, gain, lost);
}
+ if(!hasFocus) {
+ System.err.println("requestFocus: "+requestFocus);
+ System.err.println("waitForFocus: "+waitForFocus);
+ System.err.println("gain: "+gain);
+ System.err.println("lost: "+lost);
+ }
Assert.assertTrue("Did not gain focus", hasFocus);
}
@@ -402,7 +408,7 @@ public class AWTRobotUtil {
*/
public static boolean waitForFocusCount(boolean desired, FocusEventCountAdapter eca) throws InterruptedException {
for (int wait=0; wait<POLL_DIVIDER; wait++) {
- if( eca.hasFocus() == desired ) {
+ if( desired && eca.focusGained() || !desired && eca.focusLost() ) {
return true;
}
Thread.sleep(TIME_SLICE);
diff --git a/src/test/com/jogamp/opengl/test/junit/util/FocusEventCountAdapter.java b/src/test/com/jogamp/opengl/test/junit/util/FocusEventCountAdapter.java
index b555515b4..461c72683 100644
--- a/src/test/com/jogamp/opengl/test/junit/util/FocusEventCountAdapter.java
+++ b/src/test/com/jogamp/opengl/test/junit/util/FocusEventCountAdapter.java
@@ -29,6 +29,7 @@
package com.jogamp.opengl.test.junit.util;
public interface FocusEventCountAdapter extends EventCountAdapter {
- boolean hasFocus();
+ boolean focusLost();
+ boolean focusGained();
}
diff --git a/src/test/com/jogamp/opengl/test/junit/util/NEWTFocusAdapter.java b/src/test/com/jogamp/opengl/test/junit/util/NEWTFocusAdapter.java
index 9f710c4a0..27d4abd9c 100644
--- a/src/test/com/jogamp/opengl/test/junit/util/NEWTFocusAdapter.java
+++ b/src/test/com/jogamp/opengl/test/junit/util/NEWTFocusAdapter.java
@@ -35,29 +35,35 @@ import com.jogamp.newt.event.WindowUpdateEvent;
public class NEWTFocusAdapter implements WindowListener, FocusEventCountAdapter {
String prefix;
- boolean focusGained;
+ int focusCount;
public NEWTFocusAdapter(String prefix) {
this.prefix = prefix;
reset();
}
- public boolean hasFocus() {
- return focusGained;
+ public boolean focusLost() {
+ return focusCount<0;
+ }
+
+ public boolean focusGained() {
+ return focusCount>0;
}
public void reset() {
- focusGained = false;
+ focusCount = 0;
}
public void windowGainedFocus(WindowEvent e) {
- focusGained = true;
- System.err.println("FOCUS NEWT GAINED ["+focusGained+"]: "+prefix+", "+e);
+ if(focusCount<0) { focusCount=0; }
+ focusCount++;
+ System.err.println("FOCUS NEWT GAINED [fc "+focusCount+"]: "+prefix+", "+e);
}
public void windowLostFocus(WindowEvent e) {
- focusGained = false;
- System.err.println("FOCUS NEWT LOST ["+focusGained+"]: "+prefix+", "+e);
+ if(focusCount>0) { focusCount=0; }
+ focusCount--;
+ System.err.println("FOCUS NEWT LOST [fc "+focusCount+"]: "+prefix+", "+e);
}
public void windowResized(WindowEvent e) { }
@@ -66,6 +72,6 @@ public class NEWTFocusAdapter implements WindowListener, FocusEventCountAdapter
public void windowDestroyed(WindowEvent e) { }
public void windowRepaint(WindowUpdateEvent e) { }
- public String toString() { return prefix+"[gained "+focusGained+"]"; }
+ public String toString() { return prefix+"[focusCount "+focusCount+"]"; }
}