diff options
Diffstat (limited to 'src/junit/com/jogamp/test/junit/util/AWTRobotUtil.java')
-rw-r--r-- | src/junit/com/jogamp/test/junit/util/AWTRobotUtil.java | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/junit/com/jogamp/test/junit/util/AWTRobotUtil.java b/src/junit/com/jogamp/test/junit/util/AWTRobotUtil.java index 48563b190..4e0d4a883 100644 --- a/src/junit/com/jogamp/test/junit/util/AWTRobotUtil.java +++ b/src/junit/com/jogamp/test/junit/util/AWTRobotUtil.java @@ -211,6 +211,27 @@ public class AWTRobotUtil { return wait<POLL_DIVIDER; } + /** + * + * @return True if the Window became the global focused Window within TIME_OUT + */ + public static boolean waitForFocus(Object obj, int gainT0, EventCountAdapter gain, + int lostT0, EventCountAdapter lost) throws InterruptedException { + if(!waitForFocus(obj)) { + return false; + } + int wait; + for (wait=0; wait<POLL_DIVIDER; wait++) { + int gainT1 = gain.getCount(); + int lostT1 = (null!=lost) ? lost.getCount() : -1; + if(gainT1-gainT0==1 && lostT1-lostT0==-1) { + return true; + } + Thread.sleep(TIME_OUT/POLL_DIVIDER); + } + return false; + } + public static boolean requestFocusAndWait(Robot robot, Object requestFocus, Object waitForFocus) throws AWTException, InterruptedException, InvocationTargetException { @@ -218,6 +239,17 @@ public class AWTRobotUtil { return waitForFocus(waitForFocus); } + public static boolean requestFocusAndWait(Robot robot, Object requestFocus, Object waitForFocus, + EventCountAdapter gain, EventCountAdapter lost) + throws AWTException, InterruptedException, InvocationTargetException { + + int gainT0 = gain.getCount(); + int lostT0 = (null!=lost) ? lost.getCount() : 0; + + requestFocus(robot, requestFocus); + return waitForFocus(waitForFocus, gainT0, gain, lostT0, lost); + } + /** * @param keyTypedCounter shall return the number of keys typed (press + release) * @return True if typeCount keys within TIME_OUT has been received @@ -288,5 +320,19 @@ public class AWTRobotUtil { return mouseClickCounter.getCount()-c0; } + /** + * + * @return True if the EventCountAdapter became the desired value within TIME_OUT + */ + public static boolean waitForCount(int desired, EventCountAdapter eca) throws InterruptedException { + for (int wait=0; wait<POLL_DIVIDER; wait++) { + if( eca.getCount() == desired ) { + return true; + } + Thread.sleep(TIME_OUT/POLL_DIVIDER); + } + return false; + } + } |