From: <gjo...@us...> - 2007-01-30 17:49:06
|
Revision: 2183 http://abbot.svn.sourceforge.net/abbot/?rev=2183&view=rev Author: gjohnsto Date: 2007-01-30 09:48:08 -0800 (Tue, 30 Jan 2007) Log Message: ----------- Tidy up some more. Add some comments/javadoc. Modified Paths: -------------- abbot.swt/trunk/abbot.swt/src/abbot/swt/utilities/Displays.java abbot.swt/trunk/abbot.swt/test/abbot/swt/tester/test/RobotTest.java Modified: abbot.swt/trunk/abbot.swt/src/abbot/swt/utilities/Displays.java =================================================================== --- abbot.swt/trunk/abbot.swt/src/abbot/swt/utilities/Displays.java 2007-01-30 17:42:15 UTC (rev 2182) +++ abbot.swt/trunk/abbot.swt/src/abbot/swt/utilities/Displays.java 2007-01-30 17:48:08 UTC (rev 2183) @@ -1,6 +1,7 @@ package abbot.swt.utilities; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -28,7 +29,7 @@ * @see #delay(Display, long) */ private static final long MAX_DELAY = Robot.MAX_DELAY; - + /** * Gets the default {@link Robot}. */ @@ -43,8 +44,6 @@ return getRobot().getDisplay(); } - - /** * Gets all undisposed root {@link Shell}s for the default {@link Display}. */ @@ -57,14 +56,16 @@ */ public static List getShells(Display display) { Shell[] shells = getShellsArray(display); - if (shells.length > 0) { - List list = new ArrayList(shells.length); - Collections.addAll(list, (Object[]) shells); - return list; - } + if (shells.length > 0) + return Arrays.asList(shells); return Collections.EMPTY_LIST; } + /** + * Gets an array of all undisposed root {@link Shell}s for the specified {@link Display}. + * + * @see #getShells(Display) + */ private static Shell[] getShellsArray(final Display display) { if (!display.isDisposed()) { @@ -112,45 +113,106 @@ return displays; } - -// GOT HERE + // GOT HERE + /** - * Delays the caller for the specified number of milliseconds. May be called on a thread that - * is, or is not, a display thread without making the display UI unresponsive. + * Delays the caller for the specified number of milliseconds on the default {@link Robot}. + * Safe to call on any {@link Thread}, even the default {@link Robot}'s {@link Display}'s + * {@link Thread}. * * @param ms * the number of milliseconds to delay */ public static void delay(final long ms) { - Robot.getDefault().delay(ms); + delay(getRobot(), ms); } /** - * Dispatches all events that are in the specified display's event queue at the time of the - * call. + * Delays the caller for the specified number of milliseconds on the specified {@link Robot}. + * Safe to call on any {@link Thread}, even the specified {@link Robot}'s {@link Display}'s + * {@link Thread}. * - * @param display - * the {@link Display} to process + * @param robot + * the {@link Robot} to delay on + * @param ms + * the number of milliseconds to delay */ - public static void waitForIdle() { - Robot.getDefault().waitForIdle(); + public static void delay(Robot robot, long ms) { + robot.delay(ms); } /** - * Dispatches all events that are in the specified display's event queue after first delaying - * the specified number of milliseconds. + * Delays the caller for the specified number of milliseconds on a {@link Robot} for the + * specified {@link Display}. Safe to call on any {@link Thread}, even the specified + * {@link Display}'s {@link Thread}. * * @param display - * the {@link Display} to process - * @param + * the {@link Display} + * @param ms + * the number of milliseconds to delay */ + public static void delay(Display display, long ms) { + delay(new Robot(display), ms); + } + + /** + * Dispatches all events that are in the default display's event queue at the time of the call. + */ + public static void waitForIdle() { + waitForIdle(getRobot()); + } + + /** + * Dispatches all events that are in the specified {@link Robot}'s {@link Display}'s event + * queue at the time of the call. + */ + public static void waitForIdle(Robot robot) { + robot.waitForIdle(); + } + + /** + * Dispatches all events that are in the specified display's event queue at the time of the + * call. + * <p> + * <b>Note:</b> Each call to this method creates, but does not cache, a new {@link Robot} to do + * the actual waiting. If you need to wait for idle on the default display, you should probably + * use {@link #waitForIdle()} instead. If you need to wait for idle on a non-default display a + * lot, you should consider creating your own {@link Robot} for it and using + * {@link #waitForIdle(Robot)} instead. + */ + public static void waitForIdle(Display display) { + waitForIdle(new Robot(display)); + } + + /** + * Dispatches all events that are in the default {@link Display}'s event queue after first + * delaying the specified number of milliseconds. + */ public static void waitForIdle(long predelay) { - delay(predelay); - waitForIdle(); + waitForIdle(getRobot(), predelay); } /** + * Dispatches all events that are in the specified {@link Robot}'s {@link Display}'s event + * queue after first delaying the specified number of milliseconds. + */ + public static void waitForIdle(Robot robot, long predelay) { + robot.delay(predelay); + robot.waitForIdle(); + } + + /** + * Dispatches all events that are in the specified {@link Display}'s event queue after first + * delaying the specified number of milliseconds. + * + * @see #waitForIdle(Display) for a caveat + */ + public static void waitForIdle(Display display, long predelay) { + waitForIdle(new Robot(display), predelay); + } + + /** * Throws an {@link IllegalArgumentException} if the specified delay argument is invalid. * * @param ms Modified: abbot.swt/trunk/abbot.swt/test/abbot/swt/tester/test/RobotTest.java =================================================================== --- abbot.swt/trunk/abbot.swt/test/abbot/swt/tester/test/RobotTest.java 2007-01-30 17:42:15 UTC (rev 2182) +++ abbot.swt/trunk/abbot.swt/test/abbot/swt/tester/test/RobotTest.java 2007-01-30 17:48:08 UTC (rev 2183) @@ -490,8 +490,9 @@ robot.focus(tf1); robot.keyString(keymap); robot.waitForIdle(); + String actualText = tf1.getText(); for (int i = 0; i < keymap.length(); i++) { - assertEquals("Wrong text typed", keymap.charAt(i), tf1.getText().charAt(i)); + assertEquals("Wrong text typed", keymap.charAt(i), actualText.charAt(i)); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |