From: <gjo...@us...> - 2007-07-19 17:24:01
|
Revision: 2457 http://abbot.svn.sourceforge.net/abbot/?rev=2457&view=rev Author: gjohnsto Date: 2007-07-19 10:23:53 -0700 (Thu, 19 Jul 2007) Log Message: ----------- Clean up d&d support a bit. Add back individual Robot.drag() and drop() methods. Modified Paths: -------------- abbot.swt/trunk/abbot.swt/src/abbot/swt/Robot.java abbot.swt/trunk/abbot.swt/src/abbot/swt/tester/Robot.java abbot.swt/trunk/abbot.swt/src/abbot/swt/tester/TreeItemTester.java Modified: abbot.swt/trunk/abbot.swt/src/abbot/swt/Robot.java =================================================================== --- abbot.swt/trunk/abbot.swt/src/abbot/swt/Robot.java 2007-07-19 17:11:31 UTC (rev 2456) +++ abbot.swt/trunk/abbot.swt/src/abbot/swt/Robot.java 2007-07-19 17:23:53 UTC (rev 2457) @@ -15,6 +15,9 @@ import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Monitor; +import abbot.swt.utilities.Events; +import abbot.swt.utilities.Events.EventLogger; + /** * Provides API for low-level input event generation. <i>Very</i> roughly analogous to what * <code>java.awt.Robot</code> provides for AWT. @@ -30,7 +33,7 @@ * DragDetect event. This could be 1, but GEF (on Windows, at least) seems to need it to be at * least 2. */ - private static final int DRAG_NUDGE = 2; + private static final int DRAG_THRESHOLD = 2; /** * The default {@link Robot} instance, based on the default {@link Display}. @@ -454,24 +457,59 @@ throw new IllegalArgumentException("invalid key character" + c); } - public synchronized void mouseDragDrop(int sx, int sy, int tx, int ty, int buttons) { + public void mouseDragDrop(int sx, int sy, int tx, int ty, int buttons) { + drag(sx, sy, buttons); + drop(tx, ty, buttons); + } + + public void drag(int sx, int sy, int buttons) { checkThread(); checkLocation(sx, sy); - checkLocation(tx, ty); checkButtons(buttons); - Point n = getNudgeLocation(sx, sy); + int dx = 0; + int dy = 0; + if (isValidLocation(sx + DRAG_THRESHOLD, sy)) + dx = 1; + else if (isValidLocation(sx - DRAG_THRESHOLD, sy)) + dx = -1; + else if (isValidLocation(sx, sy + DRAG_THRESHOLD)) + dy = 1; + else if (isValidLocation(sx, sy - DRAG_THRESHOLD)) + dy = -1; + else + throw new RuntimeException("cannot drag"); +// EventLogger logger = new EventLogger() { +// protected boolean isSignificant(Event event) { +// return event.type != SWT.Paint; +// } +// }; +// Events.addLogger(display, logger); + postMouseMove(sx, sy); - sleep(1000); mousePress(buttons); -// sleep(1000); - postMouseMove(n.x, n.y); -// sleep(1000); + sleep(100); + + int x = sx; + int y = sy; + for (int i = 1; i < DRAG_THRESHOLD; i++) { + sleep(100); + x += dx; + y += dy; + postMouseMove(x, y); + } + +// Events.removeLogger(display, logger); + } + + public synchronized void drop(int tx, int ty, int buttons) { + checkThread(); + checkLocation(tx, ty); + checkButtons(buttons); + postMouseMove(tx, ty); -// sleep(1000); mouseRelease(buttons); -// sleep(1000); } private void sleep(long ms) { @@ -482,23 +520,6 @@ } } - private Point getNudgeLocation(int x, int y) { - - if (isValidLocation(x + DRAG_NUDGE, y)) - return new Point(x + DRAG_NUDGE, y); - - if (isValidLocation(x - DRAG_NUDGE, y)) - return new Point(x - DRAG_NUDGE, y); - - if (isValidLocation(x, y + DRAG_NUDGE)) - return new Point(x, y + DRAG_NUDGE); - - if (isValidLocation(x, y - DRAG_NUDGE)) - return new Point(x, y - DRAG_NUDGE); - - throw new RuntimeException("cannot nudge"); - } - /** * Generates a user input event to move the scroll wheel on wheel-equipped mice. * @@ -939,7 +960,7 @@ }); } - private Point getCursorLocation() { + public Point getCursorLocation() { final Point[] point = new Point[1]; display.syncExec(new Runnable() { public void run() { @@ -949,7 +970,7 @@ return point[0]; } - private Control getCursorControl() { + public Control getCursorControl() { final Control[] control = new Control[1]; display.syncExec(new Runnable() { public void run() { Modified: abbot.swt/trunk/abbot.swt/src/abbot/swt/tester/Robot.java =================================================================== --- abbot.swt/trunk/abbot.swt/src/abbot/swt/tester/Robot.java 2007-07-19 17:11:31 UTC (rev 2456) +++ abbot.swt/trunk/abbot.swt/src/abbot/swt/tester/Robot.java 2007-07-19 17:23:53 UTC (rev 2457) @@ -736,7 +736,7 @@ public void click(Widget widget, int x, int y, int mask) { - Rectangle bounds = getBounds(widget); + Rectangle bounds = getBounds(widget, false); int cx = bounds.x + x; int cy = bounds.y + y; mouseMove(cx, cy); Modified: abbot.swt/trunk/abbot.swt/src/abbot/swt/tester/TreeItemTester.java =================================================================== --- abbot.swt/trunk/abbot.swt/src/abbot/swt/tester/TreeItemTester.java 2007-07-19 17:11:31 UTC (rev 2456) +++ abbot.swt/trunk/abbot.swt/src/abbot/swt/tester/TreeItemTester.java 2007-07-19 17:23:53 UTC (rev 2457) @@ -501,8 +501,28 @@ } }); } - + /** + * @param treeItem + * a {@link TreeItem} + * @param index + * the column index + * @return the bounding {@link Rectangle} of treeItem in display coordinates + */ + public Rectangle getGlobalBounds(final TreeItem treeItem, final int index) { + checkWidget(treeItem); + return (Rectangle) syncExec(new Result() { + public Object result() { + Rectangle bounds = treeItem.getBounds(index); + Point p = treeItem.getParent().toDisplay(bounds.x, bounds.y); + bounds.x = p.x; + bounds.y = p.y; + return bounds; + } + }); + } + + /** * @see TreeItem#getChecked() */ public boolean getChecked(final TreeItem treeItem) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |