JScrollPaneOperator.java revision 13978:1993af50385d
1/*
2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23package org.netbeans.jemmy.operators;
24
25import java.awt.Component;
26import java.awt.Container;
27import java.awt.Point;
28import java.awt.Rectangle;
29
30import javax.swing.JScrollBar;
31import javax.swing.JScrollPane;
32import javax.swing.JViewport;
33import javax.swing.SwingUtilities;
34import javax.swing.border.Border;
35import javax.swing.plaf.ScrollPaneUI;
36
37import org.netbeans.jemmy.ComponentChooser;
38import org.netbeans.jemmy.ComponentSearcher;
39import org.netbeans.jemmy.Outputable;
40import org.netbeans.jemmy.TestOut;
41import org.netbeans.jemmy.TimeoutExpiredException;
42import org.netbeans.jemmy.Timeoutable;
43import org.netbeans.jemmy.Timeouts;
44import org.netbeans.jemmy.drivers.scrolling.ScrollAdjuster;
45import org.netbeans.jemmy.util.EmptyVisualizer;
46
47/**
48 * <BR><BR>Timeouts used: <BR>
49 * JScrollBarOperator.OneScrollClickTimeout - time for one scroll click <BR>
50 * JScrollBarOperator.WholeScrollTimeout - time for the whole scrolling <BR>
51 * ComponentOperator.WaitComponentTimeout - time to wait component displayed
52 * <BR>.
53 *
54 * @see org.netbeans.jemmy.Timeouts
55 *
56 * @author Alexandre Iline (alexandre.iline@oracle.com)
57 *
58 */
59public class JScrollPaneOperator extends JComponentOperator
60        implements Timeoutable, Outputable {
61
62    private static int X_POINT_RECT_SIZE = 6;
63    private static int Y_POINT_RECT_SIZE = 4;
64
65    private Timeouts timeouts;
66    private TestOut output;
67    private JScrollBarOperator hScrollBarOper = null;
68    private JScrollBarOperator vScrollBarOper = null;
69
70    /**
71     * Constructor.
72     *
73     * @param b JScrollPane component.
74     */
75    public JScrollPaneOperator(JScrollPane b) {
76        super(b);
77    }
78
79    /**
80     * Constructs a JScrollPaneOperator object.
81     *
82     * @param cont a container
83     * @param chooser a component chooser specifying searching criteria.
84     * @param index an index between appropriate ones.
85     */
86    public JScrollPaneOperator(ContainerOperator<?> cont, ComponentChooser chooser, int index) {
87        this((JScrollPane) cont.
88                waitSubComponent(new JScrollPaneFinder(chooser),
89                        index));
90        copyEnvironment(cont);
91    }
92
93    /**
94     * Constructs a JScrollPaneOperator object.
95     *
96     * @param cont a container
97     * @param chooser a component chooser specifying searching criteria.
98     */
99    public JScrollPaneOperator(ContainerOperator<?> cont, ComponentChooser chooser) {
100        this(cont, chooser, 0);
101    }
102
103    /**
104     * Constructor. Waits component in container first. Uses cont's timeout and
105     * output for waiting and to init operator.
106     *
107     * @param cont Operator pointing a container to search component in.
108     * @param index Ordinal component index.
109     * @throws TimeoutExpiredException
110     */
111    public JScrollPaneOperator(ContainerOperator<?> cont, int index) {
112        this((JScrollPane) waitComponent(cont,
113                new JScrollPaneFinder(),
114                index));
115        copyEnvironment(cont);
116    }
117
118    /**
119     * Constructor. Waits component in container first. Uses cont's timeout and
120     * output for waiting and to init operator.
121     *
122     * @param cont Operator pointing a container to search component in.
123     * @throws TimeoutExpiredException
124     */
125    public JScrollPaneOperator(ContainerOperator<?> cont) {
126        this(cont, 0);
127    }
128
129    /**
130     * Searches JScrollPane in container.
131     *
132     * @param cont Container to search component in.
133     * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
134     * @param index Ordinal component index.
135     * @return JScrollPane instance or null if component was not found.
136     */
137    public static JScrollPane findJScrollPane(Container cont, ComponentChooser chooser, int index) {
138        return (JScrollPane) findComponent(cont, new JScrollPaneFinder(chooser), index);
139    }
140
141    /**
142     * Searches 0'th JScrollPane in container.
143     *
144     * @param cont Container to search component in.
145     * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
146     * @return JScrollPane instance or null if component was not found.
147     */
148    public static JScrollPane findJScrollPane(Container cont, ComponentChooser chooser) {
149        return findJScrollPane(cont, chooser, 0);
150    }
151
152    /**
153     * Searches JScrollPane in container.
154     *
155     * @param cont Container to search component in.
156     * @param index Ordinal component index.
157     * @return JScrollPane instance or null if component was not found.
158     */
159    public static JScrollPane findJScrollPane(Container cont, int index) {
160        return findJScrollPane(cont, ComponentSearcher.getTrueChooser(Integer.toString(index) + "'th JScrollPane instance"), index);
161    }
162
163    /**
164     * Searches 0'th JScrollPane in container.
165     *
166     * @param cont Container to search component in.
167     * @return JScrollPane instance or null if component was not found.
168     */
169    public static JScrollPane findJScrollPane(Container cont) {
170        return findJScrollPane(cont, 0);
171    }
172
173    /**
174     * Searches JScrollPane object which component lies on.
175     *
176     * @param comp Component to find JScrollPane under.
177     * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
178     * @return JScrollPane instance or null if component was not found.
179     */
180    public static JScrollPane findJScrollPaneUnder(Component comp, ComponentChooser chooser) {
181        return (JScrollPane) findContainerUnder(comp, new JScrollPaneFinder(chooser));
182    }
183
184    /**
185     * Searches JScrollPane object which component lies on.
186     *
187     * @param comp Component to find JScrollPane under.
188     * @return JScrollPane instance or null if component was not found.
189     */
190    public static JScrollPane findJScrollPaneUnder(Component comp) {
191        return findJScrollPaneUnder(comp, new JScrollPaneFinder());
192    }
193
194    /**
195     * Waits JScrollPane in container.
196     *
197     * @param cont Container to search component in.
198     * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
199     * @param index Ordinal component index.
200     * @return JScrollPane instance or null if component was not displayed.
201     * @throws TimeoutExpiredException
202     */
203    public static JScrollPane waitJScrollPane(Container cont, ComponentChooser chooser, int index) {
204        return (JScrollPane) waitComponent(cont, new JScrollPaneFinder(chooser), index);
205    }
206
207    /**
208     * Waits 0'th JScrollPane in container.
209     *
210     * @param cont Container to search component in.
211     * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
212     * @return JScrollPane instance or null if component was not displayed.
213     * @throws TimeoutExpiredException
214     */
215    public static JScrollPane waitJScrollPane(Container cont, ComponentChooser chooser) {
216        return waitJScrollPane(cont, chooser, 0);
217    }
218
219    /**
220     * Waits JScrollPane in container.
221     *
222     * @param cont Container to search component in.
223     * @param index Ordinal component index.
224     * @return JScrollPane instance or null if component was not displayed.
225     * @throws TimeoutExpiredException
226     */
227    public static JScrollPane waitJScrollPane(Container cont, int index) {
228        return waitJScrollPane(cont, ComponentSearcher.getTrueChooser(Integer.toString(index) + "'th JScrollPane instance"), index);
229    }
230
231    /**
232     * Waits 0'th JScrollPane in container.
233     *
234     * @param cont Container to search component in.
235     * @return JScrollPane instance or null if component was not displayed.
236     * @throws TimeoutExpiredException
237     */
238    public static JScrollPane waitJScrollPane(Container cont) {
239        return waitJScrollPane(cont, 0);
240    }
241
242    /**
243     * Sets values for both JScrollBars.
244     *
245     * @param hValue a value for the horizontal scrollbar.
246     * @param vValue a value for the vertical scrollbar.
247     */
248    public void setValues(int hValue, int vValue) {
249        initOperators();
250        hScrollBarOper.setValue(hValue);
251        vScrollBarOper.setValue(vValue);
252    }
253
254    @Override
255    public void setTimeouts(Timeouts timeouts) {
256        super.setTimeouts(timeouts);
257        this.timeouts = timeouts;
258    }
259
260    @Override
261    public Timeouts getTimeouts() {
262        return timeouts;
263    }
264
265    @Override
266    public void setOutput(TestOut out) {
267        output = out;
268        super.setOutput(output.createErrorOutput());
269    }
270
271    @Override
272    public TestOut getOutput() {
273        return output;
274    }
275
276    /**
277     * Scrolls horizontal scroll bar.
278     *
279     * @param value Value to scroll horizontal scroll bar to.
280     * @throws TimeoutExpiredException
281     */
282    public void scrollToHorizontalValue(int value) {
283        output.printTrace("Scroll JScrollPane to " + Integer.toString(value) + " horizontal value \n"
284                + toStringSource());
285        output.printGolden("Scroll JScrollPane to " + Integer.toString(value) + " horizontal value");
286        initOperators();
287        makeComponentVisible();
288        if (hScrollBarOper != null && hScrollBarOper.getSource().isVisible()) {
289            hScrollBarOper.scrollToValue(value);
290        }
291    }
292
293    /**
294     * Scrolls horizontal scroll bar.
295     *
296     * @param proportionalValue Proportional value to scroll horizontal scroll
297     * bar to.
298     * @throws TimeoutExpiredException
299     */
300    public void scrollToHorizontalValue(double proportionalValue) {
301        output.printTrace("Scroll JScrollPane to " + Double.toString(proportionalValue) + " proportional horizontal value \n"
302                + toStringSource());
303        output.printGolden("Scroll JScrollPane to " + Double.toString(proportionalValue) + " proportional horizontal value");
304        initOperators();
305        makeComponentVisible();
306        if (hScrollBarOper != null && hScrollBarOper.getSource().isVisible()) {
307            hScrollBarOper.scrollToValue(proportionalValue);
308        }
309    }
310
311    /**
312     * Scrolls vertical scroll bar.
313     *
314     * @param value Value to scroll vertical scroll bar to.
315     * @throws TimeoutExpiredException
316     */
317    public void scrollToVerticalValue(int value) {
318        output.printTrace("Scroll JScrollPane to " + Integer.toString(value) + " vertical value \n"
319                + toStringSource());
320        output.printGolden("Scroll JScrollPane to " + Integer.toString(value) + " vertical value");
321        initOperators();
322        makeComponentVisible();
323        if (vScrollBarOper != null && vScrollBarOper.getSource().isVisible()) {
324            vScrollBarOper.scrollToValue(value);
325        }
326    }
327
328    /**
329     * Scrolls vertical scroll bar.
330     *
331     * @param proportionalValue Value to scroll vertical scroll bar to.
332     * @throws TimeoutExpiredException
333     */
334    public void scrollToVerticalValue(double proportionalValue) {
335        output.printTrace("Scroll JScrollPane to " + Double.toString(proportionalValue) + " proportional vertical value \n"
336                + toStringSource());
337        output.printGolden("Scroll JScrollPane to " + Double.toString(proportionalValue) + " proportional vertical value");
338        initOperators();
339        makeComponentVisible();
340        if (vScrollBarOper != null && vScrollBarOper.getSource().isVisible()) {
341            vScrollBarOper.scrollToValue(proportionalValue);
342        }
343    }
344
345    /**
346     * Scrolls both scroll bars.
347     *
348     * @param valueX Value to scroll horizontal scroll bar to.
349     * @param valueY Value to scroll vertical scroll bar to.
350     * @throws TimeoutExpiredException
351     */
352    public void scrollToValues(int valueX, int valueY) {
353        scrollToVerticalValue(valueX);
354        scrollToHorizontalValue(valueX);
355    }
356
357    /**
358     * Scrolls both scroll bars.
359     *
360     * @param proportionalValueX Value to scroll horizontal scroll bar to.
361     * @param proportionalValueY Value to scroll vertical scroll bar to.
362     * @throws TimeoutExpiredException
363     */
364    public void scrollToValues(double proportionalValueX, double proportionalValueY) {
365        scrollToVerticalValue(proportionalValueX);
366        scrollToHorizontalValue(proportionalValueY);
367    }
368
369    /**
370     * Scrolls pane to top.
371     *
372     * @throws TimeoutExpiredException
373     */
374    public void scrollToTop() {
375        output.printTrace("Scroll JScrollPane to top\n"
376                + toStringSource());
377        output.printGolden("Scroll JScrollPane to top");
378        initOperators();
379        makeComponentVisible();
380        if (vScrollBarOper != null && vScrollBarOper.getSource().isVisible()) {
381            vScrollBarOper.scrollToMinimum();
382        }
383    }
384
385    /**
386     * Scrolls pane to bottom.
387     *
388     * @throws TimeoutExpiredException
389     */
390    public void scrollToBottom() {
391        output.printTrace("Scroll JScrollPane to bottom\n"
392                + toStringSource());
393        output.printGolden("Scroll JScrollPane to bottom");
394        initOperators();
395        makeComponentVisible();
396        if (vScrollBarOper != null && vScrollBarOper.getSource().isVisible()) {
397            vScrollBarOper.scrollToMaximum();
398        }
399    }
400
401    /**
402     * Scrolls pane to left.
403     *
404     * @throws TimeoutExpiredException
405     */
406    public void scrollToLeft() {
407        output.printTrace("Scroll JScrollPane to left\n"
408                + toStringSource());
409        output.printGolden("Scroll JScrollPane to left");
410        initOperators();
411        makeComponentVisible();
412        if (hScrollBarOper != null && hScrollBarOper.getSource().isVisible()) {
413            hScrollBarOper.scrollToMinimum();
414        }
415    }
416
417    /**
418     * Scrolls pane to right.
419     *
420     * @throws TimeoutExpiredException
421     */
422    public void scrollToRight() {
423        output.printTrace("Scroll JScrollPane to right\n"
424                + toStringSource());
425        output.printGolden("Scroll JScrollPane to right");
426        initOperators();
427        makeComponentVisible();
428        if (hScrollBarOper != null && hScrollBarOper.getSource().isVisible()) {
429            hScrollBarOper.scrollToMaximum();
430        }
431    }
432
433    /**
434     * Scrolls pane to rectangle of a component.
435     *
436     * @param comp a subcomponent defining coordinate system.
437     * @param x coordinate
438     * @param y coordinate
439     * @param width rectangle width
440     * @param height rectangle height
441     * @throws TimeoutExpiredException
442     */
443    public void scrollToComponentRectangle(Component comp, int x, int y, int width, int height) {
444        initOperators();
445        makeComponentVisible();
446        if (hScrollBarOper != null && hScrollBarOper.getSource().isVisible()) {
447            hScrollBarOper.scrollTo(new ComponentRectChecker(comp, x, y, width, height, JScrollBar.HORIZONTAL));
448        }
449        if (vScrollBarOper != null && vScrollBarOper.getSource().isVisible()) {
450            vScrollBarOper.scrollTo(new ComponentRectChecker(comp, x, y, width, height, JScrollBar.VERTICAL));
451        }
452    }
453
454    /**
455     * Scrolls pane to point.
456     *
457     * @param comp a subcomponent defining coordinate system.
458     * @param x coordinate
459     * @param y coordinate
460     * @throws TimeoutExpiredException
461     */
462    public void scrollToComponentPoint(Component comp, int x, int y) {
463        scrollToComponentRectangle(comp,
464                x - X_POINT_RECT_SIZE,
465                y - Y_POINT_RECT_SIZE,
466                2 * X_POINT_RECT_SIZE,
467                2 * Y_POINT_RECT_SIZE);
468    }
469
470    /**
471     * Scrolls pane to component on this pane. Component should lay on the
472     * JScrollPane view.
473     *
474     * @param comp Component to scroll to.
475     * @throws TimeoutExpiredException
476     */
477    public void scrollToComponent(final Component comp) {
478        String componentToString = runMapping(
479                new Operator.MapAction<String>("comp.toString()") {
480            @Override
481            public String map() {
482                return comp.toString();
483            }
484        }
485        );
486        output.printTrace("Scroll JScrollPane " + toStringSource()
487                + "\nto component " + componentToString);
488        output.printGolden("Scroll JScrollPane to " + comp.getClass().getName() + " component.");
489        scrollToComponentRectangle(comp, 0, 0, comp.getWidth(), comp.getHeight());
490    }
491
492    /**
493     * Returns operator used for horizontal scrollbar.
494     *
495     * @return an operator for the horizontal scrollbar.
496     */
497    public JScrollBarOperator getHScrollBarOperator() {
498        initOperators();
499        return hScrollBarOper;
500    }
501
502    /**
503     * Returns operator used for vertical scrollbar.
504     *
505     * @return an operator for the vertical scrollbar.
506     */
507    public JScrollBarOperator getVScrollBarOperator() {
508        initOperators();
509        return vScrollBarOper;
510    }
511
512    /**
513     * Checks if component's rectangle is inside view port (no scrolling
514     * necessary).
515     *
516     * @param comp a subcomponent defining coordinate system.
517     * @param x coordinate
518     * @param y coordinate
519     * @param width rectangle width
520     * @param height rectangle height
521     * @return true if pointed subcomponent rectangle is inside the scrolling
522     * area.
523     */
524    public boolean checkInside(Component comp, int x, int y, int width, int height) {
525        Component view = getViewport().getView();
526        Point toPoint = SwingUtilities.
527                convertPoint(comp, x, y, getViewport().getView());
528        initOperators();
529        if (hScrollBarOper != null && hScrollBarOper.getSource().isVisible()) {
530            if (toPoint.x < hScrollBarOper.getValue()) {
531                return false;
532            }
533            if (comp.getWidth() > view.getWidth()) {
534                return toPoint.x > 0;
535            } else {
536                return (toPoint.x + comp.getWidth()
537                        > hScrollBarOper.getValue() + view.getWidth());
538            }
539        }
540        if (vScrollBarOper != null && vScrollBarOper.getSource().isVisible()) {
541            if (toPoint.y < vScrollBarOper.getValue()) {
542                return false;
543            }
544            if (comp.getHeight() > view.getHeight()) {
545                return toPoint.y > 0;
546            } else {
547                return (toPoint.y + comp.getHeight()
548                        > vScrollBarOper.getValue() + view.getHeight());
549            }
550        }
551        return true;
552    }
553
554    /**
555     * Checks if component is inside view port (no scrolling necessary).
556     *
557     * @param comp a subcomponent
558     * @return true if pointed subcomponent is inside the scrolling area.
559     */
560    public boolean checkInside(Component comp) {
561        return checkInside(comp, 0, 0, comp.getWidth(), comp.getHeight());
562    }
563
564    ////////////////////////////////////////////////////////
565    //Mapping                                             //
566    /**
567     * Maps {@code JScrollPane.createHorizontalScrollBar()} through queue
568     */
569    public JScrollBar createHorizontalScrollBar() {
570        return (runMapping(new MapAction<JScrollBar>("createHorizontalScrollBar") {
571            @Override
572            public JScrollBar map() {
573                return ((JScrollPane) getSource()).createHorizontalScrollBar();
574            }
575        }));
576    }
577
578    /**
579     * Maps {@code JScrollPane.createVerticalScrollBar()} through queue
580     */
581    public JScrollBar createVerticalScrollBar() {
582        return (runMapping(new MapAction<JScrollBar>("createVerticalScrollBar") {
583            @Override
584            public JScrollBar map() {
585                return ((JScrollPane) getSource()).createVerticalScrollBar();
586            }
587        }));
588    }
589
590    /**
591     * Maps {@code JScrollPane.getColumnHeader()} through queue
592     */
593    public JViewport getColumnHeader() {
594        return (runMapping(new MapAction<JViewport>("getColumnHeader") {
595            @Override
596            public JViewport map() {
597                return ((JScrollPane) getSource()).getColumnHeader();
598            }
599        }));
600    }
601
602    /**
603     * Maps {@code JScrollPane.getCorner(String)} through queue
604     */
605    public Component getCorner(final String string) {
606        return (runMapping(new MapAction<Component>("getCorner") {
607            @Override
608            public Component map() {
609                return ((JScrollPane) getSource()).getCorner(string);
610            }
611        }));
612    }
613
614    /**
615     * Maps {@code JScrollPane.getHorizontalScrollBar()} through queue
616     */
617    public JScrollBar getHorizontalScrollBar() {
618        return (runMapping(new MapAction<JScrollBar>("getHorizontalScrollBar") {
619            @Override
620            public JScrollBar map() {
621                return ((JScrollPane) getSource()).getHorizontalScrollBar();
622            }
623        }));
624    }
625
626    /**
627     * Maps {@code JScrollPane.getHorizontalScrollBarPolicy()} through queue
628     */
629    public int getHorizontalScrollBarPolicy() {
630        return (runMapping(new MapIntegerAction("getHorizontalScrollBarPolicy") {
631            @Override
632            public int map() {
633                return ((JScrollPane) getSource()).getHorizontalScrollBarPolicy();
634            }
635        }));
636    }
637
638    /**
639     * Maps {@code JScrollPane.getRowHeader()} through queue
640     */
641    public JViewport getRowHeader() {
642        return (runMapping(new MapAction<JViewport>("getRowHeader") {
643            @Override
644            public JViewport map() {
645                return ((JScrollPane) getSource()).getRowHeader();
646            }
647        }));
648    }
649
650    /**
651     * Maps {@code JScrollPane.getUI()} through queue
652     */
653    public ScrollPaneUI getUI() {
654        return (runMapping(new MapAction<ScrollPaneUI>("getUI") {
655            @Override
656            public ScrollPaneUI map() {
657                return ((JScrollPane) getSource()).getUI();
658            }
659        }));
660    }
661
662    /**
663     * Maps {@code JScrollPane.getVerticalScrollBar()} through queue
664     */
665    public JScrollBar getVerticalScrollBar() {
666        return (runMapping(new MapAction<JScrollBar>("getVerticalScrollBar") {
667            @Override
668            public JScrollBar map() {
669                return ((JScrollPane) getSource()).getVerticalScrollBar();
670            }
671        }));
672    }
673
674    /**
675     * Maps {@code JScrollPane.getVerticalScrollBarPolicy()} through queue
676     */
677    public int getVerticalScrollBarPolicy() {
678        return (runMapping(new MapIntegerAction("getVerticalScrollBarPolicy") {
679            @Override
680            public int map() {
681                return ((JScrollPane) getSource()).getVerticalScrollBarPolicy();
682            }
683        }));
684    }
685
686    /**
687     * Maps {@code JScrollPane.getViewport()} through queue
688     */
689    public JViewport getViewport() {
690        return (runMapping(new MapAction<JViewport>("getViewport") {
691            @Override
692            public JViewport map() {
693                return ((JScrollPane) getSource()).getViewport();
694            }
695        }));
696    }
697
698    /**
699     * Maps {@code JScrollPane.getViewportBorder()} through queue
700     */
701    public Border getViewportBorder() {
702        return (runMapping(new MapAction<Border>("getViewportBorder") {
703            @Override
704            public Border map() {
705                return ((JScrollPane) getSource()).getViewportBorder();
706            }
707        }));
708    }
709
710    /**
711     * Maps {@code JScrollPane.getViewportBorderBounds()} through queue
712     */
713    public Rectangle getViewportBorderBounds() {
714        return (runMapping(new MapAction<Rectangle>("getViewportBorderBounds") {
715            @Override
716            public Rectangle map() {
717                return ((JScrollPane) getSource()).getViewportBorderBounds();
718            }
719        }));
720    }
721
722    /**
723     * Maps {@code JScrollPane.setColumnHeader(JViewport)} through queue
724     */
725    public void setColumnHeader(final JViewport jViewport) {
726        runMapping(new MapVoidAction("setColumnHeader") {
727            @Override
728            public void map() {
729                ((JScrollPane) getSource()).setColumnHeader(jViewport);
730            }
731        });
732    }
733
734    /**
735     * Maps {@code JScrollPane.setColumnHeaderView(Component)} through queue
736     */
737    public void setColumnHeaderView(final Component component) {
738        runMapping(new MapVoidAction("setColumnHeaderView") {
739            @Override
740            public void map() {
741                ((JScrollPane) getSource()).setColumnHeaderView(component);
742            }
743        });
744    }
745
746    /**
747     * Maps {@code JScrollPane.setCorner(String, Component)} through queue
748     */
749    public void setCorner(final String string, final Component component) {
750        runMapping(new MapVoidAction("setCorner") {
751            @Override
752            public void map() {
753                ((JScrollPane) getSource()).setCorner(string, component);
754            }
755        });
756    }
757
758    /**
759     * Maps {@code JScrollPane.setHorizontalScrollBar(JScrollBar)} through queue
760     */
761    public void setHorizontalScrollBar(final JScrollBar jScrollBar) {
762        runMapping(new MapVoidAction("setHorizontalScrollBar") {
763            @Override
764            public void map() {
765                ((JScrollPane) getSource()).setHorizontalScrollBar(jScrollBar);
766            }
767        });
768    }
769
770    /**
771     * Maps {@code JScrollPane.setHorizontalScrollBarPolicy(int)} through queue
772     */
773    public void setHorizontalScrollBarPolicy(final int i) {
774        runMapping(new MapVoidAction("setHorizontalScrollBarPolicy") {
775            @Override
776            public void map() {
777                ((JScrollPane) getSource()).setHorizontalScrollBarPolicy(i);
778            }
779        });
780    }
781
782    /**
783     * Maps {@code JScrollPane.setRowHeader(JViewport)} through queue
784     */
785    public void setRowHeader(final JViewport jViewport) {
786        runMapping(new MapVoidAction("setRowHeader") {
787            @Override
788            public void map() {
789                ((JScrollPane) getSource()).setRowHeader(jViewport);
790            }
791        });
792    }
793
794    /**
795     * Maps {@code JScrollPane.setRowHeaderView(Component)} through queue
796     */
797    public void setRowHeaderView(final Component component) {
798        runMapping(new MapVoidAction("setRowHeaderView") {
799            @Override
800            public void map() {
801                ((JScrollPane) getSource()).setRowHeaderView(component);
802            }
803        });
804    }
805
806    /**
807     * Maps {@code JScrollPane.setUI(ScrollPaneUI)} through queue
808     */
809    public void setUI(final ScrollPaneUI scrollPaneUI) {
810        runMapping(new MapVoidAction("setUI") {
811            @Override
812            public void map() {
813                ((JScrollPane) getSource()).setUI(scrollPaneUI);
814            }
815        });
816    }
817
818    /**
819     * Maps {@code JScrollPane.setVerticalScrollBar(JScrollBar)} through queue
820     */
821    public void setVerticalScrollBar(final JScrollBar jScrollBar) {
822        runMapping(new MapVoidAction("setVerticalScrollBar") {
823            @Override
824            public void map() {
825                ((JScrollPane) getSource()).setVerticalScrollBar(jScrollBar);
826            }
827        });
828    }
829
830    /**
831     * Maps {@code JScrollPane.setVerticalScrollBarPolicy(int)} through queue
832     */
833    public void setVerticalScrollBarPolicy(final int i) {
834        runMapping(new MapVoidAction("setVerticalScrollBarPolicy") {
835            @Override
836            public void map() {
837                ((JScrollPane) getSource()).setVerticalScrollBarPolicy(i);
838            }
839        });
840    }
841
842    /**
843     * Maps {@code JScrollPane.setViewport(JViewport)} through queue
844     */
845    public void setViewport(final JViewport jViewport) {
846        runMapping(new MapVoidAction("setViewport") {
847            @Override
848            public void map() {
849                ((JScrollPane) getSource()).setViewport(jViewport);
850            }
851        });
852    }
853
854    /**
855     * Maps {@code JScrollPane.setViewportBorder(Border)} through queue
856     */
857    public void setViewportBorder(final Border border) {
858        runMapping(new MapVoidAction("setViewportBorder") {
859            @Override
860            public void map() {
861                ((JScrollPane) getSource()).setViewportBorder(border);
862            }
863        });
864    }
865
866    /**
867     * Maps {@code JScrollPane.setViewportView(Component)} through queue
868     */
869    public void setViewportView(final Component component) {
870        runMapping(new MapVoidAction("setViewportView") {
871            @Override
872            public void map() {
873                ((JScrollPane) getSource()).setViewportView(component);
874            }
875        });
876    }
877
878    //End of mapping                                      //
879    ////////////////////////////////////////////////////////
880    private void initOperators() {
881        if (hScrollBarOper == null && getHorizontalScrollBar() != null && getHorizontalScrollBar().isVisible()) {
882            hScrollBarOper = new JScrollBarOperator(getHorizontalScrollBar());
883            hScrollBarOper.copyEnvironment(this);
884            hScrollBarOper.setVisualizer(new EmptyVisualizer());
885        }
886        if (vScrollBarOper == null && getVerticalScrollBar() != null && getVerticalScrollBar().isVisible()) {
887            vScrollBarOper = new JScrollBarOperator(getVerticalScrollBar());
888            vScrollBarOper.copyEnvironment(this);
889            vScrollBarOper.setVisualizer(new EmptyVisualizer());
890        }
891    }
892
893    private class ComponentRectChecker implements JScrollBarOperator.ScrollChecker {
894
895        Component comp;
896        int x;
897        int y;
898        int width;
899        int height;
900        int orientation;
901
902        public ComponentRectChecker(Component comp, int x, int y, int width, int height, int orientation) {
903            this.comp = comp;
904            this.x = x;
905            this.y = y;
906            this.width = width;
907            this.height = height;
908            this.orientation = orientation;
909        }
910
911        @Override
912        public int getScrollDirection(JScrollBarOperator oper) {
913            Point toPoint = SwingUtilities.
914                    convertPoint(comp, x, y, getViewport().getView());
915            int to = (orientation == JScrollBar.HORIZONTAL) ? toPoint.x : toPoint.y;
916            int ln = (orientation == JScrollBar.HORIZONTAL) ? width : height;
917            int lv = (orientation == JScrollBar.HORIZONTAL) ? getViewport().getWidth() : getViewport().getHeight();
918            int vl = oper.getValue();
919            if (to < vl) {
920                return ScrollAdjuster.DECREASE_SCROLL_DIRECTION;
921            } else if ((to + ln - 1) > (vl + lv)
922                    && to > vl) {
923                return ScrollAdjuster.INCREASE_SCROLL_DIRECTION;
924            } else {
925                return ScrollAdjuster.DO_NOT_TOUCH_SCROLL_DIRECTION;
926            }
927        }
928
929        @Override
930        public String getDescription() {
931            return "";
932        }
933
934        @Override
935        public String toString() {
936            return "ComponentRectChecker{" + "comp=" + comp + ", x=" + x + ", y=" + y + ", width=" + width + ", height=" + height + ", orientation=" + orientation + '}';
937        }
938    }
939
940    /**
941     * Checks component type.
942     */
943    public static class JScrollPaneFinder extends Finder {
944
945        /**
946         * Constructs JScrollPaneFinder.
947         *
948         * @param sf other searching criteria.
949         */
950        public JScrollPaneFinder(ComponentChooser sf) {
951            super(JScrollPane.class, sf);
952        }
953
954        /**
955         * Constructs JScrollPaneFinder.
956         */
957        public JScrollPaneFinder() {
958            super(JScrollPane.class);
959        }
960    }
961}
962