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: import java.awt.Scrollbar;
052:
053: import org.netbeans.jemmy.Timeout;
054:
055: import org.netbeans.jemmy.operators.ComponentOperator;
056: import org.netbeans.jemmy.operators.Operator;
057: import org.netbeans.jemmy.operators.ScrollbarOperator;
058:
059: /**
060: * ScrollDriver for java.awt.Scrollbar component type.
061: *
062: * @author Alexandre Iline(alexandre.iline@sun.com)
063: */
064: public class ScrollbarDriver extends AWTScrollDriver {
065: private static final int CLICK_OFFSET = 5;
066:
067: /**
068: * Constructs a ScrollbarDriver.
069: */
070: public ScrollbarDriver() {
071: super (
072: new String[] { "org.netbeans.jemmy.operators.ScrollbarOperator" });
073: }
074:
075: public void scrollToMinimum(final ComponentOperator oper,
076: final int orientation) {
077: scroll(oper, new ScrollAdjuster() {
078: public int getScrollDirection() {
079: return ((((ScrollbarOperator) oper).getMinimum() < ((ScrollbarOperator) oper)
080: .getValue()) ? DECREASE_SCROLL_DIRECTION
081: : DO_NOT_TOUCH_SCROLL_DIRECTION);
082: }
083:
084: public int getScrollOrientation() {
085: return (((ScrollbarOperator) oper).getOrientation());
086: }
087:
088: public String getDescription() {
089: return ("Scroll to minimum");
090: }
091: });
092: }
093:
094: public void scrollToMaximum(final ComponentOperator oper,
095: final int orientation) {
096: scroll(oper, new ScrollAdjuster() {
097: public int getScrollDirection() {
098: return (((((ScrollbarOperator) oper).getMaximum() - ((ScrollbarOperator) oper)
099: .getVisibleAmount()) > ((ScrollbarOperator) oper)
100: .getValue()) ? INCREASE_SCROLL_DIRECTION
101: : DO_NOT_TOUCH_SCROLL_DIRECTION);
102: }
103:
104: public int getScrollOrientation() {
105: return (((ScrollbarOperator) oper).getOrientation());
106: }
107:
108: public String getDescription() {
109: return ("Scroll to maximum");
110: }
111: });
112: }
113:
114: protected Point getClickPoint(ComponentOperator oper,
115: int direction, int orientation) {
116: int x, y;
117: if (orientation == Scrollbar.HORIZONTAL) {
118: if (direction == ScrollAdjuster.INCREASE_SCROLL_DIRECTION) {
119: x = oper.getWidth() - 1 - CLICK_OFFSET;
120: } else if (direction == ScrollAdjuster.DECREASE_SCROLL_DIRECTION) {
121: x = CLICK_OFFSET;
122: } else {
123: return (null);
124: }
125: y = oper.getHeight() / 2;
126: } else if (orientation == Scrollbar.VERTICAL) {
127: if (direction == ScrollAdjuster.INCREASE_SCROLL_DIRECTION) {
128: y = oper.getHeight() - 1 - CLICK_OFFSET;
129: } else if (direction == ScrollAdjuster.DECREASE_SCROLL_DIRECTION) {
130: y = CLICK_OFFSET;
131: } else {
132: return (null);
133: }
134: x = oper.getWidth() / 2;
135: } else {
136: return (null);
137: }
138: return (new Point(x, y));
139: }
140: }
|