001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s): Alexandre Iline.
025: *
026: * The Original Software is the Jemmy library.
027: * The Initial Developer of the Original Software is Alexandre Iline.
028: * All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: *
041: *
042: *
043: * $Id: MouseRobotDriver.java,v 1.7 2007/10/05 11:37:25 jskrivanek Exp $ $Revision: 1.7 $ $Date: 2007/10/05 11:37:25 $
044: *
045: */
046:
047: package org.netbeans.jemmy.drivers.input;
048:
049: import java.awt.Component;
050:
051: import java.awt.event.MouseEvent;
052:
053: import org.netbeans.jemmy.Timeout;
054:
055: import org.netbeans.jemmy.drivers.MouseDriver;
056:
057: import org.netbeans.jemmy.operators.ComponentOperator;
058: import org.netbeans.jemmy.operators.Operator;
059:
060: /**
061: * MouseDriver using robot operations.
062: *
063: * @author Alexandre Iline(alexandre.iline@sun.com)
064: */
065: public class MouseRobotDriver extends RobotDriver implements
066: MouseDriver {
067:
068: /**
069: * Constructs a MouseRobotDriver object.
070: * @param autoDelay Time for <code>Robot.setAutoDelay(long)</code> method.
071: */
072: public MouseRobotDriver(Timeout autoDelay) {
073: super (autoDelay);
074: }
075:
076: /**
077: * Constructs a MouseRobotDriver object.
078: * @param autoDelay Time for <code>Robot.setAutoDelay(long)</code> method.
079: * @param supported an array of supported class names
080: * @param smooth - whether to move mouse smooth from one ppoint to another.
081: */
082: public MouseRobotDriver(Timeout autoDelay, boolean smooth) {
083: super (autoDelay, smooth);
084: }
085:
086: /**
087: * Constructs a MouseRobotDriver object.
088: * @param autoDelay Time for <code>Robot.setAutoDelay(long)</code> method.
089: * @param supported an array of supported class names
090: */
091: public MouseRobotDriver(Timeout autoDelay, String[] supported) {
092: super (autoDelay, supported);
093: }
094:
095: /**
096: * Constructs a MouseRobotDriver object.
097: * @param autoDelay Time for <code>Robot.setAutoDelay(long)</code> method.
098: * @param supported an array of supported class names
099: * @param smooth - whether to move mouse smooth from one ppoint to another.
100: */
101: public MouseRobotDriver(Timeout autoDelay, String[] supported,
102: boolean smooth) {
103: super (autoDelay, supported, smooth);
104: }
105:
106: public void pressMouse(ComponentOperator oper, int x, int y,
107: int mouseButton, int modifiers) {
108: pressMouse(mouseButton, modifiers);
109: }
110:
111: public void releaseMouse(ComponentOperator oper, int x, int y,
112: int mouseButton, int modifiers) {
113: releaseMouse(mouseButton, modifiers);
114: }
115:
116: public void moveMouse(ComponentOperator oper, int x, int y) {
117: moveMouse(getAbsoluteX(oper, x), getAbsoluteY(oper, y));
118: }
119:
120: public void clickMouse(ComponentOperator oper, int x, int y,
121: int clickCount, int mouseButton, int modifiers,
122: Timeout mouseClick) {
123: clickMouse(getAbsoluteX(oper, x), getAbsoluteY(oper, y),
124: clickCount, mouseButton, modifiers, mouseClick);
125: }
126:
127: public void dragMouse(ComponentOperator oper, int x, int y,
128: int mouseButton, int modifiers) {
129: moveMouse(getAbsoluteX(oper, x), getAbsoluteY(oper, y));
130: }
131:
132: public void dragNDrop(ComponentOperator oper, int start_x,
133: int start_y, int end_x, int end_y, int mouseButton,
134: int modifiers, Timeout before, Timeout after) {
135: dragNDrop(getAbsoluteX(oper, start_x), getAbsoluteY(oper,
136: start_y), getAbsoluteX(oper, end_x), getAbsoluteY(oper,
137: end_y), mouseButton, modifiers, before, after);
138: }
139:
140: public void enterMouse(ComponentOperator oper) {
141: moveMouse(oper, oper.getCenterXForClick(), oper
142: .getCenterYForClick());
143: }
144:
145: public void exitMouse(ComponentOperator oper) {
146: //better not go anywhere
147: //exit will be executed during the next
148: //mouse move anyway.
149: // moveMouse(oper, -1, -1);
150: }
151:
152: /**
153: * Returns absolute x coordinate for relative x coordinate.
154: * @param oper an operator
155: * @param x a relative x coordinate.
156: * @return an absolute x coordinate.
157: */
158: protected int getAbsoluteX(ComponentOperator oper, int x) {
159: return (oper.getSource().getLocationOnScreen().x + x);
160: }
161:
162: /**
163: * Returns absolute y coordinate for relative y coordinate.
164: * @param oper an operator
165: * @param y a relative y coordinate.
166: * @return an absolute y coordinate.
167: */
168: protected int getAbsoluteY(ComponentOperator oper, int y) {
169: return (oper.getSource().getLocationOnScreen().y + y);
170: }
171: }
|