1/* 2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23package org.netbeans.jemmy.drivers.input; 24 25import org.netbeans.jemmy.Timeout; 26import org.netbeans.jemmy.drivers.MouseDriver; 27import org.netbeans.jemmy.operators.ComponentOperator; 28 29/** 30 * MouseDriver using robot operations. 31 * 32 * @author Alexandre Iline(alexandre.iline@oracle.com) 33 */ 34public class MouseRobotDriver extends RobotDriver implements MouseDriver { 35 36 /** 37 * Constructs a MouseRobotDriver object. 38 * 39 * @param autoDelay Time for {@code Robot.setAutoDelay(long)} method. 40 */ 41 public MouseRobotDriver(Timeout autoDelay) { 42 super(autoDelay); 43 } 44 45 /** 46 * Constructs a MouseRobotDriver object. 47 * 48 * @param autoDelay Time for {@code Robot.setAutoDelay(long)} method. 49 * @param smooth - whether to move mouse smooth from one ppoint to another. 50 */ 51 public MouseRobotDriver(Timeout autoDelay, boolean smooth) { 52 super(autoDelay, smooth); 53 } 54 55 /** 56 * Constructs a MouseRobotDriver object. 57 * 58 * @param autoDelay Time for {@code Robot.setAutoDelay(long)} method. 59 * @param supported an array of supported class names 60 */ 61 public MouseRobotDriver(Timeout autoDelay, String[] supported) { 62 super(autoDelay, supported); 63 } 64 65 /** 66 * Constructs a MouseRobotDriver object. 67 * 68 * @param autoDelay Time for {@code Robot.setAutoDelay(long)} method. 69 * @param supported an array of supported class names 70 * @param smooth - whether to move mouse smooth from one ppoint to another. 71 */ 72 public MouseRobotDriver(Timeout autoDelay, String[] supported, boolean smooth) { 73 super(autoDelay, supported, smooth); 74 } 75 76 @Override 77 public void pressMouse(ComponentOperator oper, int x, int y, int mouseButton, int modifiers) { 78 pressMouse(mouseButton, modifiers); 79 } 80 81 @Override 82 public void releaseMouse(ComponentOperator oper, int x, int y, int mouseButton, int modifiers) { 83 releaseMouse(mouseButton, modifiers); 84 } 85 86 @Override 87 public void moveMouse(ComponentOperator oper, int x, int y) { 88 moveMouse(getAbsoluteX(oper, x), getAbsoluteY(oper, y)); 89 } 90 91 @Override 92 public void clickMouse(ComponentOperator oper, int x, int y, int clickCount, int mouseButton, 93 int modifiers, Timeout mouseClick) { 94 clickMouse(getAbsoluteX(oper, x), getAbsoluteY(oper, y), clickCount, mouseButton, modifiers, mouseClick); 95 } 96 97 @Override 98 public void dragMouse(ComponentOperator oper, int x, int y, int mouseButton, int modifiers) { 99 moveMouse(getAbsoluteX(oper, x), getAbsoluteY(oper, y)); 100 } 101 102 @Override 103 public void dragNDrop(ComponentOperator oper, int start_x, int start_y, int end_x, int end_y, 104 int mouseButton, int modifiers, Timeout before, Timeout after) { 105 dragNDrop(getAbsoluteX(oper, start_x), getAbsoluteY(oper, start_y), getAbsoluteX(oper, end_x), getAbsoluteY(oper, end_y), mouseButton, modifiers, before, after); 106 } 107 108 @Override 109 public void enterMouse(ComponentOperator oper) { 110 moveMouse(oper, oper.getCenterXForClick(), oper.getCenterYForClick()); 111 } 112 113 @Override 114 public void exitMouse(ComponentOperator oper) { 115 //better not go anywhere 116 //exit will be executed during the next 117 //mouse move anyway. 118 // moveMouse(oper, -1, -1); 119 } 120 121 /** 122 * Returns absolute x coordinate for relative x coordinate. 123 * 124 * @param oper an operator 125 * @param x a relative x coordinate. 126 * @return an absolute x coordinate. 127 */ 128 protected int getAbsoluteX(ComponentOperator oper, int x) { 129 return oper.getSource().getLocationOnScreen().x + x; 130 } 131 132 /** 133 * Returns absolute y coordinate for relative y coordinate. 134 * 135 * @param oper an operator 136 * @param y a relative y coordinate. 137 * @return an absolute y coordinate. 138 */ 139 protected int getAbsoluteY(ComponentOperator oper, int y) { 140 return oper.getSource().getLocationOnScreen().y + y; 141 } 142} 143