0001: /*
0002:
0003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0004: *
0005: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0006: *
0007: * The contents of this file are subject to the terms of either the GNU
0008: * General Public License Version 2 only ("GPL") or the Common
0009: * Development and Distribution License("CDDL") (collectively, the
0010: * "License"). You may not use this file except in compliance with the
0011: * License. You can obtain a copy of the License at
0012: * http://www.netbeans.org/cddl-gplv2.html
0013: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0014: * specific language governing permissions and limitations under the
0015: * License. When distributing the software, include this License Header
0016: * Notice in each file and include the License file at
0017: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
0018: * particular file as subject to the "Classpath" exception as provided
0019: * by Sun in the GPL Version 2 section of the License file that
0020: * accompanied this code. If applicable, add the following below the
0021: * License Header, with the fields enclosed by brackets [] replaced by
0022: * your own identifying information:
0023: * "Portions Copyrighted [year] [name of copyright owner]"
0024: *
0025: * Contributor(s): Alexandre Iline.
0026:
0027: *
0028:
0029: * The Original Software is the Jemmy library.
0030:
0031: * The Initial Developer of the Original Software is Alexandre Iline.
0032:
0033: * All Rights Reserved.
0034: *
0035: * If you wish your version of this file to be governed by only the CDDL
0036: * or only the GPL Version 2, indicate your decision by adding
0037: * "[Contributor] elects to include this software in this distribution
0038: * under the [CDDL or GPL Version 2] license." If you do not indicate a
0039: * single choice of license, a recipient has the option to distribute
0040: * your version of this file under either the CDDL, the GPL Version 2 or
0041: * to extend the choice of license to its licensees as provided above.
0042: * However, if you add GPL Version 2 code and therefore, elected the GPL
0043: * Version 2 license, then the option applies only if the new code is
0044: * made subject to such option by the copyright holder.
0045:
0046: *
0047:
0048: *
0049:
0050: *
0051:
0052: * $Id$ $Revision$ $Date$
0053:
0054: *
0055:
0056: */
0057:
0058: package org.netbeans.jemmy.operators;
0059:
0060: import org.netbeans.jemmy.Action;
0061:
0062: import org.netbeans.jemmy.ComponentSearcher;
0063:
0064: import org.netbeans.jemmy.ComponentChooser;
0065:
0066: import org.netbeans.jemmy.JemmyException;
0067:
0068: import org.netbeans.jemmy.JemmyProperties;
0069:
0070: import org.netbeans.jemmy.Outputable;
0071:
0072: import org.netbeans.jemmy.TestOut;
0073:
0074: import org.netbeans.jemmy.Timeoutable;
0075:
0076: import org.netbeans.jemmy.TimeoutExpiredException;
0077:
0078: import org.netbeans.jemmy.Timeouts;
0079:
0080: import org.netbeans.jemmy.drivers.DriverManager;
0081:
0082: import org.netbeans.jemmy.drivers.ScrollDriver;
0083:
0084: import org.netbeans.jemmy.drivers.scrolling.ScrollAdjuster;
0085:
0086: import java.awt.Adjustable;
0087:
0088: import java.awt.Component;
0089:
0090: import java.awt.Container;
0091:
0092: import java.awt.Dimension;
0093:
0094: import java.awt.Point;
0095:
0096: import java.awt.Rectangle;
0097:
0098: import java.awt.ScrollPane;
0099:
0100: import javax.swing.SwingUtilities;
0101:
0102: /**
0103:
0104: * <BR><BR>Timeouts used: <BR>
0105:
0106: * ScrollbarOperator.WholeScrollTimeout - time for one scroll click <BR>
0107:
0108: * ComponentOperator.WaitComponentTimeout - time to wait component displayed <BR>.
0109:
0110: *
0111:
0112: * @see org.netbeans.jemmy.Timeouts
0113:
0114: *
0115:
0116: * @author Alexandre Iline (alexandre.iline@sun.com)
0117:
0118: *
0119:
0120: */
0121:
0122: public class ScrollPaneOperator extends ContainerOperator
0123:
0124: implements Timeoutable, Outputable {
0125:
0126: private static int X_POINT_RECT_SIZE = 6;
0127:
0128: private static int Y_POINT_RECT_SIZE = 4;
0129:
0130: private Timeouts timeouts;
0131:
0132: private TestOut output;
0133:
0134: private ScrollDriver driver;
0135:
0136: /**
0137:
0138: * Constructor.
0139:
0140: * @param b The <code>java.awt.ScrollPane</code> managed by
0141:
0142: * this instance.
0143:
0144: */
0145:
0146: public ScrollPaneOperator(ScrollPane b) {
0147:
0148: super (b);
0149:
0150: driver = DriverManager.getScrollDriver(getClass());
0151:
0152: }
0153:
0154: /**
0155:
0156: * Constructs a ScrollPaneOperator object.
0157:
0158: * @param cont a container
0159:
0160: * @param chooser a component chooser specifying searching criteria.
0161:
0162: * @param index an index between appropriate ones.
0163:
0164: */
0165:
0166: public ScrollPaneOperator(ContainerOperator cont,
0167: ComponentChooser chooser, int index) {
0168:
0169: this ((ScrollPane) cont.
0170:
0171: waitSubComponent(new ScrollPaneFinder(chooser),
0172:
0173: index));
0174:
0175: copyEnvironment(cont);
0176:
0177: }
0178:
0179: /**
0180:
0181: * Constructs a ScrollPaneOperator object.
0182:
0183: * @param cont a container
0184:
0185: * @param chooser a component chooser specifying searching criteria.
0186:
0187: */
0188:
0189: public ScrollPaneOperator(ContainerOperator cont,
0190: ComponentChooser chooser) {
0191:
0192: this (cont, chooser, 0);
0193:
0194: }
0195:
0196: /**
0197:
0198: * Constructor.
0199:
0200: * Waits component in container first.
0201:
0202: * Uses cont's timeout and output for waiting and to init operator.
0203:
0204: * @param cont Operator pointing a container to search component in.
0205:
0206: * @param index Ordinal component index.
0207:
0208: * @throws TimeoutExpiredException
0209:
0210: */
0211:
0212: public ScrollPaneOperator(ContainerOperator cont, int index) {
0213:
0214: this ((ScrollPane) waitComponent(cont,
0215:
0216: new ScrollPaneFinder(),
0217:
0218: index));
0219:
0220: copyEnvironment(cont);
0221:
0222: }
0223:
0224: /**
0225:
0226: * Constructor.
0227:
0228: * Waits component in container first.
0229:
0230: * Uses cont's timeout and output for waiting and to init operator.
0231:
0232: * @param cont Operator pointing a container to search component in.
0233:
0234: * @throws TimeoutExpiredException
0235:
0236: */
0237:
0238: public ScrollPaneOperator(ContainerOperator cont) {
0239:
0240: this (cont, 0);
0241:
0242: }
0243:
0244: /**
0245:
0246: * Searches ScrollPane in container.
0247:
0248: * @param cont Container to search component in.
0249:
0250: * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
0251:
0252: * @param index Ordinal component index.
0253:
0254: * @return ScrollPane instance or null if component was not found.
0255:
0256: */
0257:
0258: public static ScrollPane findScrollPane(Container cont,
0259: ComponentChooser chooser, int index) {
0260:
0261: return ((ScrollPane) findComponent(cont, new ScrollPaneFinder(
0262: chooser), index));
0263:
0264: }
0265:
0266: /**
0267:
0268: * Searches 0'th ScrollPane in container.
0269:
0270: * @param cont Container to search component in.
0271:
0272: * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
0273:
0274: * @return ScrollPane instance or null if component was not found.
0275:
0276: */
0277:
0278: public static ScrollPane findScrollPane(Container cont,
0279: ComponentChooser chooser) {
0280:
0281: return (findScrollPane(cont, chooser, 0));
0282:
0283: }
0284:
0285: /**
0286:
0287: * Searches ScrollPane in container.
0288:
0289: * @param cont Container to search component in.
0290:
0291: * @param index Ordinal component index.
0292:
0293: * @return ScrollPane instance or null if component was not found.
0294:
0295: */
0296:
0297: public static ScrollPane findScrollPane(Container cont, int index) {
0298:
0299: return (findScrollPane(cont, ComponentSearcher
0300: .getTrueChooser(Integer.toString(index)
0301: + "'th ScrollPane instance"), index));
0302:
0303: }
0304:
0305: /**
0306:
0307: * Searches 0'th ScrollPane in container.
0308:
0309: * @param cont Container to search component in.
0310:
0311: * @return ScrollPane instance or null if component was not found.
0312:
0313: */
0314:
0315: public static ScrollPane findScrollPane(Container cont) {
0316:
0317: return (findScrollPane(cont, 0));
0318:
0319: }
0320:
0321: /**
0322:
0323: * Searches ScrollPane object which component lies on.
0324:
0325: * @param comp Component to find ScrollPane under.
0326:
0327: * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
0328:
0329: * @return ScrollPane instance or null if component was not found.
0330:
0331: */
0332:
0333: public static ScrollPane findScrollPaneUnder(Component comp,
0334: ComponentChooser chooser) {
0335:
0336: return ((ScrollPane) findContainerUnder(comp,
0337: new ScrollPaneFinder(chooser)));
0338:
0339: }
0340:
0341: /**
0342:
0343: * Searches ScrollPane object which component lies on.
0344:
0345: * @param comp Component to find ScrollPane under.
0346:
0347: * @return ScrollPane instance or null if component was not found.
0348:
0349: */
0350:
0351: public static ScrollPane findScrollPaneUnder(Component comp) {
0352:
0353: return (findScrollPaneUnder(comp, new ScrollPaneFinder()));
0354:
0355: }
0356:
0357: /**
0358:
0359: * Waits ScrollPane in container.
0360:
0361: * @param cont Container to search component in.
0362:
0363: * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
0364:
0365: * @param index Ordinal component index.
0366:
0367: * @return ScrollPane instance or null if component was not displayed.
0368:
0369: * @throws TimeoutExpiredException
0370:
0371: */
0372:
0373: public static ScrollPane waitScrollPane(Container cont,
0374: ComponentChooser chooser, int index) {
0375:
0376: return ((ScrollPane) waitComponent(cont, new ScrollPaneFinder(
0377: chooser), index));
0378:
0379: }
0380:
0381: /**
0382:
0383: * Waits 0'th ScrollPane in container.
0384:
0385: * @param cont Container to search component in.
0386:
0387: * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
0388:
0389: * @return ScrollPane instance or null if component was not displayed.
0390:
0391: * @throws TimeoutExpiredException
0392:
0393: */
0394:
0395: public static ScrollPane waitScrollPane(Container cont,
0396: ComponentChooser chooser) {
0397:
0398: return (waitScrollPane(cont, chooser, 0));
0399:
0400: }
0401:
0402: /**
0403:
0404: * Waits ScrollPane in container.
0405:
0406: * @param cont Container to search component in.
0407:
0408: * @param index Ordinal component index.
0409:
0410: * @return ScrollPane instance or null if component was not displayed.
0411:
0412: * @throws TimeoutExpiredException
0413:
0414: */
0415:
0416: public static ScrollPane waitScrollPane(Container cont, int index) {
0417:
0418: return (waitScrollPane(cont, ComponentSearcher
0419: .getTrueChooser(Integer.toString(index)
0420: + "'th ScrollPane instance"), index));
0421:
0422: }
0423:
0424: /**
0425:
0426: * Waits 0'th ScrollPane in container.
0427:
0428: * @param cont Container to search component in.
0429:
0430: * @return ScrollPane instance or null if component was not displayed.
0431:
0432: * @throws TimeoutExpiredException
0433:
0434: */
0435:
0436: public static ScrollPane waitScrollPane(Container cont) {
0437:
0438: return (waitScrollPane(cont, 0));
0439:
0440: }
0441:
0442: static {
0443:
0444: try {
0445:
0446: Class
0447: .forName("org.netbeans.jemmy.operators.ScrollbarOperator");
0448:
0449: } catch (Exception e) {
0450:
0451: throw (new JemmyException("Exception", e));
0452:
0453: }
0454:
0455: }
0456:
0457: public void setTimeouts(Timeouts timeouts) {
0458:
0459: super .setTimeouts(timeouts);
0460:
0461: this .timeouts = timeouts;
0462:
0463: }
0464:
0465: public Timeouts getTimeouts() {
0466:
0467: return (timeouts);
0468:
0469: }
0470:
0471: public void setOutput(TestOut out) {
0472:
0473: output = out;
0474:
0475: super .setOutput(output.createErrorOutput());
0476:
0477: }
0478:
0479: public TestOut getOutput() {
0480:
0481: return (output);
0482:
0483: }
0484:
0485: public void copyEnvironment(Operator anotherOperator) {
0486:
0487: super .copyEnvironment(anotherOperator);
0488:
0489: driver =
0490:
0491: (ScrollDriver) DriverManager.
0492:
0493: getDriver(DriverManager.SCROLL_DRIVER_ID,
0494:
0495: getClass(),
0496:
0497: anotherOperator.getProperties());
0498:
0499: }
0500:
0501: /**
0502:
0503: * Sets both values.
0504:
0505: * @param x a horizontal value.
0506:
0507: * @param y a vertical value.
0508:
0509: */
0510:
0511: public void setValues(int x, int y) {
0512:
0513: getHAdjustable().setValue(x);
0514:
0515: getVAdjustable().setValue(y);
0516:
0517: }
0518:
0519: /**
0520:
0521: * Scrools to the position defined by a ScrollAdjuster instance.
0522:
0523: * @param adj specifies the position.
0524:
0525: */
0526:
0527: public void scrollTo(final ScrollAdjuster adj) {
0528:
0529: produceTimeRestricted(new Action() {
0530:
0531: public Object launch(Object obj) {
0532:
0533: driver.scroll(ScrollPaneOperator.this , adj);
0534:
0535: return (null);
0536:
0537: }
0538:
0539: public String getDescription() {
0540:
0541: return ("Scrolling");
0542:
0543: }
0544:
0545: }, getTimeouts().getTimeout(
0546: "ScrollbarOperator.WholeScrollTimeout"));
0547:
0548: }
0549:
0550: /**
0551:
0552: * Scrolls horizontal scroll bar.
0553:
0554: * @param value Value to scroll horizontal scroll bar to.
0555:
0556: * @throws TimeoutExpiredException
0557:
0558: */
0559:
0560: public void scrollToHorizontalValue(final int value) {
0561:
0562: output.printTrace("Scroll ScrollPane to "
0563: + Integer.toString(value) + " horizontal value \n" +
0564:
0565: toStringSource());
0566:
0567: output.printGolden("Scroll ScrollPane to "
0568: + Integer.toString(value) + " horizontal value");
0569:
0570: scrollTo(new ValueScrollAdjuster(value,
0571:
0572: Adjustable.HORIZONTAL,
0573:
0574: getHAdjustable()));
0575:
0576: }
0577:
0578: /**
0579:
0580: * Scrolls horizontal scroll bar.
0581:
0582: * @param proportionalValue Proportional value to scroll horizontal scroll bar to.
0583:
0584: * @throws TimeoutExpiredException
0585:
0586: */
0587:
0588: public void scrollToHorizontalValue(double proportionalValue) {
0589:
0590: output.printTrace("Scroll ScrollPane to "
0591: + Double.toString(proportionalValue)
0592: + " proportional horizontal value \n" +
0593:
0594: toStringSource());
0595:
0596: output.printGolden("Scroll ScrollPane to "
0597: + Double.toString(proportionalValue)
0598: + " proportional horizontal value");
0599:
0600: Adjustable adj = getHAdjustable();
0601:
0602: scrollTo(new ValueScrollAdjuster((int) (adj.getMinimum() +
0603:
0604: (adj.getMaximum() -
0605:
0606: adj.getVisibleAmount() -
0607:
0608: adj.getMinimum()) * proportionalValue),
0609:
0610: Adjustable.VERTICAL,
0611:
0612: getVAdjustable()));
0613:
0614: }
0615:
0616: /**
0617:
0618: * Scrolls vertical scroll bar.
0619:
0620: * @param value Value to scroll vertical scroll bar to.
0621:
0622: * @throws TimeoutExpiredException
0623:
0624: */
0625:
0626: public void scrollToVerticalValue(final int value) {
0627:
0628: output.printTrace("Scroll ScrollPane to "
0629: + Integer.toString(value) + " vertical value \n" +
0630:
0631: toStringSource());
0632:
0633: output.printGolden("Scroll ScrollPane to "
0634: + Integer.toString(value) + " vertical value");
0635:
0636: scrollTo(new ValueScrollAdjuster(value,
0637:
0638: Adjustable.VERTICAL,
0639:
0640: getVAdjustable()));
0641:
0642: }
0643:
0644: /**
0645:
0646: * Scrolls vertical scroll bar.
0647:
0648: * @param proportionalValue Value to scroll vertical scroll bar to.
0649:
0650: * @throws TimeoutExpiredException
0651:
0652: */
0653:
0654: public void scrollToVerticalValue(double proportionalValue) {
0655:
0656: output.printTrace("Scroll ScrollPane to "
0657: + Double.toString(proportionalValue)
0658: + " proportional vertical value \n" +
0659:
0660: toStringSource());
0661:
0662: output.printGolden("Scroll ScrollPane to "
0663: + Double.toString(proportionalValue)
0664: + " proportional vertical value");
0665:
0666: Adjustable adj = getVAdjustable();
0667:
0668: scrollTo(new ValueScrollAdjuster((int) (adj.getMinimum() +
0669:
0670: (adj.getMaximum() -
0671:
0672: adj.getVisibleAmount() -
0673:
0674: adj.getMinimum()) * proportionalValue),
0675:
0676: Adjustable.VERTICAL,
0677:
0678: getVAdjustable()));
0679:
0680: }
0681:
0682: /**
0683:
0684: * Scrolls both scroll bars.
0685:
0686: * @param valueX Value to scroll horizontal scroll bar to.
0687:
0688: * @param valueY Value to scroll vertical scroll bar to.
0689:
0690: * @throws TimeoutExpiredException
0691:
0692: */
0693:
0694: public void scrollToValues(int valueX, int valueY) {
0695:
0696: scrollToVerticalValue(valueX);
0697:
0698: scrollToHorizontalValue(valueX);
0699:
0700: }
0701:
0702: /**
0703:
0704: * Scrolls both scroll bars.
0705:
0706: * @param proportionalValueX Value to scroll horizontal scroll bar to.
0707:
0708: * @param proportionalValueY Value to scroll vertical scroll bar to.
0709:
0710: * @throws TimeoutExpiredException
0711:
0712: */
0713:
0714: public void scrollToValues(double proportionalValueX,
0715: double proportionalValueY) {
0716:
0717: scrollToVerticalValue(proportionalValueX);
0718:
0719: scrollToHorizontalValue(proportionalValueY);
0720:
0721: }
0722:
0723: /**
0724:
0725: * Scrolls pane to top.
0726:
0727: * @throws TimeoutExpiredException
0728:
0729: */
0730:
0731: public void scrollToTop() {
0732:
0733: output.printTrace("Scroll ScrollPane to top\n" +
0734:
0735: toStringSource());
0736:
0737: output.printGolden("Scroll ScrollPane to top");
0738:
0739: produceTimeRestricted(new Action() {
0740:
0741: public Object launch(Object obj) {
0742:
0743: driver.scrollToMinimum(ScrollPaneOperator.this ,
0744: Adjustable.VERTICAL);
0745:
0746: return (null);
0747:
0748: }
0749:
0750: public String getDescription() {
0751:
0752: return ("Scrolling");
0753:
0754: }
0755:
0756: }, getTimeouts().getTimeout(
0757: "ScrollbarOperator.WholeScrollTimeout"));
0758:
0759: }
0760:
0761: /**
0762:
0763: * Scrolls pane to bottom.
0764:
0765: * @throws TimeoutExpiredException
0766:
0767: */
0768:
0769: public void scrollToBottom() {
0770:
0771: output.printTrace("Scroll ScrollPane to bottom\n" +
0772:
0773: toStringSource());
0774:
0775: output.printGolden("Scroll ScrollPane to bottom");
0776:
0777: produceTimeRestricted(new Action() {
0778:
0779: public Object launch(Object obj) {
0780:
0781: driver.scrollToMaximum(ScrollPaneOperator.this ,
0782: Adjustable.VERTICAL);
0783:
0784: return (null);
0785:
0786: }
0787:
0788: public String getDescription() {
0789:
0790: return ("Scrolling");
0791:
0792: }
0793:
0794: }, getTimeouts().getTimeout(
0795: "ScrollbarOperator.WholeScrollTimeout"));
0796:
0797: }
0798:
0799: /**
0800:
0801: * Scrolls pane to left.
0802:
0803: * @throws TimeoutExpiredException
0804:
0805: */
0806:
0807: public void scrollToLeft() {
0808:
0809: output.printTrace("Scroll ScrollPane to left\n" +
0810:
0811: toStringSource());
0812:
0813: output.printGolden("Scroll ScrollPane to left");
0814:
0815: produceTimeRestricted(new Action() {
0816:
0817: public Object launch(Object obj) {
0818:
0819: driver.scrollToMinimum(ScrollPaneOperator.this ,
0820: Adjustable.HORIZONTAL);
0821:
0822: return (null);
0823:
0824: }
0825:
0826: public String getDescription() {
0827:
0828: return ("Scrolling");
0829:
0830: }
0831:
0832: }, getTimeouts().getTimeout(
0833: "ScrollbarOperator.WholeScrollTimeout"));
0834:
0835: }
0836:
0837: /**
0838:
0839: * Scrolls pane to right.
0840:
0841: * @throws TimeoutExpiredException
0842:
0843: */
0844:
0845: public void scrollToRight() {
0846:
0847: output.printTrace("Scroll ScrollPane to right\n" +
0848:
0849: toStringSource());
0850:
0851: output.printGolden("Scroll ScrollPane to right");
0852:
0853: produceTimeRestricted(new Action() {
0854:
0855: public Object launch(Object obj) {
0856:
0857: driver.scrollToMaximum(ScrollPaneOperator.this ,
0858: Adjustable.HORIZONTAL);
0859:
0860: return (null);
0861:
0862: }
0863:
0864: public String getDescription() {
0865:
0866: return ("Scrolling");
0867:
0868: }
0869:
0870: }, getTimeouts().getTimeout(
0871: "ScrollbarOperator.WholeScrollTimeout"));
0872:
0873: }
0874:
0875: /**
0876:
0877: * Scrolls pane to rectangle..
0878:
0879: * @param comp a subcomponent defining coordinate system.
0880:
0881: * @param x coordinate
0882:
0883: * @param y coordinate
0884:
0885: * @param width rectangle width
0886:
0887: * @param height rectangle height
0888:
0889: * @throws TimeoutExpiredException
0890:
0891: */
0892:
0893: public void scrollToComponentRectangle(Component comp, int x,
0894: int y, int width, int height) {
0895:
0896: scrollTo(new ComponentRectChecker(comp, x, y, width, height,
0897: Adjustable.HORIZONTAL));
0898:
0899: scrollTo(new ComponentRectChecker(comp, x, y, width, height,
0900: Adjustable.VERTICAL));
0901:
0902: }
0903:
0904: /**
0905:
0906: * Scrolls pane to point.
0907:
0908: * @param comp a subcomponent defining coordinate system.
0909:
0910: * @param x coordinate
0911:
0912: * @param y coordinate
0913:
0914: * @throws TimeoutExpiredException
0915:
0916: */
0917:
0918: public void scrollToComponentPoint(Component comp, int x, int y) {
0919:
0920: scrollToComponentRectangle(comp,
0921:
0922: x - X_POINT_RECT_SIZE,
0923:
0924: y - Y_POINT_RECT_SIZE,
0925:
0926: 2 * X_POINT_RECT_SIZE,
0927:
0928: 2 * Y_POINT_RECT_SIZE);
0929:
0930: }
0931:
0932: /**
0933:
0934: * Scrolls pane to component on this pane.
0935:
0936: * Component should lay on the ScrollPane view.
0937:
0938: * @param comp Component to scroll to.
0939:
0940: * @throws TimeoutExpiredException
0941:
0942: */
0943:
0944: public void scrollToComponent(final Component comp) {
0945:
0946: String componentToString = (String) runMapping(
0947:
0948: new Operator.MapAction("comp.toString()") {
0949:
0950: public Object map() {
0951:
0952: return comp.toString();
0953:
0954: }
0955:
0956: }
0957:
0958: );
0959:
0960: output.printTrace("Scroll ScrollPane " + toStringSource() +
0961:
0962: "\nto component " + componentToString);
0963:
0964: output.printGolden("Scroll ScrollPane to "
0965: + comp.getClass().getName() + " component.");
0966:
0967: scrollToComponentRectangle(comp, 0, 0, comp.getWidth(), comp
0968: .getHeight());
0969:
0970: }
0971:
0972: /**
0973:
0974: * Checks if component's rectangle is inside view port (no scrolling necessary).
0975:
0976: * @param comp a subcomponent defining coordinate system.
0977:
0978: * @param x coordinate
0979:
0980: * @param y coordinate
0981:
0982: * @param width rectangle width
0983:
0984: * @param height rectangle height
0985:
0986: * @return true if pointed subcomponent rectangle is inside the scrolling area.
0987:
0988: */
0989:
0990: public boolean checkInside(Component comp, int x, int y, int width,
0991: int height) {
0992:
0993: Point toPoint = SwingUtilities.
0994:
0995: convertPoint(comp, x, y, getSource());
0996:
0997: if (toPoint.x < getHAdjustable().getValue()) {
0998:
0999: return (false);
1000:
1001: }
1002:
1003: if (comp.getWidth() > getSource().getWidth()) {
1004:
1005: if (toPoint.x > 0) {
1006:
1007: return (false);
1008:
1009: }
1010:
1011: } else {
1012:
1013: if (toPoint.x + comp.getWidth() >
1014:
1015: getHAdjustable().getValue() + getSource().getWidth()) {
1016:
1017: return (false);
1018:
1019: }
1020:
1021: }
1022:
1023: if (toPoint.y < getVAdjustable().getValue()) {
1024:
1025: return (false);
1026:
1027: }
1028:
1029: if (comp.getHeight() > getSource().getHeight()) {
1030:
1031: if (toPoint.y > 0) {
1032:
1033: return (false);
1034:
1035: }
1036:
1037: } else {
1038:
1039: if (toPoint.y + comp.getHeight() >
1040:
1041: getVAdjustable().getValue() + getSource().getHeight()) {
1042:
1043: return (false);
1044:
1045: }
1046:
1047: }
1048:
1049: return (true);
1050:
1051: }
1052:
1053: /**
1054:
1055: * Checks if component is inside view port (no scrolling necessary).
1056:
1057: * @param comp a subcomponent defining coordinate system.
1058:
1059: * @return true if pointed subcomponent is inside the scrolling area.
1060:
1061: */
1062:
1063: public boolean checkInside(Component comp) {
1064:
1065: return (checkInside(comp, 0, 0, comp.getWidth(), comp
1066: .getHeight()));
1067:
1068: }
1069:
1070: /**
1071:
1072: * Tells if a scrollbar is visible.
1073:
1074: * @param orientation <code>Adjustable.HORIZONTAL</code> or <code>Adjustable.VERTICAL</code>
1075:
1076: * @return trus if the bar is visible.
1077:
1078: */
1079:
1080: public boolean isScrollbarVisible(int orientation) {
1081:
1082: if (orientation == Adjustable.HORIZONTAL) {
1083:
1084: return (getViewportSize().getHeight() < getHeight()
1085: - getHScrollbarHeight());
1086:
1087: } else if (orientation == Adjustable.VERTICAL) {
1088:
1089: return (getViewportSize().getWidth() < getWidth()
1090: - getVScrollbarWidth());
1091:
1092: } else {
1093:
1094: return (false);
1095:
1096: }
1097:
1098: }
1099:
1100: ////////////////////////////////////////////////////////
1101:
1102: //Mapping //
1103:
1104: /**Maps <code>ScrollPane.getHAdjustable()</code> through queue*/
1105:
1106: public Adjustable getHAdjustable() {
1107:
1108: return ((Adjustable) runMapping(new MapAction("getHAdjustable") {
1109:
1110: public Object map() {
1111:
1112: return (((ScrollPane) getSource()).getHAdjustable());
1113:
1114: }
1115: }));
1116: }
1117:
1118: /**Maps <code>ScrollPane.getHScrollbarHeight()</code> through queue*/
1119:
1120: public int getHScrollbarHeight() {
1121:
1122: return (runMapping(new MapIntegerAction("getHScrollbarHeight") {
1123:
1124: public int map() {
1125:
1126: return (((ScrollPane) getSource())
1127: .getHScrollbarHeight());
1128:
1129: }
1130: }));
1131: }
1132:
1133: /**Maps <code>ScrollPane.getScrollPosition()</code> through queue*/
1134:
1135: public Point getScrollPosition() {
1136:
1137: return ((Point) runMapping(new MapAction("getScrollPosition") {
1138:
1139: public Object map() {
1140:
1141: return (((ScrollPane) getSource()).getScrollPosition());
1142:
1143: }
1144: }));
1145: }
1146:
1147: /**Maps <code>ScrollPane.getScrollbarDisplayPolicy()</code> through queue*/
1148:
1149: public int getScrollbarDisplayPolicy() {
1150:
1151: return (runMapping(new MapIntegerAction(
1152: "getScrollbarDisplayPolicy") {
1153:
1154: public int map() {
1155:
1156: return (((ScrollPane) getSource())
1157: .getScrollbarDisplayPolicy());
1158:
1159: }
1160: }));
1161: }
1162:
1163: /**Maps <code>ScrollPane.getVAdjustable()</code> through queue*/
1164:
1165: public Adjustable getVAdjustable() {
1166:
1167: return ((Adjustable) runMapping(new MapAction("getVAdjustable") {
1168:
1169: public Object map() {
1170:
1171: return (((ScrollPane) getSource()).getVAdjustable());
1172:
1173: }
1174: }));
1175: }
1176:
1177: /**Maps <code>ScrollPane.getVScrollbarWidth()</code> through queue*/
1178:
1179: public int getVScrollbarWidth() {
1180:
1181: return (runMapping(new MapIntegerAction("getVScrollbarWidth") {
1182:
1183: public int map() {
1184:
1185: return (((ScrollPane) getSource()).getVScrollbarWidth());
1186:
1187: }
1188: }));
1189: }
1190:
1191: /**Maps <code>ScrollPane.getViewportSize()</code> through queue*/
1192:
1193: public Dimension getViewportSize() {
1194:
1195: return ((Dimension) runMapping(new MapAction("getViewportSize") {
1196:
1197: public Object map() {
1198:
1199: return (((ScrollPane) getSource()).getViewportSize());
1200:
1201: }
1202: }));
1203: }
1204:
1205: /**Maps <code>ScrollPane.paramString()</code> through queue*/
1206:
1207: public String paramString() {
1208:
1209: return ((String) runMapping(new MapAction("paramString") {
1210:
1211: public Object map() {
1212:
1213: return (((ScrollPane) getSource()).paramString());
1214:
1215: }
1216: }));
1217: }
1218:
1219: /**Maps <code>ScrollPane.setScrollPosition(int, int)</code> through queue*/
1220:
1221: public void setScrollPosition(final int i, final int i1) {
1222:
1223: runMapping(new MapVoidAction("setScrollPosition") {
1224:
1225: public void map() {
1226:
1227: ((ScrollPane) getSource()).setScrollPosition(i, i1);
1228:
1229: }
1230: });
1231: }
1232:
1233: /**Maps <code>ScrollPane.setScrollPosition(Point)</code> through queue*/
1234:
1235: public void setScrollPosition(final Point point) {
1236:
1237: runMapping(new MapVoidAction("setScrollPosition") {
1238:
1239: public void map() {
1240:
1241: ((ScrollPane) getSource()).setScrollPosition(point);
1242:
1243: }
1244: });
1245: }
1246:
1247: //End of mapping //
1248:
1249: ////////////////////////////////////////////////////////
1250:
1251: private class ValueScrollAdjuster implements ScrollAdjuster {
1252:
1253: int value;
1254:
1255: int orientation;
1256:
1257: Adjustable adj;
1258:
1259: public ValueScrollAdjuster(int value, int orientation,
1260: Adjustable adj) {
1261:
1262: this .value = value;
1263:
1264: this .orientation = orientation;
1265:
1266: this .adj = adj;
1267:
1268: }
1269:
1270: public int getScrollDirection() {
1271:
1272: if (adj.getValue() == value) {
1273:
1274: return (ScrollAdjuster.DO_NOT_TOUCH_SCROLL_DIRECTION);
1275:
1276: } else {
1277:
1278: return ((adj.getValue() < value) ?
1279:
1280: ScrollAdjuster.INCREASE_SCROLL_DIRECTION :
1281:
1282: ScrollAdjuster.DECREASE_SCROLL_DIRECTION);
1283:
1284: }
1285:
1286: }
1287:
1288: public int getScrollOrientation() {
1289:
1290: return (orientation);
1291:
1292: }
1293:
1294: public String getDescription() {
1295:
1296: return ("Scroll to " + Integer.toString(value) + " value");
1297:
1298: }
1299:
1300: }
1301:
1302: private class ComponentRectChecker implements ScrollAdjuster {
1303:
1304: Component comp;
1305:
1306: int x;
1307:
1308: int y;
1309:
1310: int width;
1311:
1312: int height;
1313:
1314: int orientation;
1315:
1316: public ComponentRectChecker(Component comp, int x, int y,
1317: int width, int height, int orientation) {
1318:
1319: this .comp = comp;
1320:
1321: this .x = x;
1322:
1323: this .y = y;
1324:
1325: this .width = width;
1326:
1327: this .height = height;
1328:
1329: this .orientation = orientation;
1330:
1331: }
1332:
1333: public int getScrollDirection() {
1334:
1335: int sp =
1336:
1337: (orientation == Adjustable.HORIZONTAL) ?
1338:
1339: (int) getScrollPosition().getX() :
1340:
1341: (int) getScrollPosition().getY();
1342:
1343: Point pnt = SwingUtilities.convertPoint(comp, x, y,
1344: ((Container) getSource()).getComponents()[0]);
1345:
1346: int cp =
1347:
1348: (orientation == Adjustable.HORIZONTAL) ?
1349:
1350: pnt.x :
1351:
1352: pnt.y;
1353:
1354: int sl =
1355:
1356: (orientation == Adjustable.HORIZONTAL) ?
1357:
1358: (int) getViewportSize().getWidth() :
1359:
1360: (int) getViewportSize().getHeight();
1361:
1362: int cl =
1363:
1364: (orientation == Adjustable.HORIZONTAL) ?
1365:
1366: width :
1367:
1368: height;
1369:
1370: if (cp <= sp) {
1371:
1372: return (ScrollAdjuster.DECREASE_SCROLL_DIRECTION);
1373:
1374: } else if ((cp + cl) > (sp + sl) &&
1375:
1376: cp > sp) {
1377:
1378: return (ScrollAdjuster.INCREASE_SCROLL_DIRECTION);
1379:
1380: } else {
1381:
1382: return (ScrollAdjuster.DO_NOT_TOUCH_SCROLL_DIRECTION);
1383:
1384: }
1385:
1386: }
1387:
1388: public int getScrollOrientation() {
1389:
1390: return (orientation);
1391:
1392: }
1393:
1394: public String getDescription() {
1395:
1396: return ("");
1397:
1398: }
1399:
1400: }
1401:
1402: /**
1403:
1404: * Checks component type.
1405:
1406: */
1407:
1408: public static class ScrollPaneFinder extends Finder {
1409:
1410: /**
1411:
1412: * Constructs ScrollPaneFinder.
1413:
1414: * @param sf other searching criteria.
1415:
1416: */
1417:
1418: public ScrollPaneFinder(ComponentChooser sf) {
1419:
1420: super (ScrollPane.class, sf);
1421:
1422: }
1423:
1424: /**
1425:
1426: * Constructs ScrollPaneFinder.
1427:
1428: */
1429:
1430: public ScrollPaneFinder() {
1431:
1432: super (ScrollPane.class);
1433:
1434: }
1435:
1436: }
1437:
1438: }
|