summaryrefslogtreecommitdiffstats
path: root/src/junit
diff options
context:
space:
mode:
Diffstat (limited to 'src/junit')
-rw-r--r--src/junit/com/jogamp/test/junit/jogl/awt/TestSwingAWTUsageBeforeJOGLInitBug411.java52
-rw-r--r--src/junit/com/jogamp/test/junit/newt/TestFocus01SwingAWT.java1
-rw-r--r--src/junit/com/jogamp/test/junit/newt/TestFocus02SwingAWT.java6
-rw-r--r--src/junit/com/jogamp/test/junit/util/AWTRobotUtil.java39
4 files changed, 54 insertions, 44 deletions
diff --git a/src/junit/com/jogamp/test/junit/jogl/awt/TestSwingAWTUsageBeforeJOGLInitBug411.java b/src/junit/com/jogamp/test/junit/jogl/awt/TestSwingAWTUsageBeforeJOGLInitBug411.java
index ac6b61586..f55c9b8c8 100644
--- a/src/junit/com/jogamp/test/junit/jogl/awt/TestSwingAWTUsageBeforeJOGLInitBug411.java
+++ b/src/junit/com/jogamp/test/junit/jogl/awt/TestSwingAWTUsageBeforeJOGLInitBug411.java
@@ -29,6 +29,7 @@
package com.jogamp.test.junit.jogl.awt;
import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears;
+import com.jogamp.test.junit.util.*;
import java.lang.reflect.InvocationTargetException;
import javax.media.opengl.GLAutoDrawable;
@@ -40,6 +41,7 @@ import com.jogamp.opengl.util.Animator;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.newt.awt.NewtCanvasAWT;
+import java.awt.AWTException;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
@@ -73,8 +75,6 @@ import org.junit.Test;
public class TestSwingAWTUsageBeforeJOGLInitBug411 {
static long durationPerTest = 500; // ms
static Robot robot;
- static boolean keyTyped;
- static boolean buttonClicked;
static Border border;
static JFrame frame;
static JButton button;
@@ -118,8 +118,6 @@ public class TestSwingAWTUsageBeforeJOGLInitBug411 {
int count;
// simulate AWT usage before JOGL's initialization of X11 threading
- keyTyped = false;
- buttonClicked = false;
windowClosing=false;
border = BorderFactory.createLineBorder (Color.yellow, 2);
@@ -130,7 +128,6 @@ public class TestSwingAWTUsageBeforeJOGLInitBug411 {
button.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
System.err.println("Test: "+e);
- buttonClicked = true;
}
});
panel.add(button, BorderLayout.NORTH);
@@ -147,12 +144,6 @@ public class TestSwingAWTUsageBeforeJOGLInitBug411 {
windowClosing=true;
}
});
- frame.addKeyListener(new KeyAdapter() {
- public void keyTyped(KeyEvent e) {
- System.err.println("Test: "+e);
- keyTyped = true;
- }
- });
frame.setContentPane(panel);
frame.setSize(512, 512);
frame.pack();
@@ -170,34 +161,9 @@ public class TestSwingAWTUsageBeforeJOGLInitBug411 {
robot = new Robot();
robot.setAutoWaitForIdle(true);
- javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
- public void run() {
- frame.requestFocus();
- }});
+ AWTRobotUtil.toFront(robot, frame);
+ AWTRobotUtil.requestFocus(robot, button);
- Thread.sleep(200);
-
- robot.delay(100);
-
- for (count=0; !keyTyped && count<99; count++) {
- robot.keyPress(KeyEvent.VK_Q);
- robot.delay(50);
- robot.keyRelease(KeyEvent.VK_Q);
- robot.delay(100);
- Thread.sleep(100);
- }
- Point p0 = button.getLocationOnScreen();
- Rectangle r0 = button.getBounds();
- robot.mouseMove( (int) ( p0.getX() + r0.getWidth() /2.0 + .5 ) ,
- (int) ( p0.getY() + r0.getHeight()/2.0 + .5 ) );
-
- for (count=0; !buttonClicked && count<99; count++) {
- robot.mousePress(InputEvent.BUTTON1_MASK);
- robot.delay(50);
- robot.mouseRelease(InputEvent.BUTTON1_MASK);
- robot.delay(100);
- Thread.sleep(100);
- }
System.err.println("Clean End of Pre-JOGL-Swing");
GLProfile.initSingleton();
@@ -211,7 +177,9 @@ public class TestSwingAWTUsageBeforeJOGLInitBug411 {
frame=null;
}
- protected void runTestGL(final Canvas canvas, GLAutoDrawable drawable) throws InterruptedException, InvocationTargetException {
+ protected void runTestGL(final Canvas canvas, GLAutoDrawable drawable)
+ throws AWTException, InterruptedException, InvocationTargetException {
+
Dimension size = new Dimension(400,400);
canvas.setPreferredSize(size);
@@ -222,6 +190,8 @@ public class TestSwingAWTUsageBeforeJOGLInitBug411 {
}
});
+ AWTRobotUtil.toFront(robot, frame);
+
drawable.addGLEventListener(new Gears());
for(int i=0; i<100; i++) {
@@ -270,7 +240,7 @@ public class TestSwingAWTUsageBeforeJOGLInitBug411 {
}
@Test
- public void test01GLCanvas() throws InterruptedException, InvocationTargetException {
+ public void test01GLCanvas() throws AWTException, InterruptedException, InvocationTargetException {
GLProfile glp = GLProfile.getDefault();
GLCapabilities caps = new GLCapabilities(glp);
@@ -290,7 +260,7 @@ public class TestSwingAWTUsageBeforeJOGLInitBug411 {
}
@Test
- public void test02NewtCanvasAWT() throws InterruptedException, InvocationTargetException {
+ public void test02NewtCanvasAWT() throws AWTException, InterruptedException, InvocationTargetException {
GLProfile glp = GLProfile.getDefault();
GLCapabilities caps = new GLCapabilities(glp);
diff --git a/src/junit/com/jogamp/test/junit/newt/TestFocus01SwingAWT.java b/src/junit/com/jogamp/test/junit/newt/TestFocus01SwingAWT.java
index 3a85b4795..bcfe3b86b 100644
--- a/src/junit/com/jogamp/test/junit/newt/TestFocus01SwingAWT.java
+++ b/src/junit/com/jogamp/test/junit/newt/TestFocus01SwingAWT.java
@@ -100,6 +100,7 @@ public class TestFocus01SwingAWT {
frame1.getContentPane().add(button, BorderLayout.NORTH);
frame1.setSize(width, height);
frame1.setVisible(true);
+ AWTRobotUtil.toFront(robot, frame1);
int wait=0;
while(wait<10 && glWindow1.getTotalFrames()<1) { Thread.sleep(100); wait++; }
diff --git a/src/junit/com/jogamp/test/junit/newt/TestFocus02SwingAWT.java b/src/junit/com/jogamp/test/junit/newt/TestFocus02SwingAWT.java
index c7948540f..c0ea9fa33 100644
--- a/src/junit/com/jogamp/test/junit/newt/TestFocus02SwingAWT.java
+++ b/src/junit/com/jogamp/test/junit/newt/TestFocus02SwingAWT.java
@@ -92,7 +92,8 @@ public class TestFocus02SwingAWT {
}
- private void testFocus01ProgrFocusImpl(Robot robot) throws InterruptedException, InvocationTargetException {
+ private void testFocus01ProgrFocusImpl(Robot robot)
+ throws AWTException, InterruptedException, InvocationTargetException {
int x = 0;
int y = 0;
@@ -140,6 +141,7 @@ public class TestFocus02SwingAWT {
jFrame1.setContentPane(jPanel1);
jFrame1.setSize(width, height);
jFrame1.setVisible(true); // from here on, we need to run modifications on EDT
+ AWTRobotUtil.toFront(robot, jFrame1);
int wait=0;
while(wait<10 && glWindow1.getTotalFrames()<1) { Thread.sleep(100); wait++; }
@@ -240,7 +242,7 @@ public class TestFocus02SwingAWT {
}
@Test
- public void testFocus01ProgrFocus() throws InterruptedException, InvocationTargetException {
+ public void testFocus01ProgrFocus() throws AWTException, InterruptedException, InvocationTargetException {
testFocus01ProgrFocusImpl(null);
}
diff --git a/src/junit/com/jogamp/test/junit/util/AWTRobotUtil.java b/src/junit/com/jogamp/test/junit/util/AWTRobotUtil.java
index 419601e03..ba11df4d6 100644
--- a/src/junit/com/jogamp/test/junit/util/AWTRobotUtil.java
+++ b/src/junit/com/jogamp/test/junit/util/AWTRobotUtil.java
@@ -35,11 +35,48 @@ import java.awt.Container;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
+import java.awt.Window;
import java.awt.event.InputEvent;
import javax.swing.JFrame;
public class AWTRobotUtil {
+ /**
+ * toFront, call setVisible(true) and toFront(),
+ * after positioning the mouse in the middle of the window via robot.
+ * If the given robot is null, a new one is created (waitForIdle=true).
+ */
+ public static void toFront(Robot robot, Window window)
+ throws AWTException, InterruptedException, InvocationTargetException {
+
+ if(null == robot) {
+ robot = new Robot();
+ robot.setAutoWaitForIdle(true);
+ }
+ Point p0 = window.getLocationOnScreen();
+ Rectangle r0 = window.getBounds();
+ int dx = (int) ( r0.getWidth() / 2.0 + .5 );
+ int dy = (int) ( r0.getHeight() / 2.0 + .5 );
+ int x0 = (int) ( p0.getX() + dx + .5 ) ;
+ int y0 = (int) ( p0.getY() + dy + .5 ) ;
+ System.err.println("robot pos: "+x0+"/"+y0);
+ robot.mouseMove( x0, y0 );
+ robot.delay(50);
+
+ final Window f_window = window;
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ f_window.setVisible(true);
+ f_window.toFront();
+ f_window.requestFocus();
+ }});
+ robot.delay(200);
+ }
+
+ /**
+ * requestFocus, if robot is valid, use mouse operation,
+ * otherwise programatic, ie call requestFocus
+ */
public static void requestFocus(Robot robot, Object obj)
throws InterruptedException, InvocationTargetException {
Component comp = null;
@@ -87,7 +124,7 @@ public class AWTRobotUtil {
y0 = win.getY() + win.getHeight() / 2 ;
}
- System.err.println("pos: "+x0+"/"+y0);
+ System.err.println("robot pos: "+x0+"/"+y0);
robot.mouseMove( x0, y0 );
robot.delay(50);
robot.mousePress(InputEvent.BUTTON1_MASK);