001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s): Alexandre Iline.
025: *
026: * The Original Software is the Jemmy library.
027: * The Initial Developer of the Original Software is Alexandre Iline.
028: * All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: *
041: *
042: *
043: * $Id$ $Revision$ $Date$
044: *
045: */
046:
047: package org.netbeans.jemmy.operators;
048:
049: import org.netbeans.jemmy.Action;
050: import org.netbeans.jemmy.ComponentSearcher;
051: import org.netbeans.jemmy.ComponentChooser;
052: import org.netbeans.jemmy.JemmyProperties;
053: import org.netbeans.jemmy.Outputable;
054: import org.netbeans.jemmy.TestOut;
055: import org.netbeans.jemmy.Timeoutable;
056: import org.netbeans.jemmy.TimeoutExpiredException;
057: import org.netbeans.jemmy.Timeouts;
058: import org.netbeans.jemmy.Waitable;
059: import org.netbeans.jemmy.Waiter;
060:
061: import org.netbeans.jemmy.util.EmptyVisualizer;
062:
063: import org.netbeans.jemmy.drivers.DriverManager;
064: import org.netbeans.jemmy.drivers.ScrollDriver;
065:
066: import org.netbeans.jemmy.drivers.scrolling.ScrollAdjuster;
067:
068: import org.netbeans.jemmy.util.EmptyVisualizer;
069:
070: import java.awt.Component;
071: import java.awt.Container;
072: import java.awt.Point;
073:
074: import java.awt.event.AdjustmentListener;
075:
076: import java.util.Hashtable;
077:
078: import javax.swing.BoundedRangeModel;
079: import javax.swing.JButton;
080: import javax.swing.JScrollBar;
081:
082: import javax.swing.plaf.ScrollBarUI;
083:
084: /**
085: *
086: * Operator is supposed to be used to operate with an instance of
087: * javax.swing.JScrollBar class. <BR><BR>
088: *
089: *
090: * <BR><BR>Timeouts used: <BR>
091: * JScrollBarOperator.OneScrollClickTimeout - time for one scroll click <BR>
092: * JScrollBarOperator.WholeScrollTimeout - time for the whole scrolling <BR>
093: * JScrollBarOperator.BeforeDropTimeout - to sleep before drop
094: * JScrollBarOperator.DragAndDropScrollingDelta - to sleep before drag steps
095: * ComponentOperator.WaitComponentTimeout - time to wait component displayed <BR>.
096: *
097: * @see org.netbeans.jemmy.Timeouts
098: *
099: * @author Alexandre Iline (alexandre.iline@sun.com)
100: */
101:
102: public class JScrollBarOperator extends JComponentOperator implements
103: Timeoutable, Outputable {
104:
105: /**
106: * Identifier for a "minimum" property.
107: * @see #getDump
108: */
109: public static final String MINIMUM_DPROP = "Minimum";
110:
111: /**
112: * Identifier for a "maximum" property.
113: * @see #getDump
114: */
115: public static final String MAXIMUM_DPROP = "Maximum";
116:
117: /**
118: * Identifier for a "value" property.
119: * @see #getDump
120: */
121: public static final String VALUE_DPROP = "Value";
122:
123: /**
124: * Identifier for a "orientation" property.
125: * @see #getDump
126: */
127: public static final String ORIENTATION_DPROP = "Orientation";
128:
129: /**
130: * Identifier for a "HORIZONTAL" value of "orientation" property.
131: * @see #getDump
132: */
133: public static final String HORIZONTAL_ORIENTATION_DPROP_VALUE = "HORIZONTAL";
134:
135: /**
136: * Identifier for a "VERTICAL" value of "orientation" property.
137: * @see #getDump
138: */
139: public static final String VERTICAL_ORIENTATION_DPROP_VALUE = "VERTICAL";
140:
141: private final static long ONE_SCROLL_CLICK_TIMEOUT = 0;
142: private final static long WHOLE_SCROLL_TIMEOUT = 60000;
143: private final static long BEFORE_DROP_TIMEOUT = 0;
144: private final static long DRAG_AND_DROP_SCROLLING_DELTA = 0;
145:
146: private static final int MINIMAL_PAD_SIZE = 10;
147:
148: private static final int MINIMAL_DRAGGER_SIZE = 5;
149:
150: private Timeouts timeouts;
151: private TestOut output;
152: private JButtonOperator minButtOperator;
153: private JButtonOperator maxButtOperator;
154:
155: private ScrollDriver driver;
156:
157: /**
158: * Constructor.
159: * @param b JScrollBar component.
160: */
161: public JScrollBarOperator(JScrollBar b) {
162: super (b);
163: driver = DriverManager.getScrollDriver(getClass());
164: }
165:
166: /**
167: * Constructs a JScrollBarOperator object.
168: * @param cont a container
169: * @param chooser a component chooser specifying searching criteria.
170: * @param index an index between appropriate ones.
171: */
172: public JScrollBarOperator(ContainerOperator cont,
173: ComponentChooser chooser, int index) {
174: this ((JScrollBar) cont.waitSubComponent(new JScrollBarFinder(
175: chooser), index));
176: copyEnvironment(cont);
177: }
178:
179: /**
180: * Constructs a JScrollBarOperator object.
181: * @param cont a container
182: * @param chooser a component chooser specifying searching criteria.
183: */
184: public JScrollBarOperator(ContainerOperator cont,
185: ComponentChooser chooser) {
186: this (cont, chooser, 0);
187: }
188:
189: /**
190: * Constructor.
191: * Waits component in container first.
192: * Uses cont's timeout and output for waiting and to init operator.
193: * @param cont Operator pointing a container to search component in.
194: * @param index Ordinal component index.
195: * @throws TimeoutExpiredException
196: */
197: public JScrollBarOperator(ContainerOperator cont, int index) {
198: this ((JScrollBar) waitComponent(cont, new JScrollBarFinder(),
199: index));
200: copyEnvironment(cont);
201: }
202:
203: /**
204: * Constructor.
205: * Waits component in container first.
206: * Uses cont's timeout and output for waiting and to init operator.
207: * @param cont Operator pointing a container to search component in.
208: * @throws TimeoutExpiredException
209: */
210: public JScrollBarOperator(ContainerOperator cont) {
211: this (cont, 0);
212: }
213:
214: /**
215: * Searches JScrollBar in container.
216: * @param cont Container to search component in.
217: * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
218: * @param index Ordinal component index.
219: * @return JScrollBar instance or null if component was not found.
220: */
221: public static JScrollBar findJScrollBar(Container cont,
222: ComponentChooser chooser, int index) {
223: return ((JScrollBar) findComponent(cont, new JScrollBarFinder(
224: chooser), index));
225: }
226:
227: /**
228: * Searches 0'th JScrollBar in container.
229: * @param cont Container to search component in.
230: * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
231: * @return JScrollBar instance or null if component was not found.
232: */
233: public static JScrollBar findJScrollBar(Container cont,
234: ComponentChooser chooser) {
235: return (findJScrollBar(cont, chooser, 0));
236: }
237:
238: /**
239: * Searches JScrollBar in container.
240: * @param cont Container to search component in.
241: * @param index Ordinal component index.
242: * @return JScrollBar instance or null if component was not found.
243: */
244: public static JScrollBar findJScrollBar(Container cont, int index) {
245: return (findJScrollBar(cont, ComponentSearcher
246: .getTrueChooser(Integer.toString(index)
247: + "'th JScrollBar instance"), index));
248: }
249:
250: /**
251: * Searches 0'th JScrollBar in container.
252: * @param cont Container to search component in.
253: * @return JScrollBar instance or null if component was not found.
254: */
255: public static JScrollBar findJScrollBar(Container cont) {
256: return (findJScrollBar(cont, 0));
257: }
258:
259: /**
260: * Waits JScrollBar in container.
261: * @param cont Container to search component in.
262: * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
263: * @param index Ordinal component index.
264: * @return JScrollBar instance or null if component was not displayed.
265: * @throws TimeoutExpiredException
266: */
267: public static JScrollBar waitJScrollBar(Container cont,
268: ComponentChooser chooser, int index) {
269: return ((JScrollBar) waitComponent(cont, new JScrollBarFinder(
270: chooser), index));
271: }
272:
273: /**
274: * Waits 0'th JScrollBar in container.
275: * @param cont Container to search component in.
276: * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
277: * @return JScrollBar instance or null if component was not displayed.
278: * @throws TimeoutExpiredException
279: */
280: public static JScrollBar waitJScrollBar(Container cont,
281: ComponentChooser chooser) {
282: return (waitJScrollBar(cont, chooser, 0));
283: }
284:
285: /**
286: * Waits JScrollBar in container.
287: * @param cont Container to search component in.
288: * @param index Ordinal component index.
289: * @return JScrollBar instance or null if component was not displayed.
290: * @throws TimeoutExpiredException
291: */
292: public static JScrollBar waitJScrollBar(Container cont, int index) {
293: return (waitJScrollBar(cont, ComponentSearcher
294: .getTrueChooser(Integer.toString(index)
295: + "'th JScrollBar instance"), index));
296: }
297:
298: /**
299: * Waits 0'th JScrollBar in container.
300: * @param cont Container to search component in.
301: * @return JScrollBar instance or null if component was not displayed.
302: * @throws TimeoutExpiredException
303: */
304: public static JScrollBar waitJScrollBar(Container cont) {
305: return (waitJScrollBar(cont, 0));
306: }
307:
308: static {
309: Timeouts.initDefault(
310: "JScrollBarOperator.OneScrollClickTimeout",
311: ONE_SCROLL_CLICK_TIMEOUT);
312: Timeouts.initDefault("JScrollBarOperator.WholeScrollTimeout",
313: WHOLE_SCROLL_TIMEOUT);
314: Timeouts.initDefault("JScrollBarOperator.BeforeDropTimeout",
315: BEFORE_DROP_TIMEOUT);
316: Timeouts.initDefault(
317: "JScrollBarOperator.DragAndDropScrollingDelta",
318: DRAG_AND_DROP_SCROLLING_DELTA);
319: }
320:
321: public void setOutput(TestOut out) {
322: output = out;
323: super .setOutput(output.createErrorOutput());
324: }
325:
326: public TestOut getOutput() {
327: return (output);
328: }
329:
330: public void setTimeouts(Timeouts timeouts) {
331: this .timeouts = timeouts;
332: super .setTimeouts(timeouts);
333: }
334:
335: public Timeouts getTimeouts() {
336: return (timeouts);
337: }
338:
339: public void copyEnvironment(Operator anotherOperator) {
340: super .copyEnvironment(anotherOperator);
341: driver = (ScrollDriver) DriverManager.getDriver(
342: DriverManager.SCROLL_DRIVER_ID, getClass(),
343: anotherOperator.getProperties());
344: }
345:
346: /**
347: * Does simple scroll click.
348: * @param increase a scrolling direction.
349: * @throws TimeoutExpiredException
350: * @deprecated All scrolling is done through a ScrollDriver registered to this operator type.
351: */
352: public void scroll(boolean increase) {
353: scrollToValue(getValue() + (increase ? 1 : -1));
354: }
355:
356: /**
357: * Scrolls scrollbar to the position defined by w parameter.
358: * Uses ScrollDriver registered to this operator type.
359: * @param w Scrolling is stopped when w.actionProduced(waiterParam) != null
360: * @param waiterParam a waiting parameter.
361: * @param increase a scrolling direction.
362: * @see #scrollTo(JScrollBarOperator.ScrollChecker)
363: * @throws TimeoutExpiredException
364: */
365: public void scrollTo(Waitable w, Object waiterParam,
366: boolean increase) {
367: scrollTo(new WaitableChecker(w, waiterParam, increase, this ));
368: }
369:
370: /**
371: * Scrolls scrollbar to the position defined by a ScrollChecker implementation.
372: * @param checker ScrollChecker implementation defining scrolling direction, and so on.
373: * @see ScrollChecker
374: * @throws TimeoutExpiredException
375: */
376: public void scrollTo(ScrollChecker checker) {
377: scrollTo(new CheckerAdjustable(checker, this ));
378: }
379:
380: /**
381: * Scrolls scrollbar to the position defined by a ScrollAdjuster implementation.
382: * @param adj defines scrolling direction, and so on.
383: * @throws TimeoutExpiredException
384: */
385: public void scrollTo(final ScrollAdjuster adj) {
386: initOperators();
387: produceTimeRestricted(new Action() {
388: public Object launch(Object obj) {
389: driver.scroll(JScrollBarOperator.this , adj);
390: return (null);
391: }
392:
393: public String getDescription() {
394: return ("Scrolling");
395: }
396: }, getTimeouts().getTimeout(
397: "JScrollBarOperator.WholeScrollTimeout"));
398: }
399:
400: /**
401: * Scrolls scroll bar to necessary value.
402: * @param value Scroll bar value to scroll to.
403: * @throws TimeoutExpiredException
404: */
405: public void scrollToValue(int value) {
406: output.printTrace("Scroll JScrollBar to "
407: + Integer.toString(value) + " value\n"
408: + toStringSource());
409: output.printGolden("Scroll JScrollBar to "
410: + Integer.toString(value) + " value");
411: scrollTo(new ValueScrollAdjuster(value));
412: }
413:
414: /**
415: * Scrolls scroll bar to necessary proportional value.
416: * @param proportionalValue Proportional scroll to. Must be >= 0 and <= 1.
417: * @throws TimeoutExpiredException
418: */
419: public void scrollToValue(double proportionalValue) {
420: output.printTrace("Scroll JScrollBar to "
421: + Double.toString(proportionalValue)
422: + " proportional value\n" + toStringSource());
423: output.printGolden("Scroll JScrollBar to "
424: + Double.toString(proportionalValue)
425: + " proportional value");
426: scrollTo(new ValueScrollAdjuster(
427: (int) (getMinimum() + (getMaximum()
428: - getVisibleAmount() - getMinimum())
429: * proportionalValue)));
430: }
431:
432: /**
433: * Scrolls to minimum value.
434: * @throws TimeoutExpiredException
435: */
436: public void scrollToMinimum() {
437: output.printTrace("Scroll JScrollBar to minimum value\n"
438: + toStringSource());
439: output.printGolden("Scroll JScrollBar to minimum value");
440: initOperators();
441: produceTimeRestricted(new Action() {
442: public Object launch(Object obj) {
443: driver.scrollToMinimum(JScrollBarOperator.this ,
444: getOrientation());
445: return (null);
446: }
447:
448: public String getDescription() {
449: return ("Scrolling");
450: }
451: }, getTimeouts().getTimeout(
452: "JScrollBarOperator.WholeScrollTimeout"));
453: }
454:
455: /**
456: * Scrolls to maximum value.
457: * @throws TimeoutExpiredException
458: */
459: public void scrollToMaximum() {
460: output.printTrace("Scroll JScrollBar to maximum value\n"
461: + toStringSource());
462: output.printGolden("Scroll JScrollBar to maximum value");
463: initOperators();
464: produceTimeRestricted(new Action() {
465: public Object launch(Object obj) {
466: driver.scrollToMaximum(JScrollBarOperator.this ,
467: getOrientation());
468: return (null);
469: }
470:
471: public String getDescription() {
472: return ("Scrolling");
473: }
474: }, getTimeouts().getTimeout(
475: "JScrollBarOperator.WholeScrollTimeout"));
476: }
477:
478: /**
479: * Returns a button responsible for value decreasing.
480: * @return an operator for the decrease button.
481: */
482: public JButtonOperator getDecreaseButton() {
483: initOperators();
484: return (minButtOperator);
485: }
486:
487: /**
488: * Returns a button responsible for value increasing.
489: * @return an operator for the increase button.
490: */
491: public JButtonOperator getIncreaseButton() {
492: initOperators();
493: return (maxButtOperator);
494: }
495:
496: public Hashtable getDump() {
497: Hashtable result = super .getDump();
498: result.put(MINIMUM_DPROP, Integer
499: .toString(((JScrollBar) getSource()).getMinimum()));
500: result.put(MAXIMUM_DPROP, Integer
501: .toString(((JScrollBar) getSource()).getMaximum()));
502: result
503: .put(
504: ORIENTATION_DPROP,
505: (((JScrollBar) getSource()).getOrientation() == JScrollBar.HORIZONTAL) ? HORIZONTAL_ORIENTATION_DPROP_VALUE
506: : VERTICAL_ORIENTATION_DPROP_VALUE);
507: result.put(VALUE_DPROP, Integer
508: .toString(((JScrollBar) getSource()).getValue()));
509: return (result);
510: }
511:
512: ////////////////////////////////////////////////////////
513: //Mapping //
514:
515: /**Maps <code>JScrollBar.addAdjustmentListener(AdjustmentListener)</code> through queue*/
516: public void addAdjustmentListener(
517: final AdjustmentListener adjustmentListener) {
518: runMapping(new MapVoidAction("addAdjustmentListener") {
519: public void map() {
520: ((JScrollBar) getSource())
521: .addAdjustmentListener(adjustmentListener);
522: }
523: });
524: }
525:
526: /**Maps <code>JScrollBar.getBlockIncrement()</code> through queue*/
527: public int getBlockIncrement() {
528: return (runMapping(new MapIntegerAction("getBlockIncrement") {
529: public int map() {
530: return (((JScrollBar) getSource()).getBlockIncrement());
531: }
532: }));
533: }
534:
535: /**Maps <code>JScrollBar.getBlockIncrement(int)</code> through queue*/
536: public int getBlockIncrement(final int i) {
537: return (runMapping(new MapIntegerAction("getBlockIncrement") {
538: public int map() {
539: return (((JScrollBar) getSource()).getBlockIncrement(i));
540: }
541: }));
542: }
543:
544: /**Maps <code>JScrollBar.getMaximum()</code> through queue*/
545: public int getMaximum() {
546: return (runMapping(new MapIntegerAction("getMaximum") {
547: public int map() {
548: return (((JScrollBar) getSource()).getMaximum());
549: }
550: }));
551: }
552:
553: /**Maps <code>JScrollBar.getMinimum()</code> through queue*/
554: public int getMinimum() {
555: return (runMapping(new MapIntegerAction("getMinimum") {
556: public int map() {
557: return (((JScrollBar) getSource()).getMinimum());
558: }
559: }));
560: }
561:
562: /**Maps <code>JScrollBar.getModel()</code> through queue*/
563: public BoundedRangeModel getModel() {
564: return ((BoundedRangeModel) runMapping(new MapAction("getModel") {
565: public Object map() {
566: return (((JScrollBar) getSource()).getModel());
567: }
568: }));
569: }
570:
571: /**Maps <code>JScrollBar.getOrientation()</code> through queue*/
572: public int getOrientation() {
573: return (runMapping(new MapIntegerAction("getOrientation") {
574: public int map() {
575: return (((JScrollBar) getSource()).getOrientation());
576: }
577: }));
578: }
579:
580: /**Maps <code>JScrollBar.getUI()</code> through queue*/
581: public ScrollBarUI getUI() {
582: return ((ScrollBarUI) runMapping(new MapAction("getUI") {
583: public Object map() {
584: return (((JScrollBar) getSource()).getUI());
585: }
586: }));
587: }
588:
589: /**Maps <code>JScrollBar.getUnitIncrement()</code> through queue*/
590: public int getUnitIncrement() {
591: return (runMapping(new MapIntegerAction("getUnitIncrement") {
592: public int map() {
593: return (((JScrollBar) getSource()).getUnitIncrement());
594: }
595: }));
596: }
597:
598: /**Maps <code>JScrollBar.getUnitIncrement(int)</code> through queue*/
599: public int getUnitIncrement(final int i) {
600: return (runMapping(new MapIntegerAction("getUnitIncrement") {
601: public int map() {
602: return (((JScrollBar) getSource()).getUnitIncrement(i));
603: }
604: }));
605: }
606:
607: /**Maps <code>JScrollBar.getValue()</code> through queue*/
608: public int getValue() {
609: return (runMapping(new MapIntegerAction("getValue") {
610: public int map() {
611: return (((JScrollBar) getSource()).getValue());
612: }
613: }));
614: }
615:
616: /**Maps <code>JScrollBar.getValueIsAdjusting()</code> through queue*/
617: public boolean getValueIsAdjusting() {
618: return (runMapping(new MapBooleanAction("getValueIsAdjusting") {
619: public boolean map() {
620: return (((JScrollBar) getSource())
621: .getValueIsAdjusting());
622: }
623: }));
624: }
625:
626: /**Maps <code>JScrollBar.getVisibleAmount()</code> through queue*/
627: public int getVisibleAmount() {
628: return (runMapping(new MapIntegerAction("getVisibleAmount") {
629: public int map() {
630: return (((JScrollBar) getSource()).getVisibleAmount());
631: }
632: }));
633: }
634:
635: /**Maps <code>JScrollBar.removeAdjustmentListener(AdjustmentListener)</code> through queue*/
636: public void removeAdjustmentListener(
637: final AdjustmentListener adjustmentListener) {
638: runMapping(new MapVoidAction("removeAdjustmentListener") {
639: public void map() {
640: ((JScrollBar) getSource())
641: .removeAdjustmentListener(adjustmentListener);
642: }
643: });
644: }
645:
646: /**Maps <code>JScrollBar.setBlockIncrement(int)</code> through queue*/
647: public void setBlockIncrement(final int i) {
648: runMapping(new MapVoidAction("setBlockIncrement") {
649: public void map() {
650: ((JScrollBar) getSource()).setBlockIncrement(i);
651: }
652: });
653: }
654:
655: /**Maps <code>JScrollBar.setMaximum(int)</code> through queue*/
656: public void setMaximum(final int i) {
657: runMapping(new MapVoidAction("setMaximum") {
658: public void map() {
659: ((JScrollBar) getSource()).setMaximum(i);
660: }
661: });
662: }
663:
664: /**Maps <code>JScrollBar.setMinimum(int)</code> through queue*/
665: public void setMinimum(final int i) {
666: runMapping(new MapVoidAction("setMinimum") {
667: public void map() {
668: ((JScrollBar) getSource()).setMinimum(i);
669: }
670: });
671: }
672:
673: /**Maps <code>JScrollBar.setModel(BoundedRangeModel)</code> through queue*/
674: public void setModel(final BoundedRangeModel boundedRangeModel) {
675: runMapping(new MapVoidAction("setModel") {
676: public void map() {
677: ((JScrollBar) getSource()).setModel(boundedRangeModel);
678: }
679: });
680: }
681:
682: /**Maps <code>JScrollBar.setOrientation(int)</code> through queue*/
683: public void setOrientation(final int i) {
684: runMapping(new MapVoidAction("setOrientation") {
685: public void map() {
686: ((JScrollBar) getSource()).setOrientation(i);
687: }
688: });
689: }
690:
691: /**Maps <code>JScrollBar.setUnitIncrement(int)</code> through queue*/
692: public void setUnitIncrement(final int i) {
693: runMapping(new MapVoidAction("setUnitIncrement") {
694: public void map() {
695: ((JScrollBar) getSource()).setUnitIncrement(i);
696: }
697: });
698: }
699:
700: /**Maps <code>JScrollBar.setValue(int)</code> through queue*/
701: public void setValue(final int i) {
702: runMapping(new MapVoidAction("setValue") {
703: public void map() {
704: ((JScrollBar) getSource()).setValue(i);
705: }
706: });
707: }
708:
709: /**Maps <code>JScrollBar.setValueIsAdjusting(boolean)</code> through queue*/
710: public void setValueIsAdjusting(final boolean b) {
711: runMapping(new MapVoidAction("setValueIsAdjusting") {
712: public void map() {
713: ((JScrollBar) getSource()).setValueIsAdjusting(b);
714: }
715: });
716: }
717:
718: /**Maps <code>JScrollBar.setValues(int, int, int, int)</code> through queue*/
719: public void setValues(final int i, final int i1, final int i2,
720: final int i3) {
721: runMapping(new MapVoidAction("setValues") {
722: public void map() {
723: ((JScrollBar) getSource()).setValues(i, i1, i2, i3);
724: }
725: });
726: }
727:
728: /**Maps <code>JScrollBar.setVisibleAmount(int)</code> through queue*/
729: public void setVisibleAmount(final int i) {
730: runMapping(new MapVoidAction("setVisibleAmount") {
731: public void map() {
732: ((JScrollBar) getSource()).setVisibleAmount(i);
733: }
734: });
735: }
736:
737: //End of mapping //
738: ////////////////////////////////////////////////////////
739:
740: private void initOperators() {
741: if (minButtOperator != null && maxButtOperator != null) {
742: return;
743: }
744: ComponentChooser chooser = new ComponentChooser() {
745: public boolean checkComponent(Component comp) {
746: return (comp instanceof JButton);
747: }
748:
749: public String getDescription() {
750: return ("");
751: }
752: };
753: ComponentSearcher searcher = new ComponentSearcher(
754: (Container) getSource());
755: searcher.setOutput(output.createErrorOutput());
756: JButton butt0 = (JButton) searcher.findComponent(chooser, 0);
757: JButton butt1 = (JButton) searcher.findComponent(chooser, 1);
758:
759: if (butt0 == null || butt1 == null) {
760: minButtOperator = null;
761: maxButtOperator = null;
762: return;
763: }
764:
765: JButton minButt, maxButt;
766:
767: if (((JScrollBar) getSource()).getOrientation() == JScrollBar.HORIZONTAL) {
768: if (butt0.getX() < butt1.getX()) {
769: minButt = butt0;
770: maxButt = butt1;
771: } else {
772: minButt = butt1;
773: maxButt = butt0;
774: }
775: } else {
776: if (butt0.getY() < butt1.getY()) {
777: minButt = butt0;
778: maxButt = butt1;
779: } else {
780: minButt = butt1;
781: maxButt = butt0;
782: }
783: }
784: minButtOperator = new JButtonOperator(minButt);
785: maxButtOperator = new JButtonOperator(maxButt);
786:
787: minButtOperator.copyEnvironment(this );
788: maxButtOperator.copyEnvironment(this );
789:
790: minButtOperator.setOutput(output.createErrorOutput());
791: maxButtOperator.setOutput(output.createErrorOutput());
792:
793: Timeouts times = timeouts.cloneThis();
794: times
795: .setTimeout(
796: "AbstractButtonOperator.PushButtonTimeout",
797: times
798: .getTimeout("JScrollBarOperator.OneScrollClickTimeout"));
799:
800: minButtOperator.setTimeouts(times);
801: maxButtOperator.setTimeouts(times);
802:
803: minButtOperator.setVisualizer(new EmptyVisualizer());
804: maxButtOperator.setVisualizer(new EmptyVisualizer());
805: }
806:
807: /**
808: * Interface can be used to define some kind of complicated
809: * scrolling rules.
810: */
811: public interface ScrollChecker {
812: /**
813: * Defines a scrolling direction.
814: * @param oper an operator
815: * @see org.netbeans.jemmy.drivers.scrolling.ScrollAdjuster#INCREASE_SCROLL_DIRECTION
816: * @see org.netbeans.jemmy.drivers.scrolling.ScrollAdjuster#DECREASE_SCROLL_DIRECTION
817: * @see org.netbeans.jemmy.drivers.scrolling.ScrollAdjuster#DO_NOT_TOUCH_SCROLL_DIRECTION
818: * @return one of the following values:<BR>
819: * ScrollAdjuster.INCREASE_SCROLL_DIRECTION<BR>
820: * ScrollAdjuster.DECREASE_SCROLL_DIRECTION<BR>
821: * ScrollAdjuster.DO_NOT_TOUCH_SCROLL_DIRECTION<BR>
822: */
823: public int getScrollDirection(JScrollBarOperator oper);
824:
825: /**
826: * Scrolling rules decription.
827: * @return a description
828: */
829: public String getDescription();
830: }
831:
832: private class ValueScrollAdjuster implements ScrollAdjuster {
833: int value;
834:
835: public ValueScrollAdjuster(int value) {
836: this .value = value;
837: }
838:
839: public int getScrollDirection() {
840: if (getValue() == value) {
841: return (ScrollAdjuster.DO_NOT_TOUCH_SCROLL_DIRECTION);
842: } else {
843: return ((getValue() < value) ? ScrollAdjuster.INCREASE_SCROLL_DIRECTION
844: : ScrollAdjuster.DECREASE_SCROLL_DIRECTION);
845: }
846: }
847:
848: public int getScrollOrientation() {
849: return (getOrientation());
850: }
851:
852: public String getDescription() {
853: return ("Scroll to " + Integer.toString(value) + " value");
854: }
855: }
856:
857: private class WaitableChecker implements ScrollAdjuster {
858: Waitable w;
859: Object waitParam;
860: boolean increase;
861: boolean reached = false;
862: JScrollBarOperator oper;
863:
864: public WaitableChecker(Waitable w, Object waitParam,
865: boolean increase, JScrollBarOperator oper) {
866: this .w = w;
867: this .waitParam = waitParam;
868: this .increase = increase;
869: this .oper = oper;
870: }
871:
872: public int getScrollDirection() {
873: if (!reached && w.actionProduced(waitParam) != null) {
874: reached = true;
875: }
876: if (reached) {
877: return (this .DO_NOT_TOUCH_SCROLL_DIRECTION);
878: } else {
879: return (increase ? this .INCREASE_SCROLL_DIRECTION
880: : this .DECREASE_SCROLL_DIRECTION);
881: }
882: }
883:
884: public int getScrollOrientation() {
885: return (getOrientation());
886: }
887:
888: public String getDescription() {
889: return (w.getDescription());
890: }
891: }
892:
893: private class CheckerAdjustable implements ScrollAdjuster {
894: ScrollChecker checker;
895: JScrollBarOperator oper;
896:
897: public CheckerAdjustable(ScrollChecker checker,
898: JScrollBarOperator oper) {
899: this .checker = checker;
900: this .oper = oper;
901: }
902:
903: public int getScrollDirection() {
904: return (checker.getScrollDirection(oper));
905: }
906:
907: public int getScrollOrientation() {
908: return (getOrientation());
909: }
910:
911: public String getDescription() {
912: return (checker.getDescription());
913: }
914: }
915:
916: /**
917: * Checks component type.
918: */
919: public static class JScrollBarFinder extends Finder {
920: /**
921: * Constructs JScrollBarFinder.
922: * @param sf other searching criteria.
923: */
924: public JScrollBarFinder(ComponentChooser sf) {
925: super (JScrollBar.class, sf);
926: }
927:
928: /**
929: * Constructs JScrollBarFinder.
930: */
931: public JScrollBarFinder() {
932: super (JScrollBar.class);
933: }
934: }
935: }
|