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