test/java/awt/regtesthelpers/Util.java

Print this page




 183      * @param color expected color
 184      * @param attempts number of attempts to undertake
 185      * @param delay delay before each attempt
 186      * @param robot a robot to use for retrieving pixel color
 187      * @return true if area color matches the color expected, otherwise false
 188      */
 189     public static boolean testBoundsColor(final Rectangle bounds, final Color color, int attempts, int delay, final Robot robot) {
 190         int right = bounds.x + bounds.width - 1;
 191         int bottom = bounds.y + bounds.height - 1;
 192         while (attempts-- > 0) {
 193             if (testPixelColor(bounds.x, bounds.y, color, 1, delay, robot)
 194                 && testPixelColor(right, bounds.y, color, 1, 0, robot)
 195                 && testPixelColor(right, bottom, color, 1, 0, robot)
 196                 && testPixelColor(bounds.x, bottom, color, 1, 0, robot)) {
 197                 return true;
 198             }
 199         }
 200         return false;
 201     }
 202 
 203     public static void waitForIdle(final Robot robot) {



 204         robot.waitForIdle();
 205     }
 206 
 207     public static Field getField(final Class klass, final String fieldName) {
 208         return AccessController.doPrivileged(new PrivilegedAction<Field>() {
 209             public Field run() {
 210                 try {
 211                     Field field = klass.getDeclaredField(fieldName);
 212                     assert (field != null);
 213                     field.setAccessible(true);
 214                     return field;
 215                 } catch (SecurityException se) {
 216                     throw new RuntimeException("Error: unexpected exception caught!", se);
 217                 } catch (NoSuchFieldException nsfe) {
 218                     throw new RuntimeException("Error: unexpected exception caught!", nsfe);
 219                 }
 220             }
 221         });
 222     }
 223 




 183      * @param color expected color
 184      * @param attempts number of attempts to undertake
 185      * @param delay delay before each attempt
 186      * @param robot a robot to use for retrieving pixel color
 187      * @return true if area color matches the color expected, otherwise false
 188      */
 189     public static boolean testBoundsColor(final Rectangle bounds, final Color color, int attempts, int delay, final Robot robot) {
 190         int right = bounds.x + bounds.width - 1;
 191         int bottom = bounds.y + bounds.height - 1;
 192         while (attempts-- > 0) {
 193             if (testPixelColor(bounds.x, bounds.y, color, 1, delay, robot)
 194                 && testPixelColor(right, bounds.y, color, 1, 0, robot)
 195                 && testPixelColor(right, bottom, color, 1, 0, robot)
 196                 && testPixelColor(bounds.x, bottom, color, 1, 0, robot)) {
 197                 return true;
 198             }
 199         }
 200         return false;
 201     }
 202 
 203     public static void waitForIdle(Robot robot) {
 204         if (robot == null) {
 205             robot = createRobot();
 206         }
 207         robot.waitForIdle();
 208     }
 209 
 210     public static Field getField(final Class klass, final String fieldName) {
 211         return AccessController.doPrivileged(new PrivilegedAction<Field>() {
 212             public Field run() {
 213                 try {
 214                     Field field = klass.getDeclaredField(fieldName);
 215                     assert (field != null);
 216                     field.setAccessible(true);
 217                     return field;
 218                 } catch (SecurityException se) {
 219                     throw new RuntimeException("Error: unexpected exception caught!", se);
 220                 } catch (NoSuchFieldException nsfe) {
 221                     throw new RuntimeException("Error: unexpected exception caught!", nsfe);
 222                 }
 223             }
 224         });
 225     }
 226