23 * questions. 24 */ 25 package org.jemmy.input; 26 27 28 import java.awt.event.InputEvent; 29 import org.jemmy.control.*; 30 import org.jemmy.Point; 31 import org.jemmy.action.Action; 32 import org.jemmy.env.Environment; 33 import org.jemmy.env.Timeout; 34 import org.jemmy.interfaces.Mouse.MouseButton; 35 import org.jemmy.interfaces.Drag; 36 import org.jemmy.interfaces.Modifier; 37 import org.jemmy.interfaces.Mouse; 38 import org.jemmy.interfaces.Mouse.MouseButtons; 39 import org.jemmy.interfaces.Showable; 40 41 42 /** 43 * 44 * @author shura 45 */ 46 public class DragImpl implements Drag { 47 48 /** 49 * 50 */ 51 public static final int DND_POINTS = 10; 52 53 static { 54 Environment.getEnvironment().setTimeout(BEFORE_DRAG_TIMEOUT); 55 Environment.getEnvironment().setTimeout(BEFORE_DROP_TIMEOUT); 56 Environment.getEnvironment().setTimeout(IN_DRAG_TIMEOUT); 57 } 58 59 private Wrap<?> source; 60 61 /** 62 * 63 * @param source 64 */ 65 public DragImpl(Wrap<?> source) { 66 this.source = source; 67 } 68 69 /** 70 * 71 * @param targetPoint 72 */ 73 public void dnd(Point targetPoint) { 74 dnd(source, targetPoint); 75 } 76 77 /** 78 * 79 * @param target 80 * @param targetPoint 81 */ 82 public void dnd(Wrap target, Point targetPoint) { 83 dnd(source.getClickPoint(), target, targetPoint); 84 } 85 86 /** 87 * 88 * @param point 89 * @param target 90 * @param targetPoint 91 */ 92 public void dnd(Point point, Wrap target, Point targetPoint) { 93 dnd(point, target, targetPoint, MouseButtons.BUTTON1); 94 } 95 96 /** 97 * 98 * @param point 99 * @param target 100 * @param targetPoint 101 * @param button 102 */ 103 public void dnd(Point point, Wrap target, Point targetPoint, MouseButton button) { 104 dnd(point, target, targetPoint, button, new Modifier[]{}); 105 } 106 107 /** 108 * 109 * @param point 110 * @param target 111 * @param targetPoint 112 * @param button 113 * @param modifiers 114 */ 115 public void dnd(Point pointParam, final Wrap target, final Point targetPoint, final MouseButton button, final Modifier... modifiers) { 116 final Point point = pointParam == null ? source.getClickPoint() : pointParam; 117 source.getEnvironment().getExecutor().execute(target.getEnvironment(), false, new Action() { 118 public void run(Object... parameters) { 119 if(source.is(Showable.class)) ((Showable)source.as(Showable.class)).shower().show(); 120 source.mouse().move(point); 121 source.mouse().press(button, modifiers); 122 source.getEnvironment().getTimeout(BEFORE_DRAG_TIMEOUT.getName()).sleep(); 123 Point intermediatePoint = new Point(); 124 int xDistance = target.getScreenBounds().x + targetPoint.x - source.getScreenBounds().x - point.x; 125 int yDistance = target.getScreenBounds().y + targetPoint.y - source.getScreenBounds().y - point.y; 126 int startX = point.x + source.getScreenBounds().x; 127 int startY = point.y + source.getScreenBounds().y; 128 int endX = startX + xDistance; 129 int endY = startY + yDistance; 130 for(int i = 0; i < DND_POINTS + 1; i++) { 131 intermediatePoint.x = startX + xDistance * i / DND_POINTS - source.getScreenBounds().x; 132 intermediatePoint.y = startY + yDistance * i / DND_POINTS - source.getScreenBounds().y; 133 source.mouse().move(intermediatePoint); 134 source.getEnvironment().getTimeout(IN_DRAG_TIMEOUT.getName()).sleep(); | 23 * questions. 24 */ 25 package org.jemmy.input; 26 27 28 import java.awt.event.InputEvent; 29 import org.jemmy.control.*; 30 import org.jemmy.Point; 31 import org.jemmy.action.Action; 32 import org.jemmy.env.Environment; 33 import org.jemmy.env.Timeout; 34 import org.jemmy.interfaces.Mouse.MouseButton; 35 import org.jemmy.interfaces.Drag; 36 import org.jemmy.interfaces.Modifier; 37 import org.jemmy.interfaces.Mouse; 38 import org.jemmy.interfaces.Mouse.MouseButtons; 39 import org.jemmy.interfaces.Showable; 40 41 42 /** 43 * @author shura 44 */ 45 public class DragImpl implements Drag { 46 47 public static final int DND_POINTS = 10; 48 49 static { 50 Environment.getEnvironment().setTimeout(BEFORE_DRAG_TIMEOUT); 51 Environment.getEnvironment().setTimeout(BEFORE_DROP_TIMEOUT); 52 Environment.getEnvironment().setTimeout(IN_DRAG_TIMEOUT); 53 } 54 55 private Wrap<?> source; 56 57 public DragImpl(Wrap<?> source) { 58 this.source = source; 59 } 60 61 public void dnd(Point targetPoint) { 62 dnd(source, targetPoint); 63 } 64 65 public void dnd(Wrap target, Point targetPoint) { 66 dnd(source.getClickPoint(), target, targetPoint); 67 } 68 69 public void dnd(Point point, Wrap target, Point targetPoint) { 70 dnd(point, target, targetPoint, MouseButtons.BUTTON1); 71 } 72 73 public void dnd(Point point, Wrap target, Point targetPoint, MouseButton button) { 74 dnd(point, target, targetPoint, button, new Modifier[]{}); 75 } 76 77 public void dnd(Point pointParam, final Wrap target, final Point targetPoint, final MouseButton button, final Modifier... modifiers) { 78 final Point point = pointParam == null ? source.getClickPoint() : pointParam; 79 source.getEnvironment().getExecutor().execute(target.getEnvironment(), false, new Action() { 80 public void run(Object... parameters) { 81 if(source.is(Showable.class)) ((Showable)source.as(Showable.class)).shower().show(); 82 source.mouse().move(point); 83 source.mouse().press(button, modifiers); 84 source.getEnvironment().getTimeout(BEFORE_DRAG_TIMEOUT.getName()).sleep(); 85 Point intermediatePoint = new Point(); 86 int xDistance = target.getScreenBounds().x + targetPoint.x - source.getScreenBounds().x - point.x; 87 int yDistance = target.getScreenBounds().y + targetPoint.y - source.getScreenBounds().y - point.y; 88 int startX = point.x + source.getScreenBounds().x; 89 int startY = point.y + source.getScreenBounds().y; 90 int endX = startX + xDistance; 91 int endY = startY + yDistance; 92 for(int i = 0; i < DND_POINTS + 1; i++) { 93 intermediatePoint.x = startX + xDistance * i / DND_POINTS - source.getScreenBounds().x; 94 intermediatePoint.y = startY + yDistance * i / DND_POINTS - source.getScreenBounds().y; 95 source.mouse().move(intermediatePoint); 96 source.getEnvironment().getTimeout(IN_DRAG_TIMEOUT.getName()).sleep(); |