35 import org.jemmy.interfaces.Mouse; 36 import static org.jemmy.interfaces.Mouse.CLICK; 37 import org.jemmy.interfaces.Showable; 38 39 /** 40 * 41 * @author shura 42 */ 43 public class MouseImpl implements Mouse { 44 45 private Wrap<?> target; 46 private RobotDriver robotDriver; 47 private boolean detached = false; 48 49 static { 50 if (Environment.getEnvironment().getTimeout(CLICK) == null) { 51 Environment.getEnvironment().setTimeout(MouseImpl.CLICK); 52 } 53 } 54 55 /** 56 * 57 * @param target 58 */ 59 public MouseImpl(Wrap<?> target) { 60 this.target = target; 61 this.robotDriver = new RobotDriver(new Timeout("", 10)); 62 } 63 64 public Mouse detached() { 65 this.detached = true; 66 return this; 67 } 68 69 private void runAction(Action action) { 70 if (detached) { 71 target.getEnvironment().getExecutor().executeDetached(target.getEnvironment(), false, action); 72 } else { 73 target.getEnvironment().getExecutor().execute(target.getEnvironment(), false, action); 74 } 75 } 76 77 /** 78 * 79 */ 80 @Override 81 public void press() { 82 press(MouseButtons.BUTTON1); 83 } 84 85 /** 86 * 87 * @param button 88 */ 89 @Override 90 public void press(MouseButton button) { 91 press(button, new Modifier[]{}); 92 } 93 94 /** 95 * 96 * @param button 97 * @param modifiers 98 */ 99 @Override 100 public void press(final MouseButton button, final Modifier... modifiers) { 101 runAction(new Action() { 102 103 public void run(Object... parameters) { 104 robotDriver.pressMouse(button, modifiers); 105 } 106 107 @Override 108 public String toString() { 109 return "pressing mouse button " + button + " with " + modifiers + " modifiers"; 110 } 111 }); 112 } 113 114 /** 115 * 116 */ 117 public void release() { 118 release(MouseButtons.BUTTON1); 119 } 120 121 /** 122 * 123 * @param button 124 */ 125 @Override 126 public void release(MouseButton button) { 127 release(button, new Modifier[]{}); 128 } 129 130 /** 131 * 132 * @param button 133 * @param modifiers 134 */ 135 @Override 136 public void release(final MouseButton button, final Modifier... modifiers) { 137 runAction(new Action() { 138 139 public void run(Object... parameters) { 140 robotDriver.releaseMouse(button, modifiers); 141 } 142 143 @Override 144 public String toString() { 145 return "releasing mouse button " + button + " with " + modifiers + " modifiers"; 146 } 147 }); 148 } 149 150 /** 151 * 152 */ 153 public void move() { 154 move(target.getClickPoint()); 155 } 156 157 /** 158 * 159 * @param p 160 */ 161 public void move(final Point p) { 162 runAction(new Action() { 163 164 public void run(Object... parameters) { 165 robotDriver.moveMouse(getAbsolute(target, p)); 166 } 167 168 @Override 169 public String toString() { 170 return "moving mouse to " + p; 171 } 172 }); 173 } 174 175 /** 176 * 177 */ 178 public void click() { 179 this.click(1); 180 } 181 182 /** 183 * 184 * @param count 185 */ 186 public void click(int count) { 187 this.click(count, null); 188 } 189 190 /** 191 * 192 * @param count 193 * @param p Point to click, if null {@linkplain Wrap#getClickPoint() 194 * Wrap.getClickPoint()} method is invoked to get the point to click. 195 */ 196 public void click(int count, Point p) { 197 this.click(count, p, MouseButtons.BUTTON1); 198 } 199 200 /** 201 * 202 * @param count 203 * @param p Point to click, if null {@linkplain Wrap#getClickPoint() 204 * Wrap.getClickPoint()} method is invoked to get the point to click. 205 * @param button 206 */ 207 @Override 208 public void click(int count, Point p, MouseButton button) { 209 click(count, p, button, new Modifier[] {}); 210 } 211 212 /** 213 * 214 * @param count 215 * @param p Point to click, if null {@linkplain Wrap#getClickPoint() 216 * Wrap.getClickPoint()} method is invoked to get the point to click. 217 * @param button 218 * @param modifiers 219 */ 220 @Override 221 public void click(final int count, final Point p, final MouseButton button, final Modifier... modifiers) { 222 runAction(new Action() { 223 224 public void run(Object... parameters) { 225 if (target.is(Showable.class)) { 226 target.as(Showable.class).shower().show(); 227 } 228 robotDriver.clickMouse(getAbsolute(target, 229 p == null ? target.getClickPoint() : p), 230 count, button, target.getEnvironment().getTimeout(CLICK), modifiers); 231 } 232 233 @Override 234 public String toString() { 235 return "clicking " + button + " mouse button " + count + " times at " + p + " with " + Arrays.toString(modifiers) + " modifiers"; 236 } 237 }); 238 } | 35 import org.jemmy.interfaces.Mouse; 36 import static org.jemmy.interfaces.Mouse.CLICK; 37 import org.jemmy.interfaces.Showable; 38 39 /** 40 * 41 * @author shura 42 */ 43 public class MouseImpl implements Mouse { 44 45 private Wrap<?> target; 46 private RobotDriver robotDriver; 47 private boolean detached = false; 48 49 static { 50 if (Environment.getEnvironment().getTimeout(CLICK) == null) { 51 Environment.getEnvironment().setTimeout(MouseImpl.CLICK); 52 } 53 } 54 55 public MouseImpl(Wrap<?> target) { 56 this.target = target; 57 this.robotDriver = new RobotDriver(new Timeout("", 10)); 58 } 59 60 public Mouse detached() { 61 this.detached = true; 62 return this; 63 } 64 65 private void runAction(Action action) { 66 if (detached) { 67 target.getEnvironment().getExecutor().executeDetached(target.getEnvironment(), false, action); 68 } else { 69 target.getEnvironment().getExecutor().execute(target.getEnvironment(), false, action); 70 } 71 } 72 73 @Override 74 public void press() { 75 press(MouseButtons.BUTTON1); 76 } 77 78 @Override 79 public void press(MouseButton button) { 80 press(button, new Modifier[]{}); 81 } 82 83 @Override 84 public void press(final MouseButton button, final Modifier... modifiers) { 85 runAction(new Action() { 86 87 public void run(Object... parameters) { 88 robotDriver.pressMouse(button, modifiers); 89 } 90 91 @Override 92 public String toString() { 93 return "pressing mouse button " + button + " with " + modifiers + " modifiers"; 94 } 95 }); 96 } 97 98 public void release() { 99 release(MouseButtons.BUTTON1); 100 } 101 102 @Override 103 public void release(MouseButton button) { 104 release(button, new Modifier[]{}); 105 } 106 107 @Override 108 public void release(final MouseButton button, final Modifier... modifiers) { 109 runAction(new Action() { 110 111 public void run(Object... parameters) { 112 robotDriver.releaseMouse(button, modifiers); 113 } 114 115 @Override 116 public String toString() { 117 return "releasing mouse button " + button + " with " + modifiers + " modifiers"; 118 } 119 }); 120 } 121 122 public void move() { 123 move(target.getClickPoint()); 124 } 125 126 public void move(final Point p) { 127 runAction(new Action() { 128 129 public void run(Object... parameters) { 130 robotDriver.moveMouse(getAbsolute(target, p)); 131 } 132 133 @Override 134 public String toString() { 135 return "moving mouse to " + p; 136 } 137 }); 138 } 139 140 public void click() { 141 this.click(1); 142 } 143 144 public void click(int count) { 145 this.click(count, null); 146 } 147 148 /** 149 * @param count todo document 150 * @param p Point to click, if null {@linkplain Wrap#getClickPoint() 151 * Wrap.getClickPoint()} method is invoked to get the point to click. 152 */ 153 public void click(int count, Point p) { 154 this.click(count, p, MouseButtons.BUTTON1); 155 } 156 157 /** 158 * 159 * @param count todo document 160 * @param p Point to click, if null {@linkplain Wrap#getClickPoint() 161 * Wrap.getClickPoint()} method is invoked to get the point to click. 162 * @param button todo document 163 */ 164 @Override 165 public void click(int count, Point p, MouseButton button) { 166 click(count, p, button, new Modifier[] {}); 167 } 168 169 /** 170 * 171 * @param count todo document 172 * @param p Point to click, if null {@linkplain Wrap#getClickPoint() 173 * Wrap.getClickPoint()} method is invoked to get the point to click. 174 * @param button todo document 175 * @param modifiers todo document 176 */ 177 @Override 178 public void click(final int count, final Point p, final MouseButton button, final Modifier... modifiers) { 179 runAction(new Action() { 180 181 public void run(Object... parameters) { 182 if (target.is(Showable.class)) { 183 target.as(Showable.class).shower().show(); 184 } 185 robotDriver.clickMouse(getAbsolute(target, 186 p == null ? target.getClickPoint() : p), 187 count, button, target.getEnvironment().getTimeout(CLICK), modifiers); 188 } 189 190 @Override 191 public String toString() { 192 return "clicking " + button + " mouse button " + count + " times at " + p + " with " + Arrays.toString(modifiers) + " modifiers"; 193 } 194 }); 195 } |