diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java | 68 |
1 files changed, 37 insertions, 31 deletions
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 a07c3046f..6c502f33e 100644 --- a/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java +++ b/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java @@ -32,16 +32,12 @@ import jogamp.newt.WindowImplAccess; import java.lang.reflect.InvocationTargetException; import java.awt.AWTException; import java.awt.Component; -import java.awt.Container; import java.awt.EventQueue; import java.awt.KeyboardFocusManager; -import java.awt.Point; -import java.awt.Rectangle; import java.awt.Robot; import java.awt.Toolkit; import javax.media.opengl.awt.GLCanvas; -import javax.swing.JFrame; import org.junit.Assert; @@ -56,7 +52,7 @@ public class AWTRobotUtil { public static final int TIME_SLICE = TIME_OUT / POLL_DIVIDER ; public static Integer AWT_CLICK_TO = null; - public static Point getCenterLocation(Object obj) + public static java.awt.Point getCenterLocation(Object obj, boolean onTitleBarIfWindow) throws InterruptedException, InvocationTargetException { Component comp = null; com.jogamp.newt.Window win = null; @@ -71,28 +67,29 @@ public class AWTRobotUtil { int x0, y0; if(null!=comp) { - Point p0 = comp.getLocationOnScreen(); - Rectangle r0 = comp.getBounds(); - if( comp instanceof JFrame ) { - JFrame jFrame = (JFrame) comp; - Container cont = jFrame.getContentPane(); - Point p1 = cont.getLocationOnScreen(); - int dx = (int) ( r0.getWidth() / 2.0 + .5 ); - int dy = (int) ( ( p1.getY() - p0.getY() ) / 2.0 + .5 ); - x0 = (int) ( p0.getX() + dx + .5 ) ; - y0 = (int) ( p0.getY() + dy + .5 ) ; + java.awt.Point p0 = comp.getLocationOnScreen(); + java.awt.Rectangle r0 = comp.getBounds(); + if( onTitleBarIfWindow && comp instanceof java.awt.Window) { + java.awt.Window window = (java.awt.Window) comp; + java.awt.Insets insets = window.getInsets(); + y0 = (int) ( p0.getY() + insets.top / 2.0 + .5 ) ; } else { - x0 = (int) ( p0.getX() + r0.getWidth() / 2.0 + .5 ) ; y0 = (int) ( p0.getY() + r0.getHeight() / 2.0 + .5 ) ; } + x0 = (int) ( p0.getX() + r0.getWidth() / 2.0 + .5 ) ; } else { javax.media.nativewindow.util.Point p0 = win.getLocationOnScreen(null); - p0.translate(win.getWidth()/2, win.getHeight()/2); + if( onTitleBarIfWindow ) { + javax.media.nativewindow.util.InsetsImmutable insets = win.getInsets(); + p0.translate(win.getWidth()/2, insets.getTopHeight()/2); + } else { + p0.translate(win.getWidth()/2, win.getHeight()/2); + } x0 = p0.getX(); y0 = p0.getY(); } - return new Point(x0, y0); + return new java.awt.Point(x0, y0); } /** @@ -109,7 +106,7 @@ public class AWTRobotUtil { robot = new Robot(); robot.setAutoWaitForIdle(true); } - Point p0 = getCenterLocation(window); + java.awt.Point p0 = getCenterLocation(window, false); System.err.println("robot pos: "+p0); robot.mouseMove( (int) p0.getX(), (int) p0.getY() ); robot.delay(ROBOT_DELAY); @@ -132,8 +129,9 @@ public class AWTRobotUtil { /** * centerMouse + * @param onTitleBarIfWindow TODO */ - public static void centerMouse(Robot robot, Object obj) + public static void centerMouse(Robot robot, Object obj, boolean onTitleBarIfWindow) throws AWTException, InterruptedException, InvocationTargetException { if(null == robot) { @@ -141,7 +139,7 @@ public class AWTRobotUtil { robot.setAutoWaitForIdle(true); } - Point p0 = getCenterLocation(obj); + java.awt.Point p0 = getCenterLocation(obj, onTitleBarIfWindow); System.err.println("robot pos: "+p0); robot.mouseMove( (int) p0.getX(), (int) p0.getY() ); @@ -174,8 +172,6 @@ public class AWTRobotUtil { final Component comp; final com.jogamp.newt.Window win; - // KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner(); - if(obj instanceof com.jogamp.newt.Window) { win = (com.jogamp.newt.Window) obj; comp = null; @@ -186,13 +182,23 @@ public class AWTRobotUtil { throw new RuntimeException("Neither AWT nor NEWT: "+obj); } - if(null!=comp) { - javax.swing.SwingUtilities.invokeAndWait(new Runnable() { - public void run() { - comp.requestFocus(); - }}); + if(null == robot) { + if(null!=comp) { + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + comp.requestFocus(); + }}); + } else { + win.requestFocus(); + } } else { - win.requestFocus(); + final int mouseButton = java.awt.event.InputEvent.BUTTON1_MASK; + centerMouse(robot, obj, true); + + robot.waitForIdle(); + robot.mousePress(mouseButton); + robot.mouseRelease(mouseButton); + robot.delay( getClickTimeout(obj) + 1 ); } } @@ -317,7 +323,7 @@ public class AWTRobotUtil { robot.setAutoWaitForIdle(true); } - centerMouse(robot, obj); + centerMouse(robot, obj, false); Assert.assertEquals("Key already pressed", false, counter.isPressed()); @@ -381,7 +387,7 @@ public class AWTRobotUtil { final int clickTO = getClickTimeout(obj); - centerMouse(robot, obj); + centerMouse(robot, obj, false); Assert.assertEquals("Mouse already pressed", false, counter.isPressed()); |