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