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$ $Revision$ $Date$
044: *
045: */
046:
047: package org.netbeans.jemmy.drivers.scrolling;
048:
049: import java.awt.Adjustable;
050: import java.awt.Point;
051:
052: import org.netbeans.jemmy.QueueTool;
053: import org.netbeans.jemmy.Timeout;
054:
055: import org.netbeans.jemmy.drivers.DriverManager;
056: import org.netbeans.jemmy.drivers.MouseDriver;
057:
058: import org.netbeans.jemmy.operators.ComponentOperator;
059: import org.netbeans.jemmy.operators.Operator;
060:
061: /**
062: * ScrollDriver for awt components.
063: *
064: * @author Alexandre Iline(alexandre.iline@sun.com)
065: */
066: public abstract class AWTScrollDriver extends AbstractScrollDriver {
067: private QueueTool queueTool;
068:
069: /**
070: * Constructs a ChoiceDriver.
071: * @param supported an array of supported class names
072: */
073: public AWTScrollDriver(String[] supported) {
074: super (supported);
075: queueTool = new QueueTool();
076: }
077:
078: protected void step(final ComponentOperator oper,
079: final ScrollAdjuster adj) {
080: if (adj.getScrollDirection() != ScrollAdjuster.DO_NOT_TOUCH_SCROLL_DIRECTION) {
081: queueTool.invokeSmoothly(new QueueTool.QueueAction(
082: "Choise expanding") {
083: public Object launch() {
084: Point clickPoint = getClickPoint(oper, adj
085: .getScrollDirection(), adj
086: .getScrollOrientation());
087: if (clickPoint != null) {
088: DriverManager
089: .getMouseDriver(oper)
090: .clickMouse(
091: oper,
092: clickPoint.x,
093: clickPoint.y,
094: 1,
095: Operator
096: .getDefaultMouseButton(),
097: 0,
098: oper
099: .getTimeouts()
100: .create(
101: "ComponentOperator.MouseClickTimeout"));
102: }
103: return (null);
104: }
105: });
106: }
107: }
108:
109: protected void jump(ComponentOperator oper, ScrollAdjuster adj) {
110: }
111:
112: protected void startPushAndWait(final ComponentOperator oper,
113: final int direction, final int orientation) {
114: queueTool.invokeSmoothly(new QueueTool.QueueAction(
115: "Choise expanding") {
116: public Object launch() {
117: Point clickPoint = getClickPoint(oper, direction,
118: orientation);
119: if (clickPoint != null) {
120: MouseDriver mdriver = DriverManager
121: .getMouseDriver(oper);
122: mdriver.moveMouse(oper, clickPoint.x, clickPoint.y);
123: mdriver.pressMouse(oper, clickPoint.x,
124: clickPoint.y, Operator
125: .getDefaultMouseButton(), 0);
126: }
127: return (null);
128: }
129: });
130: }
131:
132: protected void stopPushAndWait(final ComponentOperator oper,
133: final int direction, final int orientation) {
134: queueTool.invokeSmoothly(new QueueTool.QueueAction(
135: "Choise expanding") {
136: public Object launch() {
137: Point clickPoint = getClickPoint(oper, direction,
138: orientation);
139: if (clickPoint != null) {
140: MouseDriver mdriver = DriverManager
141: .getMouseDriver(oper);
142: mdriver.releaseMouse(oper, clickPoint.x,
143: clickPoint.y, Operator
144: .getDefaultMouseButton(), 0);
145: }
146: return (null);
147: }
148: });
149: }
150:
151: protected Point startDragging(ComponentOperator oper) {
152: return (null);
153: }
154:
155: protected void drop(ComponentOperator oper, Point pnt) {
156: }
157:
158: protected void drag(ComponentOperator oper, Point pnt) {
159: }
160:
161: protected Timeout getScrollDeltaTimeout(ComponentOperator oper) {
162: return (oper.getTimeouts()
163: .create("ScrollbarOperator.DragAndDropScrollingDelta"));
164: }
165:
166: protected boolean canDragAndDrop(ComponentOperator oper) {
167: return (false);
168: }
169:
170: protected boolean canJump(ComponentOperator oper) {
171: return (false);
172: }
173:
174: protected boolean canPushAndWait(ComponentOperator oper) {
175: return (true);
176: }
177:
178: protected int getDragAndDropStepLength(ComponentOperator oper) {
179: return (1);
180: }
181:
182: /**
183: * Defines a click point which needs to be used in
184: * order to increase/decrease scroller value.
185: * @param oper an operator.
186: * @param direction - one of the ScrollAdjister.INCREASE_SCROLL_DIRECTION,
187: * ScrollAdjister.DECREASE_SCROLL_DIRECTION, ScrollAdjister.DO_NOT_TOUCH_SCROLL_DIRECTION values.
188: * @param orientation one of the Adjustable.HORIZONTAL or Adjustable.VERTICAL values.
189: * @return a point to click.
190: */
191: protected abstract Point getClickPoint(ComponentOperator oper,
192: int direction, int orientation);
193: }
|