ScrollPaneOperator.java revision 13978:1993af50385d
1166124Srafan/*
2166124Srafan * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
3166124Srafan * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4166124Srafan *
5166124Srafan * This code is free software; you can redistribute it and/or modify it
6166124Srafan * under the terms of the GNU General Public License version 2 only, as
7166124Srafan * published by the Free Software Foundation.
8166124Srafan *
9166124Srafan * This code is distributed in the hope that it will be useful, but WITHOUT
10166124Srafan * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11166124Srafan * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12166124Srafan * version 2 for more details (a copy is included in the LICENSE file that
13166124Srafan * accompanied this code).
14166124Srafan *
15166124Srafan * You should have received a copy of the GNU General Public License version
16166124Srafan * 2 along with this work; if not, write to the Free Software Foundation,
17166124Srafan * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18166124Srafan *
19166124Srafan * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20166124Srafan * or visit www.oracle.com if you need additional information or have any
21166124Srafan * questions.
22166124Srafan */
23166124Srafanpackage org.netbeans.jemmy.operators;
24166124Srafan
25166124Srafanimport java.awt.Adjustable;
26166124Srafanimport java.awt.Component;
27166124Srafanimport java.awt.Container;
28166124Srafanimport java.awt.Dimension;
29166124Srafanimport java.awt.Point;
30166124Srafanimport java.awt.ScrollPane;
31166124Srafanimport javax.swing.SwingUtilities;
32166124Srafanimport org.netbeans.jemmy.Action;
33166124Srafanimport org.netbeans.jemmy.ComponentChooser;
34166124Srafanimport org.netbeans.jemmy.ComponentSearcher;
35166124Srafanimport org.netbeans.jemmy.JemmyException;
36166124Srafanimport org.netbeans.jemmy.Outputable;
37166124Srafanimport org.netbeans.jemmy.TestOut;
38166124Srafanimport org.netbeans.jemmy.TimeoutExpiredException;
39166124Srafanimport org.netbeans.jemmy.Timeoutable;
40166124Srafanimport org.netbeans.jemmy.Timeouts;
41166124Srafanimport org.netbeans.jemmy.drivers.DriverManager;
42166124Srafanimport org.netbeans.jemmy.drivers.ScrollDriver;
43166124Srafanimport org.netbeans.jemmy.drivers.scrolling.ScrollAdjuster;
44166124Srafan
45166124Srafan/**
46166124Srafan * <BR><BR>Timeouts used: <BR>
47166124Srafan * ScrollbarOperator.WholeScrollTimeout - time for one scroll click <BR>
48166124Srafan * ComponentOperator.WaitComponentTimeout - time to wait component displayed
49166124Srafan * <BR>.
50166124Srafan *
51166124Srafan * @see org.netbeans.jemmy.Timeouts
52166124Srafan *
53166124Srafan * @author Alexandre Iline (alexandre.iline@oracle.com)
54166124Srafan *
55166124Srafan */
56166124Srafanpublic class ScrollPaneOperator extends ContainerOperator<ScrollPane>
57166124Srafan        implements Timeoutable, Outputable {
58166124Srafan
59166124Srafan    private static int X_POINT_RECT_SIZE = 6;
60166124Srafan    private static int Y_POINT_RECT_SIZE = 4;
61166124Srafan    private Timeouts timeouts;
62166124Srafan    private TestOut output;
63166124Srafan    private ScrollDriver driver;
64166124Srafan
65166124Srafan    /**
66166124Srafan     * Constructor.
67166124Srafan     *
68166124Srafan     * @param b The {@code java.awt.ScrollPane} managed by this instance.
69166124Srafan     */
70166124Srafan    public ScrollPaneOperator(ScrollPane b) {
71166124Srafan        super(b);
72166124Srafan        driver = DriverManager.getScrollDriver(getClass());
73    }
74
75    /**
76     * Constructs a ScrollPaneOperator object.
77     *
78     * @param cont a container
79     * @param chooser a component chooser specifying searching criteria.
80     * @param index an index between appropriate ones.
81     */
82    public ScrollPaneOperator(ContainerOperator<?> cont, ComponentChooser chooser, int index) {
83        this((ScrollPane) cont.
84                waitSubComponent(new ScrollPaneFinder(chooser),
85                        index));
86        copyEnvironment(cont);
87    }
88
89    /**
90     * Constructs a ScrollPaneOperator object.
91     *
92     * @param cont a container
93     * @param chooser a component chooser specifying searching criteria.
94     */
95    public ScrollPaneOperator(ContainerOperator<?> cont, ComponentChooser chooser) {
96        this(cont, chooser, 0);
97    }
98
99    /**
100     * Constructor. Waits component in container first. Uses cont's timeout and
101     * output for waiting and to init operator.
102     *
103     * @param cont Operator pointing a container to search component in.
104     * @param index Ordinal component index.
105     * @throws TimeoutExpiredException
106     */
107    public ScrollPaneOperator(ContainerOperator<?> cont, int index) {
108        this((ScrollPane) waitComponent(cont,
109                new ScrollPaneFinder(),
110                index));
111        copyEnvironment(cont);
112    }
113
114    /**
115     * Constructor. Waits component in container first. Uses cont's timeout and
116     * output for waiting and to init operator.
117     *
118     * @param cont Operator pointing a container to search component in.
119     * @throws TimeoutExpiredException
120     */
121    public ScrollPaneOperator(ContainerOperator<?> cont) {
122        this(cont, 0);
123    }
124
125    /**
126     * Searches ScrollPane in container.
127     *
128     * @param cont Container to search component in.
129     * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
130     * @param index Ordinal component index.
131     * @return ScrollPane instance or null if component was not found.
132     */
133    public static ScrollPane findScrollPane(Container cont, ComponentChooser chooser, int index) {
134        return (ScrollPane) findComponent(cont, new ScrollPaneFinder(chooser), index);
135    }
136
137    /**
138     * Searches 0'th ScrollPane in container.
139     *
140     * @param cont Container to search component in.
141     * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
142     * @return ScrollPane instance or null if component was not found.
143     */
144    public static ScrollPane findScrollPane(Container cont, ComponentChooser chooser) {
145        return findScrollPane(cont, chooser, 0);
146    }
147
148    /**
149     * Searches ScrollPane in container.
150     *
151     * @param cont Container to search component in.
152     * @param index Ordinal component index.
153     * @return ScrollPane instance or null if component was not found.
154     */
155    public static ScrollPane findScrollPane(Container cont, int index) {
156        return findScrollPane(cont, ComponentSearcher.getTrueChooser(Integer.toString(index) + "'th ScrollPane instance"), index);
157    }
158
159    /**
160     * Searches 0'th ScrollPane in container.
161     *
162     * @param cont Container to search component in.
163     * @return ScrollPane instance or null if component was not found.
164     */
165    public static ScrollPane findScrollPane(Container cont) {
166        return findScrollPane(cont, 0);
167    }
168
169    /**
170     * Searches ScrollPane object which component lies on.
171     *
172     * @param comp Component to find ScrollPane under.
173     * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
174     * @return ScrollPane instance or null if component was not found.
175     */
176    public static ScrollPane findScrollPaneUnder(Component comp, ComponentChooser chooser) {
177        return (ScrollPane) findContainerUnder(comp, new ScrollPaneFinder(chooser));
178    }
179
180    /**
181     * Searches ScrollPane object which component lies on.
182     *
183     * @param comp Component to find ScrollPane under.
184     * @return ScrollPane instance or null if component was not found.
185     */
186    public static ScrollPane findScrollPaneUnder(Component comp) {
187        return findScrollPaneUnder(comp, new ScrollPaneFinder());
188    }
189
190    /**
191     * Waits ScrollPane in container.
192     *
193     * @param cont Container to search component in.
194     * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
195     * @param index Ordinal component index.
196     * @return ScrollPane instance or null if component was not displayed.
197     * @throws TimeoutExpiredException
198     */
199    public static ScrollPane waitScrollPane(Container cont, ComponentChooser chooser, int index) {
200        return (ScrollPane) waitComponent(cont, new ScrollPaneFinder(chooser), index);
201    }
202
203    /**
204     * Waits 0'th ScrollPane in container.
205     *
206     * @param cont Container to search component in.
207     * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
208     * @return ScrollPane instance or null if component was not displayed.
209     * @throws TimeoutExpiredException
210     */
211    public static ScrollPane waitScrollPane(Container cont, ComponentChooser chooser) {
212        return waitScrollPane(cont, chooser, 0);
213    }
214
215    /**
216     * Waits ScrollPane in container.
217     *
218     * @param cont Container to search component in.
219     * @param index Ordinal component index.
220     * @return ScrollPane instance or null if component was not displayed.
221     * @throws TimeoutExpiredException
222     */
223    public static ScrollPane waitScrollPane(Container cont, int index) {
224        return waitScrollPane(cont, ComponentSearcher.getTrueChooser(Integer.toString(index) + "'th ScrollPane instance"), index);
225    }
226
227    /**
228     * Waits 0'th ScrollPane in container.
229     *
230     * @param cont Container to search component in.
231     * @return ScrollPane instance or null if component was not displayed.
232     * @throws TimeoutExpiredException
233     */
234    public static ScrollPane waitScrollPane(Container cont) {
235        return waitScrollPane(cont, 0);
236    }
237
238    static {
239        try {
240            Class.forName("org.netbeans.jemmy.operators.ScrollbarOperator");
241        } catch (Exception e) {
242            throw (new JemmyException("Exception", e));
243        }
244    }
245
246    @Override
247    public void setTimeouts(Timeouts timeouts) {
248        super.setTimeouts(timeouts);
249        this.timeouts = timeouts;
250    }
251
252    @Override
253    public Timeouts getTimeouts() {
254        return timeouts;
255    }
256
257    @Override
258    public void setOutput(TestOut out) {
259        output = out;
260        super.setOutput(output.createErrorOutput());
261    }
262
263    @Override
264    public TestOut getOutput() {
265        return output;
266    }
267
268    @Override
269    public void copyEnvironment(Operator anotherOperator) {
270        super.copyEnvironment(anotherOperator);
271        driver
272                = (ScrollDriver) DriverManager.
273                getDriver(DriverManager.SCROLL_DRIVER_ID,
274                        getClass(),
275                        anotherOperator.getProperties());
276    }
277
278    /**
279     * Sets both values.
280     *
281     * @param x a horizontal value.
282     * @param y a vertical value.
283     */
284    public void setValues(int x, int y) {
285        getHAdjustable().setValue(x);
286        getVAdjustable().setValue(y);
287    }
288
289    /**
290     * Scrools to the position defined by a ScrollAdjuster instance.
291     *
292     * @param adj specifies the position.
293     */
294    public void scrollTo(final ScrollAdjuster adj) {
295        produceTimeRestricted(new Action<Void, Void>() {
296            @Override
297            public Void launch(Void obj) {
298                driver.scroll(ScrollPaneOperator.this, adj);
299                return null;
300            }
301
302            @Override
303            public String getDescription() {
304                return "Scrolling";
305            }
306
307            @Override
308            public String toString() {
309                return "ScrollPaneOperator.scrollTo.Action{description = " + getDescription() + '}';
310            }
311        }, "ScrollbarOperator.WholeScrollTimeout");
312    }
313
314    /**
315     * Scrolls horizontal scroll bar.
316     *
317     * @param value Value to scroll horizontal scroll bar to.
318     * @throws TimeoutExpiredException
319     */
320    public void scrollToHorizontalValue(final int value) {
321        output.printTrace("Scroll ScrollPane to " + Integer.toString(value) + " horizontal value \n"
322                + toStringSource());
323        output.printGolden("Scroll ScrollPane to " + Integer.toString(value) + " horizontal value");
324        scrollTo(new ValueScrollAdjuster(value,
325                Adjustable.HORIZONTAL,
326                getHAdjustable()));
327    }
328
329    /**
330     * Scrolls horizontal scroll bar.
331     *
332     * @param proportionalValue Proportional value to scroll horizontal scroll
333     * bar to.
334     * @throws TimeoutExpiredException
335     */
336    public void scrollToHorizontalValue(double proportionalValue) {
337        output.printTrace("Scroll ScrollPane to " + Double.toString(proportionalValue) + " proportional horizontal value \n"
338                + toStringSource());
339        output.printGolden("Scroll ScrollPane to " + Double.toString(proportionalValue) + " proportional horizontal value");
340        Adjustable adj = getHAdjustable();
341        scrollTo(new ValueScrollAdjuster((int) (adj.getMinimum()
342                + (adj.getMaximum()
343                - adj.getVisibleAmount()
344                - adj.getMinimum()) * proportionalValue),
345                Adjustable.VERTICAL,
346                getVAdjustable()));
347    }
348
349    /**
350     * Scrolls vertical scroll bar.
351     *
352     * @param value Value to scroll vertical scroll bar to.
353     * @throws TimeoutExpiredException
354     */
355    public void scrollToVerticalValue(final int value) {
356        output.printTrace("Scroll ScrollPane to " + Integer.toString(value) + " vertical value \n"
357                + toStringSource());
358        output.printGolden("Scroll ScrollPane to " + Integer.toString(value) + " vertical value");
359        scrollTo(new ValueScrollAdjuster(value,
360                Adjustable.VERTICAL,
361                getVAdjustable()));
362    }
363
364    /**
365     * Scrolls vertical scroll bar.
366     *
367     * @param proportionalValue Value to scroll vertical scroll bar to.
368     * @throws TimeoutExpiredException
369     */
370    public void scrollToVerticalValue(double proportionalValue) {
371        output.printTrace("Scroll ScrollPane to " + Double.toString(proportionalValue) + " proportional vertical value \n"
372                + toStringSource());
373        output.printGolden("Scroll ScrollPane to " + Double.toString(proportionalValue) + " proportional vertical value");
374        Adjustable adj = getVAdjustable();
375        scrollTo(new ValueScrollAdjuster((int) (adj.getMinimum()
376                + (adj.getMaximum()
377                - adj.getVisibleAmount()
378                - adj.getMinimum()) * proportionalValue),
379                Adjustable.VERTICAL,
380                getVAdjustable()));
381    }
382
383    /**
384     * Scrolls both scroll bars.
385     *
386     * @param valueX Value to scroll horizontal scroll bar to.
387     * @param valueY Value to scroll vertical scroll bar to.
388     * @throws TimeoutExpiredException
389     */
390    public void scrollToValues(int valueX, int valueY) {
391        scrollToVerticalValue(valueX);
392        scrollToHorizontalValue(valueX);
393    }
394
395    /**
396     * Scrolls both scroll bars.
397     *
398     * @param proportionalValueX Value to scroll horizontal scroll bar to.
399     * @param proportionalValueY Value to scroll vertical scroll bar to.
400     * @throws TimeoutExpiredException
401     */
402    public void scrollToValues(double proportionalValueX, double proportionalValueY) {
403        scrollToVerticalValue(proportionalValueX);
404        scrollToHorizontalValue(proportionalValueY);
405    }
406
407    /**
408     * Scrolls pane to top.
409     *
410     * @throws TimeoutExpiredException
411     */
412    public void scrollToTop() {
413        output.printTrace("Scroll ScrollPane to top\n"
414                + toStringSource());
415        output.printGolden("Scroll ScrollPane to top");
416        produceTimeRestricted(new Action<Void, Void>() {
417            @Override
418            public Void launch(Void obj) {
419                driver.scrollToMinimum(ScrollPaneOperator.this, Adjustable.VERTICAL);
420                return null;
421            }
422
423            @Override
424            public String getDescription() {
425                return "Scrolling";
426            }
427
428            @Override
429            public String toString() {
430                return "ScrollPaneOperator.scrollToTop.Action{description = " + getDescription() + '}';
431            }
432        }, "ScrollbarOperator.WholeScrollTimeout");
433    }
434
435    /**
436     * Scrolls pane to bottom.
437     *
438     * @throws TimeoutExpiredException
439     */
440    public void scrollToBottom() {
441        output.printTrace("Scroll ScrollPane to bottom\n"
442                + toStringSource());
443        output.printGolden("Scroll ScrollPane to bottom");
444        produceTimeRestricted(new Action<Void, Void>() {
445            @Override
446            public Void launch(Void obj) {
447                driver.scrollToMaximum(ScrollPaneOperator.this, Adjustable.VERTICAL);
448                return null;
449            }
450
451            @Override
452            public String getDescription() {
453                return "Scrolling";
454            }
455
456            @Override
457            public String toString() {
458                return "ScrollPaneOperator.scrollToBottom.Action{description = " + getDescription() + '}';
459            }
460        }, "ScrollbarOperator.WholeScrollTimeout");
461    }
462
463    /**
464     * Scrolls pane to left.
465     *
466     * @throws TimeoutExpiredException
467     */
468    public void scrollToLeft() {
469        output.printTrace("Scroll ScrollPane to left\n"
470                + toStringSource());
471        output.printGolden("Scroll ScrollPane to left");
472        produceTimeRestricted(new Action<Void, Void>() {
473            @Override
474            public Void launch(Void obj) {
475                driver.scrollToMinimum(ScrollPaneOperator.this, Adjustable.HORIZONTAL);
476                return null;
477            }
478
479            @Override
480            public String getDescription() {
481                return "Scrolling";
482            }
483
484            @Override
485            public String toString() {
486                return "ScrollPaneOperator.scrollToLeft.Action{description = " + getDescription() + '}';
487            }
488        }, "ScrollbarOperator.WholeScrollTimeout");
489    }
490
491    /**
492     * Scrolls pane to right.
493     *
494     * @throws TimeoutExpiredException
495     */
496    public void scrollToRight() {
497        output.printTrace("Scroll ScrollPane to right\n"
498                + toStringSource());
499        output.printGolden("Scroll ScrollPane to right");
500        produceTimeRestricted(new Action<Void, Void>() {
501            @Override
502            public Void launch(Void obj) {
503                driver.scrollToMaximum(ScrollPaneOperator.this, Adjustable.HORIZONTAL);
504                return null;
505            }
506
507            @Override
508            public String getDescription() {
509                return "Scrolling";
510            }
511
512            @Override
513            public String toString() {
514                return "ScrollPaneOperator.scrollToRight.Action{description = " + getDescription() + '}';
515            }
516        }, "ScrollbarOperator.WholeScrollTimeout");
517    }
518
519    /**
520     * Scrolls pane to rectangle..
521     *
522     * @param comp a subcomponent defining coordinate system.
523     * @param x coordinate
524     * @param y coordinate
525     * @param width rectangle width
526     * @param height rectangle height
527     * @throws TimeoutExpiredException
528     */
529    public void scrollToComponentRectangle(Component comp, int x, int y, int width, int height) {
530        scrollTo(new ComponentRectChecker(comp, x, y, width, height, Adjustable.HORIZONTAL));
531        scrollTo(new ComponentRectChecker(comp, x, y, width, height, Adjustable.VERTICAL));
532    }
533
534    /**
535     * Scrolls pane to point.
536     *
537     * @param comp a subcomponent defining coordinate system.
538     * @param x coordinate
539     * @param y coordinate
540     * @throws TimeoutExpiredException
541     */
542    public void scrollToComponentPoint(Component comp, int x, int y) {
543        scrollToComponentRectangle(comp,
544                x - X_POINT_RECT_SIZE,
545                y - Y_POINT_RECT_SIZE,
546                2 * X_POINT_RECT_SIZE,
547                2 * Y_POINT_RECT_SIZE);
548    }
549
550    /**
551     * Scrolls pane to component on this pane. Component should lay on the
552     * ScrollPane view.
553     *
554     * @param comp Component to scroll to.
555     * @throws TimeoutExpiredException
556     */
557    public void scrollToComponent(final Component comp) {
558        String componentToString = runMapping(
559                new Operator.MapAction<String>("comp.toString()") {
560            @Override
561            public String map() {
562                return comp.toString();
563            }
564        }
565        );
566        output.printTrace("Scroll ScrollPane " + toStringSource()
567                + "\nto component " + componentToString);
568        output.printGolden("Scroll ScrollPane to " + comp.getClass().getName() + " component.");
569        scrollToComponentRectangle(comp, 0, 0, comp.getWidth(), comp.getHeight());
570    }
571
572    /**
573     * Checks if component's rectangle is inside view port (no scrolling
574     * necessary).
575     *
576     * @param comp a subcomponent defining coordinate system.
577     * @param x coordinate
578     * @param y coordinate
579     * @param width rectangle width
580     * @param height rectangle height
581     * @return true if pointed subcomponent rectangle is inside the scrolling
582     * area.
583     */
584    public boolean checkInside(Component comp, int x, int y, int width, int height) {
585        Point toPoint = SwingUtilities.
586                convertPoint(comp, x, y, getSource());
587        if (toPoint.x < getHAdjustable().getValue()) {
588            return false;
589        }
590        if (comp.getWidth() > getSource().getWidth()) {
591            if (toPoint.x > 0) {
592                return false;
593            }
594        } else if (toPoint.x + comp.getWidth()
595                > getHAdjustable().getValue() + getSource().getWidth()) {
596            return false;
597        }
598        if (toPoint.y < getVAdjustable().getValue()) {
599            return false;
600        }
601        if (comp.getHeight() > getSource().getHeight()) {
602            if (toPoint.y > 0) {
603                return false;
604            }
605        } else if (toPoint.y + comp.getHeight()
606                > getVAdjustable().getValue() + getSource().getHeight()) {
607            return false;
608        }
609        return true;
610    }
611
612    /**
613     * Checks if component is inside view port (no scrolling necessary).
614     *
615     * @param comp a subcomponent defining coordinate system.
616     * @return true if pointed subcomponent is inside the scrolling area.
617     */
618    public boolean checkInside(Component comp) {
619        return checkInside(comp, 0, 0, comp.getWidth(), comp.getHeight());
620    }
621
622    /**
623     * Tells if a scrollbar is visible.
624     *
625     * @param orientation {@code Adjustable.HORIZONTAL} or
626     * {@code Adjustable.VERTICAL}
627     * @return trus if the bar is visible.
628     */
629    public boolean isScrollbarVisible(int orientation) {
630        if (orientation == Adjustable.HORIZONTAL) {
631            return getViewportSize().getHeight() < getHeight() - getHScrollbarHeight();
632        } else if (orientation == Adjustable.VERTICAL) {
633            return getViewportSize().getWidth() < getWidth() - getVScrollbarWidth();
634        } else {
635            return false;
636        }
637    }
638
639    ////////////////////////////////////////////////////////
640    //Mapping                                             //
641    /**
642     * Maps {@code ScrollPane.getHAdjustable()} through queue
643     */
644    public Adjustable getHAdjustable() {
645        return (runMapping(new MapAction<Adjustable>("getHAdjustable") {
646            @Override
647            public Adjustable map() {
648                return ((ScrollPane) getSource()).getHAdjustable();
649            }
650        }));
651    }
652
653    /**
654     * Maps {@code ScrollPane.getHScrollbarHeight()} through queue
655     */
656    public int getHScrollbarHeight() {
657        return (runMapping(new MapIntegerAction("getHScrollbarHeight") {
658            @Override
659            public int map() {
660                return ((ScrollPane) getSource()).getHScrollbarHeight();
661            }
662        }));
663    }
664
665    /**
666     * Maps {@code ScrollPane.getScrollPosition()} through queue
667     */
668    public Point getScrollPosition() {
669        return (runMapping(new MapAction<Point>("getScrollPosition") {
670            @Override
671            public Point map() {
672                return ((ScrollPane) getSource()).getScrollPosition();
673            }
674        }));
675    }
676
677    /**
678     * Maps {@code ScrollPane.getScrollbarDisplayPolicy()} through queue
679     */
680    public int getScrollbarDisplayPolicy() {
681        return (runMapping(new MapIntegerAction("getScrollbarDisplayPolicy") {
682            @Override
683            public int map() {
684                return ((ScrollPane) getSource()).getScrollbarDisplayPolicy();
685            }
686        }));
687    }
688
689    /**
690     * Maps {@code ScrollPane.getVAdjustable()} through queue
691     */
692    public Adjustable getVAdjustable() {
693        return (runMapping(new MapAction<Adjustable>("getVAdjustable") {
694            @Override
695            public Adjustable map() {
696                return ((ScrollPane) getSource()).getVAdjustable();
697            }
698        }));
699    }
700
701    /**
702     * Maps {@code ScrollPane.getVScrollbarWidth()} through queue
703     */
704    public int getVScrollbarWidth() {
705        return (runMapping(new MapIntegerAction("getVScrollbarWidth") {
706            @Override
707            public int map() {
708                return ((ScrollPane) getSource()).getVScrollbarWidth();
709            }
710        }));
711    }
712
713    /**
714     * Maps {@code ScrollPane.getViewportSize()} through queue
715     */
716    public Dimension getViewportSize() {
717        return (runMapping(new MapAction<Dimension>("getViewportSize") {
718            @Override
719            public Dimension map() {
720                return ((ScrollPane) getSource()).getViewportSize();
721            }
722        }));
723    }
724
725    /**
726     * Maps {@code ScrollPane.paramString()} through queue
727     */
728    public String paramString() {
729        return (runMapping(new MapAction<String>("paramString") {
730            @Override
731            public String map() {
732                return ((ScrollPane) getSource()).paramString();
733            }
734        }));
735    }
736
737    /**
738     * Maps {@code ScrollPane.setScrollPosition(int, int)} through queue
739     */
740    public void setScrollPosition(final int i, final int i1) {
741        runMapping(new MapVoidAction("setScrollPosition") {
742            @Override
743            public void map() {
744                ((ScrollPane) getSource()).setScrollPosition(i, i1);
745            }
746        });
747    }
748
749    /**
750     * Maps {@code ScrollPane.setScrollPosition(Point)} through queue
751     */
752    public void setScrollPosition(final Point point) {
753        runMapping(new MapVoidAction("setScrollPosition") {
754            @Override
755            public void map() {
756                ((ScrollPane) getSource()).setScrollPosition(point);
757            }
758        });
759    }
760
761    //End of mapping                                      //
762    ////////////////////////////////////////////////////////
763    private static class ValueScrollAdjuster implements ScrollAdjuster {
764
765        int value;
766        int orientation;
767        Adjustable adj;
768
769        public ValueScrollAdjuster(int value, int orientation, Adjustable adj) {
770            this.value = value;
771            this.orientation = orientation;
772            this.adj = adj;
773        }
774
775        @Override
776        public int getScrollDirection() {
777            if (adj.getValue() == value) {
778                return ScrollAdjuster.DO_NOT_TOUCH_SCROLL_DIRECTION;
779            } else {
780                return ((adj.getValue() < value)
781                        ? ScrollAdjuster.INCREASE_SCROLL_DIRECTION
782                        : ScrollAdjuster.DECREASE_SCROLL_DIRECTION);
783            }
784        }
785
786        @Override
787        public int getScrollOrientation() {
788            return orientation;
789        }
790
791        @Override
792        public String getDescription() {
793            return "Scroll to " + Integer.toString(value) + " value";
794        }
795
796        @Override
797        public String toString() {
798            return "ValueScrollAdjuster{" + "value=" + value + ", orientation=" + orientation + ", adj=" + adj + '}';
799        }
800    }
801
802    private class ComponentRectChecker implements ScrollAdjuster {
803
804        Component comp;
805        int x;
806        int y;
807        int width;
808        int height;
809        int orientation;
810
811        public ComponentRectChecker(Component comp, int x, int y, int width, int height, int orientation) {
812            this.comp = comp;
813            this.x = x;
814            this.y = y;
815            this.width = width;
816            this.height = height;
817            this.orientation = orientation;
818        }
819
820        @Override
821        public int getScrollDirection() {
822            int sp = (orientation == Adjustable.HORIZONTAL)
823                    ? (int) getScrollPosition().getX()
824                    : (int) getScrollPosition().getY();
825            Point pnt = SwingUtilities.convertPoint(comp, x, y, ((Container) getSource()).getComponents()[0]);
826            int cp = (orientation == Adjustable.HORIZONTAL)
827                    ? pnt.x
828                    : pnt.y;
829            int sl = (orientation == Adjustable.HORIZONTAL)
830                    ? (int) getViewportSize().getWidth()
831                    : (int) getViewportSize().getHeight();
832            int cl = (orientation == Adjustable.HORIZONTAL)
833                    ? width
834                    : height;
835            if (cp <= sp) {
836                return ScrollAdjuster.DECREASE_SCROLL_DIRECTION;
837            } else if ((cp + cl) > (sp + sl)
838                    && cp > sp) {
839                return ScrollAdjuster.INCREASE_SCROLL_DIRECTION;
840            } else {
841                return ScrollAdjuster.DO_NOT_TOUCH_SCROLL_DIRECTION;
842            }
843        }
844
845        @Override
846        public int getScrollOrientation() {
847            return orientation;
848        }
849
850        @Override
851        public String getDescription() {
852            return "";
853        }
854
855        @Override
856        public String toString() {
857            return "ComponentRectChecker{" + "comp=" + comp + ", x=" + x + ", y=" + y + ", width=" + width + ", height=" + height + ", orientation=" + orientation + '}';
858        }
859    }
860
861    /**
862     * Checks component type.
863     */
864    public static class ScrollPaneFinder extends Finder {
865
866        /**
867         * Constructs ScrollPaneFinder.
868         *
869         * @param sf other searching criteria.
870         */
871        public ScrollPaneFinder(ComponentChooser sf) {
872            super(ScrollPane.class, sf);
873        }
874
875        /**
876         * Constructs ScrollPaneFinder.
877         */
878        public ScrollPaneFinder() {
879            super(ScrollPane.class);
880        }
881    }
882}
883