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 javax.swing.JButton;
053: import javax.swing.JScrollBar;
054:
055: import org.netbeans.jemmy.ComponentSearcher;
056: import org.netbeans.jemmy.QueueTool;
057: import org.netbeans.jemmy.Timeout;
058:
059: import org.netbeans.jemmy.drivers.DriverManager;
060: import org.netbeans.jemmy.drivers.MouseDriver;
061:
062: import org.netbeans.jemmy.operators.ComponentOperator;
063: import org.netbeans.jemmy.operators.JButtonOperator;
064: import org.netbeans.jemmy.operators.JScrollBarOperator;
065: import org.netbeans.jemmy.operators.Operator;
066:
067: /**
068: * ScrollDriver for javax.swing.JScrollBar component type.
069: *
070: * @author Alexandre Iline(alexandre.iline@sun.com)
071: */
072: public class JScrollBarAPIDriver extends AbstractScrollDriver {
073: private final static int SMALL_INCREMENT = 1;
074: private final static int MINIMAL_DRAGGER_SIZE = 5;
075: private final static int RELATIVE_DRAG_STEP_LENGTH = 20;
076:
077: private QueueTool queueTool;
078:
079: /**
080: * Constructs a JScrollBarDriver.
081: */
082: public JScrollBarAPIDriver() {
083: super (
084: new String[] { "org.netbeans.jemmy.operators.JScrollBarOperator" });
085: queueTool = new QueueTool();
086: }
087:
088: public void scrollToMinimum(ComponentOperator oper, int orientation) {
089: JScrollBarOperator scroll = (JScrollBarOperator) oper;
090: setValue(oper, scroll.getMinimum());
091: }
092:
093: public void scrollToMaximum(ComponentOperator oper, int orientation) {
094: JScrollBarOperator scroll = (JScrollBarOperator) oper;
095: setValue(oper, scroll.getMaximum() - scroll.getVisibleAmount());
096: }
097:
098: protected void step(ComponentOperator oper, ScrollAdjuster adj) {
099: JScrollBarOperator scroll = (JScrollBarOperator) oper;
100: int newValue = -1;
101: if (adj.getScrollDirection() == adj.DECREASE_SCROLL_DIRECTION) {
102: newValue = (scroll.getValue() > scroll.getMinimum()
103: + scroll.getUnitIncrement()) ? scroll.getValue()
104: - scroll.getUnitIncrement() : scroll.getMinimum();
105: } else if (adj.getScrollDirection() == adj.INCREASE_SCROLL_DIRECTION) {
106: newValue = (scroll.getValue() < scroll.getMaximum()
107: - scroll.getVisibleAmount()
108: - scroll.getUnitIncrement()) ? scroll.getValue()
109: + scroll.getUnitIncrement() : scroll.getMaximum();
110: }
111: setValue(oper, newValue);
112: }
113:
114: private void setValue(ComponentOperator oper, int value) {
115: if (value != -1) {
116: ((JScrollBarOperator) oper).setValue(value);
117: }
118: }
119:
120: protected Timeout getScrollDeltaTimeout(ComponentOperator oper) {
121: return (oper.getTimeouts()
122: .create("JScrollBarOperator.DragAndDropScrollingDelta"));
123: }
124:
125: protected void jump(final ComponentOperator oper,
126: final ScrollAdjuster adj) {
127: JScrollBarOperator scroll = (JScrollBarOperator) oper;
128: int newValue = -1;
129: if (adj.getScrollDirection() == adj.DECREASE_SCROLL_DIRECTION) {
130: newValue = (scroll.getValue() > scroll.getMinimum()
131: + scroll.getBlockIncrement()) ? scroll.getValue()
132: - scroll.getBlockIncrement() : scroll.getMinimum();
133: } else if (adj.getScrollDirection() == adj.INCREASE_SCROLL_DIRECTION) {
134: newValue = (scroll.getValue() < scroll.getMaximum()
135: - scroll.getVisibleAmount()
136: - scroll.getBlockIncrement()) ? scroll.getValue()
137: + scroll.getBlockIncrement() : scroll.getMaximum();
138: }
139: setValue(oper, newValue);
140: }
141:
142: protected void startPushAndWait(ComponentOperator oper,
143: int direction, int orientation) {
144: }
145:
146: protected void stopPushAndWait(ComponentOperator oper,
147: int direction, int orientation) {
148: }
149:
150: protected Point startDragging(ComponentOperator oper) {
151: return (null);
152: }
153:
154: protected void drop(ComponentOperator oper, Point pnt) {
155: }
156:
157: protected void drag(ComponentOperator oper, Point pnt) {
158: }
159:
160: protected boolean canDragAndDrop(ComponentOperator oper) {
161: return (false);
162: }
163:
164: protected boolean canJump(ComponentOperator oper) {
165: return (isSmallIncrement((JScrollBarOperator) oper));
166: }
167:
168: protected boolean canPushAndWait(ComponentOperator oper) {
169: return (false);
170: }
171:
172: protected int getDragAndDropStepLength(ComponentOperator oper) {
173: return (1);
174: }
175:
176: private boolean isSmallIncrement(JScrollBarOperator oper) {
177: return (oper.getUnitIncrement(-1) <= SMALL_INCREMENT && oper
178: .getUnitIncrement(1) <= SMALL_INCREMENT);
179: }
180:
181: }
|