test/java/awt/regtesthelpers/Util.java

Print this page




 145      * and performs a left mouse button click using the {@code robot} parameter
 146      * with the {@code delay} delay between press and release.
 147      */
 148     public static void clickOnComp(final Component comp, final Robot robot, int delay) {
 149         pointOnComp(comp, robot);
 150         robot.delay(delay);
 151         robot.mousePress(InputEvent.BUTTON1_MASK);
 152         robot.delay(delay);
 153         robot.mouseRelease(InputEvent.BUTTON1_MASK);
 154     }
 155 
 156     /**
 157      * Moves mouse pointer in the center of a given {@code comp} component
 158      * and performs a left mouse button click using the {@code robot} parameter
 159      * with the default delay between press and release.
 160      */
 161     public static void clickOnComp(final Component comp, final Robot robot) {
 162         clickOnComp(comp, robot, 50);
 163     }
 164 







 165     /*
 166      * Clicks on a title of Frame/Dialog.
 167      * WARNING: it may fail on some platforms when the window is not wide enough.
 168      */
 169     public static void clickOnTitle(final Window decoratedWindow, final Robot robot) {
 170         Point p = decoratedWindow.getLocationOnScreen();
 171         Dimension d = decoratedWindow.getSize();
 172 
 173         if (decoratedWindow instanceof Frame || decoratedWindow instanceof Dialog) {
 174             robot.mouseMove(p.x + (int)(d.getWidth()/2), p.y + (int)decoratedWindow.getInsets().top/2);

 175             robot.delay(50);
 176             robot.mousePress(InputEvent.BUTTON1_MASK);
 177             robot.delay(50);
 178             robot.mouseRelease(InputEvent.BUTTON1_MASK);
 179         }
 180     }
 181 
 182     public static void waitForIdle(final Robot robot) {
 183         // we do not use robot for now, use SunToolkit.realSync() instead
 184         ((sun.awt.SunToolkit)Toolkit.getDefaultToolkit()).realSync();
 185     }
 186 
 187     public static Field getField(final Class klass, final String fieldName) {
 188         return AccessController.doPrivileged(new PrivilegedAction<Field>() {
 189             public Field run() {
 190                 try {
 191                     Field field = klass.getDeclaredField(fieldName);
 192                     assert (field != null);
 193                     field.setAccessible(true);
 194                     return field;


 392         };
 393     }
 394 
 395     /*
 396      * The values directly map to the ones of
 397      * sun.awt.X11.XWM & sun.awt.motif.MToolkit classes.
 398      */
 399     public final static int
 400         UNDETERMINED_WM = 1,
 401         NO_WM = 2,
 402         OTHER_WM = 3,
 403         OPENLOOK_WM = 4,
 404         MOTIF_WM = 5,
 405         CDE_WM = 6,
 406         ENLIGHTEN_WM = 7,
 407         KDE2_WM = 8,
 408         SAWFISH_WM = 9,
 409         ICE_WM = 10,
 410         METACITY_WM = 11,
 411         COMPIZ_WM = 12,
 412         LG3D_WM = 13;


 413 
 414     /*
 415      * Returns -1 in case of not X Window or any problems.
 416      */
 417     public static int getWMID() {
 418         Class clazz = null;
 419         try {
 420             if ("sun.awt.X11.XToolkit".equals(Toolkit.getDefaultToolkit().getClass().getName())) {
 421                 clazz = Class.forName("sun.awt.X11.XWM");
 422             } else if ("sun.awt.motif.MToolkit".equals(Toolkit.getDefaultToolkit().getClass().getName())) {
 423                 clazz = Class.forName("sun.awt.motif.MToolkit");
 424             }
 425         } catch (ClassNotFoundException cnfe) {
 426             cnfe.printStackTrace();
 427         }
 428         if (clazz == null) {
 429             return -1;
 430         }
 431 
 432         try {




 145      * and performs a left mouse button click using the {@code robot} parameter
 146      * with the {@code delay} delay between press and release.
 147      */
 148     public static void clickOnComp(final Component comp, final Robot robot, int delay) {
 149         pointOnComp(comp, robot);
 150         robot.delay(delay);
 151         robot.mousePress(InputEvent.BUTTON1_MASK);
 152         robot.delay(delay);
 153         robot.mouseRelease(InputEvent.BUTTON1_MASK);
 154     }
 155 
 156     /**
 157      * Moves mouse pointer in the center of a given {@code comp} component
 158      * and performs a left mouse button click using the {@code robot} parameter
 159      * with the default delay between press and release.
 160      */
 161     public static void clickOnComp(final Component comp, final Robot robot) {
 162         clickOnComp(comp, robot, 50);
 163     }
 164 
 165     public static Point getTitlePoint(Window decoratedWindow) {
 166         Point p = decoratedWindow.getLocationOnScreen();
 167         Dimension d = decoratedWindow.getSize();
 168         return new Point(p.x + (int)(d.getWidth()/2),
 169                          p.y + (int)(decoratedWindow.getInsets().top/2));
 170     }
 171 
 172     /*
 173      * Clicks on a title of Frame/Dialog.
 174      * WARNING: it may fail on some platforms when the window is not wide enough.
 175      */
 176     public static void clickOnTitle(final Window decoratedWindow, final Robot robot) {



 177         if (decoratedWindow instanceof Frame || decoratedWindow instanceof Dialog) {
 178             Point p = getTitlePoint(decoratedWindow);
 179             robot.mouseMove(p.x, p.y);
 180             robot.delay(50);
 181             robot.mousePress(InputEvent.BUTTON1_MASK);
 182             robot.delay(50);
 183             robot.mouseRelease(InputEvent.BUTTON1_MASK);
 184         }
 185     }
 186 
 187     public static void waitForIdle(final Robot robot) {
 188         // we do not use robot for now, use SunToolkit.realSync() instead
 189         ((sun.awt.SunToolkit)Toolkit.getDefaultToolkit()).realSync();
 190     }
 191 
 192     public static Field getField(final Class klass, final String fieldName) {
 193         return AccessController.doPrivileged(new PrivilegedAction<Field>() {
 194             public Field run() {
 195                 try {
 196                     Field field = klass.getDeclaredField(fieldName);
 197                     assert (field != null);
 198                     field.setAccessible(true);
 199                     return field;


 397         };
 398     }
 399 
 400     /*
 401      * The values directly map to the ones of
 402      * sun.awt.X11.XWM & sun.awt.motif.MToolkit classes.
 403      */
 404     public final static int
 405         UNDETERMINED_WM = 1,
 406         NO_WM = 2,
 407         OTHER_WM = 3,
 408         OPENLOOK_WM = 4,
 409         MOTIF_WM = 5,
 410         CDE_WM = 6,
 411         ENLIGHTEN_WM = 7,
 412         KDE2_WM = 8,
 413         SAWFISH_WM = 9,
 414         ICE_WM = 10,
 415         METACITY_WM = 11,
 416         COMPIZ_WM = 12,
 417         LG3D_WM = 13,
 418         CWM_WM = 14,
 419         MUTTER_WM = 15;
 420 
 421     /*
 422      * Returns -1 in case of not X Window or any problems.
 423      */
 424     public static int getWMID() {
 425         Class clazz = null;
 426         try {
 427             if ("sun.awt.X11.XToolkit".equals(Toolkit.getDefaultToolkit().getClass().getName())) {
 428                 clazz = Class.forName("sun.awt.X11.XWM");
 429             } else if ("sun.awt.motif.MToolkit".equals(Toolkit.getDefaultToolkit().getClass().getName())) {
 430                 clazz = Class.forName("sun.awt.motif.MToolkit");
 431             }
 432         } catch (ClassNotFoundException cnfe) {
 433             cnfe.printStackTrace();
 434         }
 435         if (clazz == null) {
 436             return -1;
 437         }
 438 
 439         try {