test/lib/testlibrary/ExtendedRobot.java

Print this page

        

*** 23,43 **** * questions. */ import sun.awt.ExtendedKeyCodes; import sun.awt.SunToolkit; - import sun.security.action.GetIntegerAction; import java.awt.AWTException; import java.awt.Robot; import java.awt.GraphicsDevice; import java.awt.Toolkit; import java.awt.Point; import java.awt.MouseInfo; import java.awt.event.InputEvent; - import java.security.AccessController; - import java.security.PrivilegedAction; /** * ExtendedRobot is a subclass of {@link java.awt.Robot}. It provides some convenience methods that are * ought to be moved to {@link java.awt.Robot} class. * <p> --- 23,40 ----
*** 310,319 **** --- 307,358 ---- */ public synchronized void mouseMove(Point position) { mouseMove(position.x, position.y); } + + /** + * Emulate native drag and drop process using {@code InputEvent.BUTTON1_DOWN_MASK}. + * The method successively moves mouse cursor to point with coordinates + * ({@code fromX}, {@code fromY}), presses mouse button 1, drag mouse to + * point with coordinates ({@code toX}, {@code toY}) and releases mouse + * button 1 at last. + * + * @param fromX Source point x coordinate + * @param fromY Source point y coordinate + * @param toX Destination point x coordinate + * @param toY Destination point y coordinate + * + * @see #mousePress(int) + * @see #glide(int, int, int, int) + */ + public void dragAndDrop(int fromX, int fromY, int toX, int toY){ + mouseMove(fromX, fromY); + mousePress(InputEvent.BUTTON1_DOWN_MASK); + waitForIdle(); + glide(toX, toY); + mouseRelease(InputEvent.BUTTON1_DOWN_MASK); + waitForIdle(); + } + + /** + * Emulate native drag and drop process using {@code InputEvent.BUTTON1_DOWN_MASK}. + * The method successively moves mouse cursor to point {@code from}, + * presses mouse button 1, drag mouse to point {@code to} and releases + * mouse button 1 at last. + * + * @param from Source point + * @param to Destination point + * + * @see #mousePress(int) + * @see #glide(int, int, int, int) + * @see #dragAndDrop(int, int, int, int) + */ + public void dragAndDrop(Point from, Point to){ + dragAndDrop(from.x, from.y, to.x, to.y); + } + /** * Successively presses and releases a given key. * <p> * Key codes that have more than one physical key associated with them * (e.g. {@code KeyEvent.VK_SHIFT} could mean either the