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. Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 package org.netbeans.jemmy.operators;
26 
27 import java.awt.Color;
28 import java.awt.Component;
29 import java.awt.Container;
30 import java.awt.Rectangle;
31 import java.util.Hashtable;
32 
33 import javax.swing.Icon;
34 import javax.swing.JTabbedPane;
35 import javax.swing.SingleSelectionModel;
36 import javax.swing.event.ChangeListener;
37 import javax.swing.plaf.TabbedPaneUI;
38 
39 import org.netbeans.jemmy.ComponentChooser;
40 import org.netbeans.jemmy.JemmyInputException;
41 import org.netbeans.jemmy.Outputable;
42 import org.netbeans.jemmy.TestOut;
43 import org.netbeans.jemmy.TimeoutExpiredException;
44 import org.netbeans.jemmy.drivers.DriverManager;
45 import org.netbeans.jemmy.drivers.ListDriver;
46 
47 /**
48  * <BR><BR>Timeouts used: <BR>
49  * ComponentOperator.WaitComponentTimeout - time to wait component displayed
50  * <BR>.
51  *
52  * @see org.netbeans.jemmy.Timeouts
53  *
54  * @author Alexandre Iline (alexandre.iline@oracle.com)
55  *
56  */
57 public class JTabbedPaneOperator extends JComponentOperator
58         implements Outputable {
59 
60     /**
61      * Identifier for a "selected page" property.
62      *
63      * @see #getDump
64      */
65     public static final String SELECTED_PAGE_DPROP = "Selected";
66 
67     /**
68      * Identifier for a "page" properties.
69      *
70      * @see #getDump
71      */
72     public static final String PAGE_PREFIX_DPROP = "Page";
73 
74     private TestOut output;
75     private ListDriver driver;
76 
77     /**
78      * Constructor.
79      *
80      * @param b a component
81      */
JTabbedPaneOperator(JTabbedPane b)82     public JTabbedPaneOperator(JTabbedPane b) {
83         super(b);
84         driver = DriverManager.getListDriver(getClass());
85     }
86 
87     /**
88      * Constructs a JTabbedPaneOperator object.
89      *
90      * @param cont a container
91      * @param chooser a component chooser specifying searching criteria.
92      * @param index an index between appropriate ones.
93      */
JTabbedPaneOperator(ContainerOperator<?> cont, ComponentChooser chooser, int index)94     public JTabbedPaneOperator(ContainerOperator<?> cont, ComponentChooser chooser, int index) {
95         this((JTabbedPane) cont.
96                 waitSubComponent(new JTabbedPaneFinder(chooser),
97                         index));
98         copyEnvironment(cont);
99     }
100 
101     /**
102      * Constructs a JTabbedPaneOperator object.
103      *
104      * @param cont a container
105      * @param chooser a component chooser specifying searching criteria.
106      */
JTabbedPaneOperator(ContainerOperator<?> cont, ComponentChooser chooser)107     public JTabbedPaneOperator(ContainerOperator<?> cont, ComponentChooser chooser) {
108         this(cont, chooser, 0);
109     }
110 
111     /**
112      * Constructor. Waits component by tab title first. Uses cont's timeout and
113      * output for waiting and to init operator.
114      *
115      * @param cont a container
116      * @param text Tab title.
117      * @param tabIndex a page index to check. if equal to -1, selected page is
118      * checked.
119      * @param index Ordinal component index.
120      * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
121      * @throws TimeoutExpiredException
122      */
JTabbedPaneOperator(ContainerOperator<?> cont, String text, int tabIndex, int index)123     public JTabbedPaneOperator(ContainerOperator<?> cont, String text, int tabIndex, int index) {
124         this((JTabbedPane) waitComponent(cont,
125                 new JTabbedPaneByItemFinder(text, tabIndex,
126                         cont.getComparator()),
127                 index));
128         copyEnvironment(cont);
129     }
130 
131     /**
132      * Constructor. Waits component by activetab title first. Uses cont's
133      * timeout and output for waiting and to init operator.
134      *
135      * @param cont a container
136      * @param text Title of tab which is currently selected.
137      * @param index Ordinal component index.
138      * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
139      * @throws TimeoutExpiredException
140      */
JTabbedPaneOperator(ContainerOperator<?> cont, String text, int index)141     public JTabbedPaneOperator(ContainerOperator<?> cont, String text, int index) {
142         this(cont, text, -1, index);
143     }
144 
145     /**
146      * Constructor. Waits component in container first. Uses cont's timeout and
147      * output for waiting and to init operator.
148      *
149      * @param cont a container
150      * @param text Title of tab which is currently selected.
151      * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
152      * @throws TimeoutExpiredException
153      */
JTabbedPaneOperator(ContainerOperator<?> cont, String text)154     public JTabbedPaneOperator(ContainerOperator<?> cont, String text) {
155         this(cont, text, 0);
156     }
157 
158     /**
159      * Constructor. Waits component in container first. Uses cont's timeout and
160      * output for waiting and to init operator.
161      *
162      * @param cont a container
163      * @param index Ordinal component index.
164      * @throws TimeoutExpiredException
165      */
JTabbedPaneOperator(ContainerOperator<?> cont, int index)166     public JTabbedPaneOperator(ContainerOperator<?> cont, int index) {
167         this((JTabbedPane) waitComponent(cont,
168                 new JTabbedPaneFinder(),
169                 index));
170         copyEnvironment(cont);
171     }
172 
173     /**
174      * Constructor. Waits component in container first. Uses cont's timeout and
175      * output for waiting and to init operator.
176      *
177      * @param cont a container
178      * @throws TimeoutExpiredException
179      */
JTabbedPaneOperator(ContainerOperator<?> cont)180     public JTabbedPaneOperator(ContainerOperator<?> cont) {
181         this(cont, 0);
182     }
183 
184     /**
185      * Searches JTabbedPane in container.
186      *
187      * @param cont Container to search component in.
188      * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
189      * @param index Ordinal component index.
190      * @return JTabbedPane instance or null if component was not found.
191      */
findJTabbedPane(Container cont, ComponentChooser chooser, int index)192     public static JTabbedPane findJTabbedPane(Container cont, ComponentChooser chooser, int index) {
193         return (JTabbedPane) findComponent(cont, new JTabbedPaneFinder(chooser), index);
194     }
195 
196     /**
197      * Searches 0'th JTabbedPane in container.
198      *
199      * @param cont Container to search component in.
200      * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
201      * @return JTabbedPane instance or null if component was not found.
202      */
findJTabbedPane(Container cont, ComponentChooser chooser)203     public static JTabbedPane findJTabbedPane(Container cont, ComponentChooser chooser) {
204         return findJTabbedPane(cont, chooser, 0);
205     }
206 
207     /**
208      * Searches JTabbedPane by tab title.
209      *
210      * @param cont Container to search component in.
211      * @param text Tooltip text. If null, contents is not checked.
212      * @param ce Compare text exactly.
213      * @param ccs Compare text case sensitively.
214      * @param itemIndex Tab index. if -1 selected one is checked.
215      * @param index Ordinal component index.
216      * @return JTabbedPane instance or null if component was not found.
217      * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
218      */
findJTabbedPane(Container cont, String text, boolean ce, boolean ccs, int itemIndex, int index)219     public static JTabbedPane findJTabbedPane(Container cont, String text, boolean ce, boolean ccs, int itemIndex, int index) {
220         return findJTabbedPane(cont, new JTabbedPaneByItemFinder(text, itemIndex, new DefaultStringComparator(ce, ccs)), index);
221     }
222 
223     /**
224      * Searches JTabbedPane by tab title.
225      *
226      * @param cont Container to search component in.
227      * @param text Tooltip text. If null, contents is not checked.
228      * @param ce Compare text exactly.
229      * @param ccs Compare text case sensitively.
230      * @param itemIndex Tab index. if -1 selected one is checked.
231      * @return JTabbedPane instance or null if component was not found.
232      * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
233      */
findJTabbedPane(Container cont, String text, boolean ce, boolean ccs, int itemIndex)234     public static JTabbedPane findJTabbedPane(Container cont, String text, boolean ce, boolean ccs, int itemIndex) {
235         return findJTabbedPane(cont, text, ce, ccs, itemIndex, 0);
236     }
237 
238     /**
239      * Searches JTabbedPane object which component lies on.
240      *
241      * @param comp Component to find JTabbedPane under.
242      * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
243      * @return JTabbedPane instance or null if component was not found.
244      */
findJTabbedPaneUnder(Component comp, ComponentChooser chooser)245     public static JTabbedPane findJTabbedPaneUnder(Component comp, ComponentChooser chooser) {
246         return (JTabbedPane) findContainerUnder(comp, new JTabbedPaneFinder(chooser));
247     }
248 
249     /**
250      * Searches JTabbedPane object which component lies on.
251      *
252      * @param comp Component to find JTabbedPane under.
253      * @return JTabbedPane instance or null if component was not found.
254      */
findJTabbedPaneUnder(Component comp)255     public static JTabbedPane findJTabbedPaneUnder(Component comp) {
256         return findJTabbedPaneUnder(comp, new JTabbedPaneFinder());
257     }
258 
259     /**
260      * Waits JTabbedPane in container.
261      *
262      * @param cont Container to search component in.
263      * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
264      * @param index Ordinal component index.
265      * @return JTabbedPane instance.
266      * @throws TimeoutExpiredException
267      */
waitJTabbedPane(Container cont, ComponentChooser chooser, int index)268     public static JTabbedPane waitJTabbedPane(Container cont, ComponentChooser chooser, int index) {
269         return (JTabbedPane) waitComponent(cont, new JTabbedPaneFinder(chooser), index);
270     }
271 
272     /**
273      * Waits 0'th JTabbedPane in container.
274      *
275      * @param cont Container to search component in.
276      * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
277      * @return JTabbedPane instance.
278      * @throws TimeoutExpiredException
279      */
waitJTabbedPane(Container cont, ComponentChooser chooser)280     public static JTabbedPane waitJTabbedPane(Container cont, ComponentChooser chooser) {
281         return waitJTabbedPane(cont, chooser, 0);
282     }
283 
284     /**
285      * Waits JTabbedPane by tab title.
286      *
287      * @param cont Container to search component in.
288      * @param text Tooltip text. If null, contents is not checked.
289      * @param ce Compare text exactly.
290      * @param ccs Compare text case sensitively.
291      * @param itemIndex Tab index. if -1 selected one is checked.
292      * @param index Ordinal component index.
293      * @return JTabbedPane instance.
294      * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
295      * @throws TimeoutExpiredException
296      */
waitJTabbedPane(Container cont, String text, boolean ce, boolean ccs, int itemIndex, int index)297     public static JTabbedPane waitJTabbedPane(Container cont, String text, boolean ce, boolean ccs, int itemIndex, int index) {
298         return waitJTabbedPane(cont, new JTabbedPaneByItemFinder(text, itemIndex, new DefaultStringComparator(ce, ccs)), index);
299     }
300 
301     /**
302      * Waits JTabbedPane by tab title.
303      *
304      * @param cont Container to search component in.
305      * @param text Tooltip text. If null, contents is not checked.
306      * @param ce Compare text exactly.
307      * @param ccs Compare text case sensitively.
308      * @param itemIndex Tab index. if -1 selected one is checked.
309      * @return JTabbedPane instance.
310      * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
311      * @throws TimeoutExpiredException
312      */
waitJTabbedPane(Container cont, String text, boolean ce, boolean ccs, int itemIndex)313     public static JTabbedPane waitJTabbedPane(Container cont, String text, boolean ce, boolean ccs, int itemIndex) {
314         return waitJTabbedPane(cont, text, ce, ccs, itemIndex, 0);
315     }
316 
317     @Override
setOutput(TestOut output)318     public void setOutput(TestOut output) {
319         super.setOutput(output.createErrorOutput());
320         this.output = output;
321     }
322 
323     @Override
getOutput()324     public TestOut getOutput() {
325         return output;
326     }
327 
328     @Override
copyEnvironment(Operator anotherOperator)329     public void copyEnvironment(Operator anotherOperator) {
330         super.copyEnvironment(anotherOperator);
331         driver
332                 = (ListDriver) DriverManager.
333                 getDriver(DriverManager.LIST_DRIVER_ID,
334                         getClass(),
335                         anotherOperator.getProperties());
336     }
337 
338     /**
339      * Searches tab index by tab title.
340      *
341      * @param chooser page searching criteria
342      * @return a page index.
343      * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
344      * @deprecated Use findPage(String) or findPage(String, StringComparator)
345      */
346     @Deprecated
findPage(TabPageChooser chooser)347     public int findPage(TabPageChooser chooser) {
348         for (int i = 0; i < getTabCount(); i++) {
349             if (chooser.checkPage(this, i)) {
350                 return i;
351             }
352         }
353         return -1;
354     }
355 
356     /**
357      * Searches tab index by tab title.
358      *
359      * @param title a page title.
360      * @param comparator a string comparision algorithm
361      * @return a page index.
362      * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
363      * @deprecated Use findPage(String) or findPage(String, StringComparator)
364      */
365     @Deprecated
findPage(String title, StringComparator comparator)366     public int findPage(String title, StringComparator comparator) {
367         return findPage(new BySubStringTabPageChooser(title, comparator));
368     }
369 
370     /**
371      * Searches tab index by tab title. isCaptionEqual method is used to compare
372      * page title with match.
373      *
374      * @param title a page title.
375      * @param ce Compare text exactly.
376      * @param ccs Compare text case sensitively.
377      * @return a page index.
378      * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
379      * @deprecated Use findPage(String) or findPage(String, StringComparator)
380      */
381     @Deprecated
findPage(String title, boolean ce, boolean ccs)382     public int findPage(String title, boolean ce, boolean ccs) {
383         return findPage(title, new DefaultStringComparator(ce, ccs));
384     }
385 
386     /**
387      * Searches tab index by tab title. isCaptionEqual method is used to compare
388      * page title with match. Uses StringComparator assigned to this object.
389      *
390      * @param title a page title.
391      * @return a page index.
392      */
findPage(String title)393     public int findPage(String title) {
394         return findPage(title, getComparator());
395     }
396 
397     /**
398      * Selects tab.
399      *
400      * @param index a page ordinal index.
401      * @return a root corresponding to the page.
402      */
selectPage(int index)403     public Component selectPage(int index) {
404         output.printLine("Selecting " + index + "'th page in tabbed pane\n    :" + toStringSource());
405         makeComponentVisible();
406         driver.selectItem(this, index);
407         if (getVerification()) {
408             waitSelected(index);
409         }
410         return getComponentAt(index);
411     }
412 
413     /**
414      * Selects tab.
415      *
416      * @param chooser page searching criteria
417      * @return a root corresponding to the page.
418      */
selectPage(TabPageChooser chooser)419     public Component selectPage(TabPageChooser chooser) {
420         output.printLine("Selecting \"" + chooser.getDescription()
421                 + "\" page in tabbed pane\n    :" + toStringSource());
422         return selectPage(waitPage(chooser));
423     }
424 
425     /**
426      * Selects tab.
427      *
428      * @param title a page title.
429      * @param comparator a string comparision algorithm
430      * @return a root corresponding to the page.
431      */
selectPage(String title, StringComparator comparator)432     public Component selectPage(String title, StringComparator comparator) {
433         return selectPage(new BySubStringTabPageChooser(title, comparator));
434     }
435 
436     /**
437      * Selects tab by tab title.
438      *
439      * @param title a page title.
440      * @param ce Compare text exactly.
441      * @param ccs Compare text case sensitively.
442      * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
443      * @deprecated Use selectPage(String) or selectPage(String,
444      * StringComparator)
445      * @return a root corresponding to the page.
446      */
447     @Deprecated
selectPage(String title, boolean ce, boolean ccs)448     public Component selectPage(String title, boolean ce, boolean ccs) {
449         return selectPage(title, new DefaultStringComparator(ce, ccs));
450     }
451 
452     /**
453      * Selects tab by tab title. Uses StringComparator assigned to this object.
454      *
455      * @param title a page title.
456      * @return a root corresponding to the page.
457      */
selectPage(String title)458     public Component selectPage(String title) {
459         return selectPage(title, getComparator());
460     }
461 
462     /**
463      * Wait for a page to exist.
464      *
465      * @param chooser page searching criteria
466      * @return a page index.
467      */
waitPage(final TabPageChooser chooser)468     public int waitPage(final TabPageChooser chooser) {
469         waitState(new ComponentChooser() {
470             @Override
471             public boolean checkComponent(Component comp) {
472                 return findPage(chooser) > -1;
473             }
474 
475             @Override
476             public String getDescription() {
477                 return "Tabbed with " + chooser.getDescription() + " page.";
478             }
479 
480             @Override
481             public String toString() {
482                 return "JTabbedPaneOperator.waitPage.Action{description = " + getDescription() + '}';
483             }
484         });
485         return findPage(chooser);
486     }
487 
488     /**
489      * Wait for a page to exist.
490      *
491      * @param title a page title.
492      * @param comparator a string comparision algorithm
493      * @return a page index.
494      */
waitPage(String title, StringComparator comparator)495     public int waitPage(String title, StringComparator comparator) {
496         return waitPage(new BySubStringTabPageChooser(title, comparator));
497     }
498 
499     /**
500      * Wait for a page to exist.
501      *
502      * @param title a page title.
503      * @return a page index.
504      */
waitPage(String title)505     public int waitPage(String title) {
506         return waitPage(title, getComparator());
507     }
508 
509     /**
510      * Waits for a page to be selected.
511      *
512      * @param pageIndex an index of a page to be selected.
513      */
waitSelected(final int pageIndex)514     public void waitSelected(final int pageIndex) {
515         getOutput().printLine("Wait " + Integer.toString(pageIndex) + "'th page to be "
516                 + " selected in component \n    : "
517                 + toStringSource());
518         getOutput().printGolden("Wait " + Integer.toString(pageIndex) + "'th page to be "
519                 + " selected");
520         waitState(new ComponentChooser() {
521             @Override
522             public boolean checkComponent(Component comp) {
523                 return getSelectedIndex() == pageIndex;
524             }
525 
526             @Override
527             public String getDescription() {
528                 return Integer.toString(pageIndex) + "'th page has been selected";
529             }
530 
531             @Override
532             public String toString() {
533                 return "JTabbedPaneOperator.waitSelected.ComponentChooser{description = " + getDescription() + '}';
534             }
535         });
536     }
537 
538     /**
539      * Waits for a page to be selected.
540      *
541      * @param pageTitle a title of a page to be selected.
542      */
waitSelected(final String pageTitle)543     public void waitSelected(final String pageTitle) {
544         waitSelected(findPage(pageTitle));
545     }
546 
547     @Override
getDump()548     public Hashtable<String, Object> getDump() {
549         Hashtable<String, Object> result = super.getDump();
550         if (((JTabbedPane) getSource()).getSelectedIndex() != -1) {
551             result.put(SELECTED_PAGE_DPROP, ((JTabbedPane) getSource()).
552                     getTitleAt(((JTabbedPane) getSource()).getSelectedIndex()));
553         }
554         String[] pages = new String[((JTabbedPane) getSource()).getTabCount()];
555         for (int i = 0; i < ((JTabbedPane) getSource()).getTabCount(); i++) {
556             pages[i] = ((JTabbedPane) getSource()).getTitleAt(i);
557         }
558         addToDump(result, PAGE_PREFIX_DPROP, pages);
559         return result;
560     }
561 
562     ////////////////////////////////////////////////////////
563     //Mapping                                             //
564     /**
565      * Maps {@code JTabbedPane.addChangeListener(ChangeListener)} through queue
566      */
addChangeListener(final ChangeListener changeListener)567     public void addChangeListener(final ChangeListener changeListener) {
568         runMapping(new MapVoidAction("addChangeListener") {
569             @Override
570             public void map() {
571                 ((JTabbedPane) getSource()).addChangeListener(changeListener);
572             }
573         });
574     }
575 
576     /**
577      * Maps {@code JTabbedPane.addTab(String, Component)} through queue
578      */
addTab(final String string, final Component component)579     public void addTab(final String string, final Component component) {
580         runMapping(new MapVoidAction("addTab") {
581             @Override
582             public void map() {
583                 ((JTabbedPane) getSource()).addTab(string, component);
584             }
585         });
586     }
587 
588     /**
589      * Maps {@code JTabbedPane.addTab(String, Icon, Component)} through queue
590      */
addTab(final String string, final Icon icon, final Component component)591     public void addTab(final String string, final Icon icon, final Component component) {
592         runMapping(new MapVoidAction("addTab") {
593             @Override
594             public void map() {
595                 ((JTabbedPane) getSource()).addTab(string, icon, component);
596             }
597         });
598     }
599 
600     /**
601      * Maps {@code JTabbedPane.addTab(String, Icon, Component, String)}
602      * through queue
603      */
addTab(final String string, final Icon icon, final Component component, final String string1)604     public void addTab(final String string, final Icon icon, final Component component, final String string1) {
605         runMapping(new MapVoidAction("addTab") {
606             @Override
607             public void map() {
608                 ((JTabbedPane) getSource()).addTab(string, icon, component, string1);
609             }
610         });
611     }
612 
613     /**
614      * Maps {@code JTabbedPane.getBackgroundAt(int)} through queue
615      */
getBackgroundAt(final int i)616     public Color getBackgroundAt(final int i) {
617         return (runMapping(new MapAction<Color>("getBackgroundAt") {
618             @Override
619             public Color map() {
620                 return ((JTabbedPane) getSource()).getBackgroundAt(i);
621             }
622         }));
623     }
624 
625     /**
626      * Maps {@code JTabbedPane.getBoundsAt(int)} through queue
627      */
628     public Rectangle getBoundsAt(final int i) {
629         return (runMapping(new MapAction<Rectangle>("getBoundsAt") {
630             @Override
631             public Rectangle map() {
632                 return ((JTabbedPane) getSource()).getBoundsAt(i);
633             }
634         }));
635     }
636 
637     /**
638      * Maps {@code JTabbedPane.getComponentAt(int)} through queue
639      */
640     public Component getComponentAt(final int i) {
641         return (runMapping(new MapAction<Component>("getComponentAt") {
642             @Override
643             public Component map() {
644                 return ((JTabbedPane) getSource()).getComponentAt(i);
645             }
646         }));
647     }
648 
649     /**
650      * Maps {@code JTabbedPane.getDisabledIconAt(int)} through queue
651      */
652     public Icon getDisabledIconAt(final int i) {
653         return (runMapping(new MapAction<Icon>("getDisabledIconAt") {
654             @Override
655             public Icon map() {
656                 return ((JTabbedPane) getSource()).getDisabledIconAt(i);
657             }
658         }));
659     }
660 
661     /**
662      * Maps {@code JTabbedPane.getForegroundAt(int)} through queue
663      */
664     public Color getForegroundAt(final int i) {
665         return (runMapping(new MapAction<Color>("getForegroundAt") {
666             @Override
667             public Color map() {
668                 return ((JTabbedPane) getSource()).getForegroundAt(i);
669             }
670         }));
671     }
672 
673     /**
674      * Maps {@code JTabbedPane.getIconAt(int)} through queue
675      */
676     public Icon getIconAt(final int i) {
677         return (runMapping(new MapAction<Icon>("getIconAt") {
678             @Override
679             public Icon map() {
680                 return ((JTabbedPane) getSource()).getIconAt(i);
681             }
682         }));
683     }
684 
685     /**
686      * Maps {@code JTabbedPane.getModel()} through queue
687      */
688     public SingleSelectionModel getModel() {
689         return (runMapping(new MapAction<SingleSelectionModel>("getModel") {
690             @Override
691             public SingleSelectionModel map() {
692                 return ((JTabbedPane) getSource()).getModel();
693             }
694         }));
695     }
696 
697     /**
698      * Maps {@code JTabbedPane.getSelectedComponent()} through queue
699      */
700     public Component getSelectedComponent() {
701         return (runMapping(new MapAction<Component>("getSelectedComponent") {
702             @Override
703             public Component map() {
704                 return ((JTabbedPane) getSource()).getSelectedComponent();
705             }
706         }));
707     }
708 
709     /**
710      * Maps {@code JTabbedPane.getSelectedIndex()} through queue
711      */
712     public int getSelectedIndex() {
713         return (runMapping(new MapIntegerAction("getSelectedIndex") {
714             @Override
715             public int map() {
716                 return ((JTabbedPane) getSource()).getSelectedIndex();
717             }
718         }));
719     }
720 
721     /**
722      * Maps {@code JTabbedPane.getTabCount()} through queue
723      */
724     public int getTabCount() {
725         return (runMapping(new MapIntegerAction("getTabCount") {
726             @Override
727             public int map() {
728                 return ((JTabbedPane) getSource()).getTabCount();
729             }
730         }));
731     }
732 
733     /**
734      * Maps {@code JTabbedPane.getTabPlacement()} through queue
735      */
736     public int getTabPlacement() {
737         return (runMapping(new MapIntegerAction("getTabPlacement") {
738             @Override
739             public int map() {
740                 return ((JTabbedPane) getSource()).getTabPlacement();
741             }
742         }));
743     }
744 
745     /**
746      * Maps {@code JTabbedPane.getTabRunCount()} through queue
747      */
748     public int getTabRunCount() {
749         return (runMapping(new MapIntegerAction("getTabRunCount") {
750             @Override
751             public int map() {
752                 return ((JTabbedPane) getSource()).getTabRunCount();
753             }
754         }));
755     }
756 
757     /**
758      * Maps {@code JTabbedPane.getTitleAt(int)} through queue
759      */
760     public String getTitleAt(final int i) {
761         return (runMapping(new MapAction<String>("getTitleAt") {
762             @Override
763             public String map() {
764                 return ((JTabbedPane) getSource()).getTitleAt(i);
765             }
766         }));
767     }
768 
769     /**
770      * Maps {@code JTabbedPane.getUI()} through queue
771      */
772     public TabbedPaneUI getUI() {
773         return (runMapping(new MapAction<TabbedPaneUI>("getUI") {
774             @Override
775             public TabbedPaneUI map() {
776                 return ((JTabbedPane) getSource()).getUI();
777             }
778         }));
779     }
780 
781     /**
782      * Maps {@code JTabbedPane.indexOfComponent(Component)} through queue
783      */
784     public int indexOfComponent(final Component component) {
785         return (runMapping(new MapIntegerAction("indexOfComponent") {
786             @Override
787             public int map() {
788                 return ((JTabbedPane) getSource()).indexOfComponent(component);
789             }
790         }));
791     }
792 
793     /**
794      * Maps {@code JTabbedPane.indexOfTab(String)} through queue
795      */
796     public int indexOfTab(final String string) {
797         return (runMapping(new MapIntegerAction("indexOfTab") {
798             @Override
799             public int map() {
800                 return ((JTabbedPane) getSource()).indexOfTab(string);
801             }
802         }));
803     }
804 
805     /**
806      * Maps {@code JTabbedPane.indexOfTab(Icon)} through queue
807      */
808     public int indexOfTab(final Icon icon) {
809         return (runMapping(new MapIntegerAction("indexOfTab") {
810             @Override
811             public int map() {
812                 return ((JTabbedPane) getSource()).indexOfTab(icon);
813             }
814         }));
815     }
816 
817     /**
818      * Maps
819      * {@code JTabbedPane.insertTab(String, Icon, Component, String, int)}
820      * through queue
821      */
822     public void insertTab(final String string, final Icon icon, final Component component, final String string1, final int i) {
823         runMapping(new MapVoidAction("insertTab") {
824             @Override
825             public void map() {
826                 ((JTabbedPane) getSource()).insertTab(string, icon, component, string1, i);
827             }
828         });
829     }
830 
831     /**
832      * Maps {@code JTabbedPane.isEnabledAt(int)} through queue
833      */
834     public boolean isEnabledAt(final int i) {
835         return (runMapping(new MapBooleanAction("isEnabledAt") {
836             @Override
837             public boolean map() {
838                 return ((JTabbedPane) getSource()).isEnabledAt(i);
839             }
840         }));
841     }
842 
843     /**
844      * Maps {@code JTabbedPane.removeChangeListener(ChangeListener)}
845      * through queue
846      */
847     public void removeChangeListener(final ChangeListener changeListener) {
848         runMapping(new MapVoidAction("removeChangeListener") {
849             @Override
850             public void map() {
851                 ((JTabbedPane) getSource()).removeChangeListener(changeListener);
852             }
853         });
854     }
855 
856     /**
857      * Maps {@code JTabbedPane.removeTabAt(int)} through queue
858      */
859     public void removeTabAt(final int i) {
860         runMapping(new MapVoidAction("removeTabAt") {
861             @Override
862             public void map() {
863                 ((JTabbedPane) getSource()).removeTabAt(i);
864             }
865         });
866     }
867 
868     /**
869      * Maps {@code JTabbedPane.setBackgroundAt(int, Color)} through queue
870      */
871     public void setBackgroundAt(final int i, final Color color) {
872         runMapping(new MapVoidAction("setBackgroundAt") {
873             @Override
874             public void map() {
875                 ((JTabbedPane) getSource()).setBackgroundAt(i, color);
876             }
877         });
878     }
879 
880     /**
881      * Maps {@code JTabbedPane.setComponentAt(int, Component)} through queue
882      */
883     public void setComponentAt(final int i, final Component component) {
884         runMapping(new MapVoidAction("setComponentAt") {
885             @Override
886             public void map() {
887                 ((JTabbedPane) getSource()).setComponentAt(i, component);
888             }
889         });
890     }
891 
892     /**
893      * Maps {@code JTabbedPane.setDisabledIconAt(int, Icon)} through queue
894      */
895     public void setDisabledIconAt(final int i, final Icon icon) {
896         runMapping(new MapVoidAction("setDisabledIconAt") {
897             @Override
898             public void map() {
899                 ((JTabbedPane) getSource()).setDisabledIconAt(i, icon);
900             }
901         });
902     }
903 
904     /**
905      * Maps {@code JTabbedPane.setEnabledAt(int, boolean)} through queue
906      */
907     public void setEnabledAt(final int i, final boolean b) {
908         runMapping(new MapVoidAction("setEnabledAt") {
909             @Override
910             public void map() {
911                 ((JTabbedPane) getSource()).setEnabledAt(i, b);
912             }
913         });
914     }
915 
916     /**
917      * Maps {@code JTabbedPane.setForegroundAt(int, Color)} through queue
918      */
919     public void setForegroundAt(final int i, final Color color) {
920         runMapping(new MapVoidAction("setForegroundAt") {
921             @Override
922             public void map() {
923                 ((JTabbedPane) getSource()).setForegroundAt(i, color);
924             }
925         });
926     }
927 
928     /**
929      * Maps {@code JTabbedPane.setIconAt(int, Icon)} through queue
930      */
931     public void setIconAt(final int i, final Icon icon) {
932         runMapping(new MapVoidAction("setIconAt") {
933             @Override
934             public void map() {
935                 ((JTabbedPane) getSource()).setIconAt(i, icon);
936             }
937         });
938     }
939 
940     /**
941      * Maps {@code JTabbedPane.setModel(SingleSelectionModel)} through queue
942      */
943     public void setModel(final SingleSelectionModel singleSelectionModel) {
944         runMapping(new MapVoidAction("setModel") {
945             @Override
946             public void map() {
947                 ((JTabbedPane) getSource()).setModel(singleSelectionModel);
948             }
949         });
950     }
951 
952     /**
953      * Maps {@code JTabbedPane.setSelectedComponent(Component)} through queue
954      */
955     public void setSelectedComponent(final Component component) {
956         runMapping(new MapVoidAction("setSelectedComponent") {
957             @Override
958             public void map() {
959                 ((JTabbedPane) getSource()).setSelectedComponent(component);
960             }
961         });
962     }
963 
964     /**
965      * Maps {@code JTabbedPane.setSelectedIndex(int)} through queue
966      */
967     public void setSelectedIndex(final int i) {
968         runMapping(new MapVoidAction("setSelectedIndex") {
969             @Override
970             public void map() {
971                 ((JTabbedPane) getSource()).setSelectedIndex(i);
972             }
973         });
974     }
975 
976     /**
977      * Maps {@code JTabbedPane.setTabPlacement(int)} through queue
978      */
979     public void setTabPlacement(final int i) {
980         runMapping(new MapVoidAction("setTabPlacement") {
981             @Override
982             public void map() {
983                 ((JTabbedPane) getSource()).setTabPlacement(i);
984             }
985         });
986     }
987 
988     /**
989      * Maps {@code JTabbedPane.setTitleAt(int, String)} through queue
990      */
991     public void setTitleAt(final int i, final String string) {
992         runMapping(new MapVoidAction("setTitleAt") {
993             @Override
994             public void map() {
995                 ((JTabbedPane) getSource()).setTitleAt(i, string);
996             }
997         });
998     }
999 
1000     /**
1001      * Maps {@code JTabbedPane.setUI(TabbedPaneUI)} through queue
1002      */
1003     public void setUI(final TabbedPaneUI tabbedPaneUI) {
1004         runMapping(new MapVoidAction("setUI") {
1005             @Override
1006             public void map() {
1007                 ((JTabbedPane) getSource()).setUI(tabbedPaneUI);
1008             }
1009         });
1010     }
1011 
1012     //End of mapping                                      //
1013     ////////////////////////////////////////////////////////
1014     /**
1015      * Specifies criteria for a tab page searching.
1016      */
1017     public interface TabPageChooser {
1018 
1019         /**
1020          * Should be true if a page is good.
1021          *
1022          * @param oper Operator used to search item.
1023          * @param index Index of a page be checked.
1024          * @return true if a page fits the criteria.
1025          */
1026         public boolean checkPage(JTabbedPaneOperator oper, int index);
1027 
1028         /**
1029          * Page description.
1030          *
1031          * @return a description.
1032          */
1033         public String getDescription();
1034     }
1035 
1036     /**
1037      * Exception is thrown if a nonexistent page is trying to be selected.
1038      */
1039     public class NoSuchPageException extends JemmyInputException {
1040 
1041         private static final long serialVersionUID = 42L;
1042 
1043         /**
1044          * Constructor.
1045          *
1046          * @param item nonexistent page title.
1047          */
1048         public NoSuchPageException(String item) {
1049             super("No such page as \"" + item + "\"", getSource());
1050         }
1051     }
1052 
1053     /**
1054      * Allows to find component by page title.
1055      */
1056     public static class JTabbedPaneByItemFinder implements ComponentChooser {
1057 
1058         String title;
1059         int itemIndex;
1060         StringComparator comparator;
1061 
1062         /**
1063          * Constructs JTabbedPaneByItemFinder.
1064          *
1065          * @param lb a text pattern
1066          * @param ii page index to check. If equal to -1, selected page is
1067          * checked.
1068          * @param comparator specifies string comparision algorithm.
1069          */
1070         public JTabbedPaneByItemFinder(String lb, int ii, StringComparator comparator) {
1071             title = lb;
1072             itemIndex = ii;
1073             this.comparator = comparator;
1074         }
1075 
1076         /**
1077          * Constructs JTabbedPaneByItemFinder.
1078          *
1079          * @param lb a text pattern
1080          * @param ii page index to check. If equal to -1, selected page is
1081          * checked.
1082          */
1083         public JTabbedPaneByItemFinder(String lb, int ii) {
1084             this(lb, ii, Operator.getDefaultStringComparator());
1085         }
1086 
1087         @Override
1088         public boolean checkComponent(Component comp) {
1089             if (comp instanceof JTabbedPane) {
1090                 if (title == null) {
1091                     return true;
1092                 }
1093                 JTabbedPaneOperator tpo = new JTabbedPaneOperator((JTabbedPane) comp);
1094                 if (tpo.getTabCount() > itemIndex) {
1095                     int ii = itemIndex;
1096                     if (ii == -1) {
1097                         ii = tpo.getSelectedIndex();
1098                         if (ii == -1) {
1099                             return false;
1100                         }
1101                     }
1102                     return (comparator.equals(tpo.getTitleAt(ii),
1103                             title));
1104                 }
1105             }
1106             return false;
1107         }
1108 
1109         @Override
1110         public String getDescription() {
1111             return ("JTabbedPane with text \"" + title + "\" in "
1112                     + itemIndex + "'th item");
1113         }
1114 
1115         @Override
1116         public String toString() {
1117             return "JTabbedPaneByItemFinder{" + "title=" + title + ", itemIndex=" + itemIndex + ", comparator=" + comparator + '}';
1118         }
1119     }
1120 
1121     /**
1122      * Checks component type.
1123      */
1124     public static class JTabbedPaneFinder extends Finder {
1125 
1126         /**
1127          * Constructs JTabbedPaneFinder.
1128          *
1129          * @param sf other searching criteria.
1130          */
1131         public JTabbedPaneFinder(ComponentChooser sf) {
1132             super(JTabbedPane.class, sf);
1133         }
1134 
1135         /**
1136          * Constructs JTabbedPaneFinder.
1137          */
1138         public JTabbedPaneFinder() {
1139             super(JTabbedPane.class);
1140         }
1141     }
1142 
1143     private static class BySubStringTabPageChooser implements TabPageChooser {
1144 
1145         String title;
1146         StringComparator comparator;
1147 
1148         public BySubStringTabPageChooser(String title, StringComparator comparator) {
1149             this.title = title;
1150             this.comparator = comparator;
1151         }
1152 
1153         @Override
1154         public boolean checkPage(JTabbedPaneOperator oper, int index) {
1155             return (comparator.equals(oper.getTitleAt(index),
1156                     title));
1157         }
1158 
1159         @Override
1160         public String getDescription() {
1161             return "Page having \"" + title + "\" title.";
1162         }
1163 
1164         @Override
1165         public String toString() {
1166             return "BySubStringTabPageChooser{" + "title=" + title + ", comparator=" + comparator + '}';
1167         }
1168     }
1169 
1170 }
1171