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