0001: /*
0002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003: *
0004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005: *
0006: * The contents of this file are subject to the terms of either the GNU
0007: * General Public License Version 2 only ("GPL") or the Common
0008: * Development and Distribution License("CDDL") (collectively, the
0009: * "License"). You may not use this file except in compliance with the
0010: * License. You can obtain a copy of the License at
0011: * http://www.netbeans.org/cddl-gplv2.html
0012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013: * specific language governing permissions and limitations under the
0014: * License. When distributing the software, include this License Header
0015: * Notice in each file and include the License file at
0016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
0017: * particular file as subject to the "Classpath" exception as provided
0018: * by Sun in the GPL Version 2 section of the License file that
0019: * accompanied this code. If applicable, add the following below the
0020: * License Header, with the fields enclosed by brackets [] replaced by
0021: * your own identifying information:
0022: * "Portions Copyrighted [year] [name of copyright owner]"
0023: *
0024: * Contributor(s): Alexandre Iline.
0025: *
0026: * The Original Software is the Jemmy library.
0027: * The Initial Developer of the Original Software is Alexandre Iline.
0028: * All Rights Reserved.
0029: *
0030: * If you wish your version of this file to be governed by only the CDDL
0031: * or only the GPL Version 2, indicate your decision by adding
0032: * "[Contributor] elects to include this software in this distribution
0033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034: * single choice of license, a recipient has the option to distribute
0035: * your version of this file under either the CDDL, the GPL Version 2 or
0036: * to extend the choice of license to its licensees as provided above.
0037: * However, if you add GPL Version 2 code and therefore, elected the GPL
0038: * Version 2 license, then the option applies only if the new code is
0039: * made subject to such option by the copyright holder.
0040: *
0041: *
0042: *
0043: * $Id: JTabbedPaneOperator.java,v 1.15 2007/10/05 11:35:50 jskrivanek Exp $ $Revision: 1.15 $ $Date: 2007/10/05 11:35:50 $
0044: *
0045: */
0046:
0047: package org.netbeans.jemmy.operators;
0048:
0049: import org.netbeans.jemmy.ComponentChooser;
0050: import org.netbeans.jemmy.ComponentSearcher;
0051: import org.netbeans.jemmy.JemmyInputException;
0052: import org.netbeans.jemmy.Outputable;
0053: import org.netbeans.jemmy.TestOut;
0054: import org.netbeans.jemmy.TimeoutExpiredException;
0055:
0056: import org.netbeans.jemmy.drivers.DriverManager;
0057: import org.netbeans.jemmy.drivers.ListDriver;
0058:
0059: import java.awt.Color;
0060: import java.awt.Component;
0061: import java.awt.Container;
0062: import java.awt.Rectangle;
0063:
0064: import java.util.Hashtable;
0065:
0066: import javax.swing.Icon;
0067: import javax.swing.JTabbedPane;
0068: import javax.swing.SingleSelectionModel;
0069:
0070: import javax.swing.event.ChangeListener;
0071:
0072: import javax.swing.plaf.TabbedPaneUI;
0073:
0074: /**
0075: * <BR><BR>Timeouts used: <BR>
0076: * ComponentOperator.WaitComponentTimeout - time to wait component displayed <BR>.
0077: *
0078: * @see org.netbeans.jemmy.Timeouts
0079: *
0080: * @author Alexandre Iline (alexandre.iline@sun.com)
0081: *
0082: */
0083:
0084: public class JTabbedPaneOperator extends JComponentOperator implements
0085: Outputable {
0086:
0087: /**
0088: * Identifier for a "selected page" property.
0089: * @see #getDump
0090: */
0091: public static final String SELECTED_PAGE_DPROP = "Selected";
0092:
0093: /**
0094: * Identifier for a "page" properties.
0095: * @see #getDump
0096: */
0097: public static final String PAGE_PREFIX_DPROP = "Page";
0098:
0099: private TestOut output;
0100: private ListDriver driver;
0101:
0102: /**
0103: * Constructor.
0104: * @param b a component
0105: */
0106: public JTabbedPaneOperator(JTabbedPane b) {
0107: super (b);
0108: driver = DriverManager.getListDriver(getClass());
0109: }
0110:
0111: /**
0112: * Constructs a JTabbedPaneOperator object.
0113: * @param cont a container
0114: * @param chooser a component chooser specifying searching criteria.
0115: * @param index an index between appropriate ones.
0116: */
0117: public JTabbedPaneOperator(ContainerOperator cont,
0118: ComponentChooser chooser, int index) {
0119: this ((JTabbedPane) cont.waitSubComponent(new JTabbedPaneFinder(
0120: chooser), index));
0121: copyEnvironment(cont);
0122: }
0123:
0124: /**
0125: * Constructs a JTabbedPaneOperator object.
0126: * @param cont a container
0127: * @param chooser a component chooser specifying searching criteria.
0128: */
0129: public JTabbedPaneOperator(ContainerOperator cont,
0130: ComponentChooser chooser) {
0131: this (cont, chooser, 0);
0132: }
0133:
0134: /**
0135: * Constructor.
0136: * Waits component by tab title first.
0137: * Uses cont's timeout and output for waiting and to init operator.
0138: * @param cont a container
0139: * @param text Tab title.
0140: * @param tabIndex a page index to check. if equal to -1, selected page is checked.
0141: * @param index Ordinal component index.
0142: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0143: * @throws TimeoutExpiredException
0144: */
0145: public JTabbedPaneOperator(ContainerOperator cont, String text,
0146: int tabIndex, int index) {
0147: this ((JTabbedPane) waitComponent(cont,
0148: new JTabbedPaneByItemFinder(text, tabIndex, cont
0149: .getComparator()), index));
0150: copyEnvironment(cont);
0151: }
0152:
0153: /**
0154: * Constructor.
0155: * Waits component by activetab title first.
0156: * Uses cont's timeout and output for waiting and to init operator.
0157: * @param cont a container
0158: * @param text Title of tab which is currently selected.
0159: * @param index Ordinal component index.
0160: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0161: * @throws TimeoutExpiredException
0162: */
0163: public JTabbedPaneOperator(ContainerOperator cont, String text,
0164: int index) {
0165: this (cont, text, -1, index);
0166: }
0167:
0168: /**
0169: * Constructor.
0170: * Waits component in container first.
0171: * Uses cont's timeout and output for waiting and to init operator.
0172: * @param cont a container
0173: * @param text Title of tab which is currently selected.
0174: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0175: * @throws TimeoutExpiredException
0176: */
0177: public JTabbedPaneOperator(ContainerOperator cont, String text) {
0178: this (cont, text, 0);
0179: }
0180:
0181: /**
0182: * Constructor.
0183: * Waits component in container first.
0184: * Uses cont's timeout and output for waiting and to init operator.
0185: * @param cont a container
0186: * @param index Ordinal component index.
0187: * @throws TimeoutExpiredException
0188: */
0189: public JTabbedPaneOperator(ContainerOperator cont, int index) {
0190: this ((JTabbedPane) waitComponent(cont, new JTabbedPaneFinder(),
0191: index));
0192: copyEnvironment(cont);
0193: }
0194:
0195: /**
0196: * Constructor.
0197: * Waits component in container first.
0198: * Uses cont's timeout and output for waiting and to init operator.
0199: * @param cont a container
0200: * @throws TimeoutExpiredException
0201: */
0202: public JTabbedPaneOperator(ContainerOperator cont) {
0203: this (cont, 0);
0204: }
0205:
0206: /**
0207: * Searches JTabbedPane in container.
0208: * @param cont Container to search component in.
0209: * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
0210: * @param index Ordinal component index.
0211: * @return JTabbedPane instance or null if component was not found.
0212: */
0213: public static JTabbedPane findJTabbedPane(Container cont,
0214: ComponentChooser chooser, int index) {
0215: return ((JTabbedPane) findComponent(cont,
0216: new JTabbedPaneFinder(chooser), index));
0217: }
0218:
0219: /**
0220: * Searches 0'th JTabbedPane in container.
0221: * @param cont Container to search component in.
0222: * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
0223: * @return JTabbedPane instance or null if component was not found.
0224: */
0225: public static JTabbedPane findJTabbedPane(Container cont,
0226: ComponentChooser chooser) {
0227: return (findJTabbedPane(cont, chooser, 0));
0228: }
0229:
0230: /**
0231: * Searches JTabbedPane by tab title.
0232: * @param cont Container to search component in.
0233: * @param text Tooltip text. If null, contents is not checked.
0234: * @param ce Compare text exactly.
0235: * @param ccs Compare text case sensitively.
0236: * @param itemIndex Tab index. if -1 selected one is checked.
0237: * @param index Ordinal component index.
0238: * @return JTabbedPane instance or null if component was not found.
0239: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0240: */
0241: public static JTabbedPane findJTabbedPane(Container cont,
0242: String text, boolean ce, boolean ccs, int itemIndex,
0243: int index) {
0244: return (findJTabbedPane(cont, new JTabbedPaneByItemFinder(text,
0245: itemIndex, new DefaultStringComparator(ce, ccs)), index));
0246: }
0247:
0248: /**
0249: * Searches JTabbedPane by tab title.
0250: * @param cont Container to search component in.
0251: * @param text Tooltip text. If null, contents is not checked.
0252: * @param ce Compare text exactly.
0253: * @param ccs Compare text case sensitively.
0254: * @param itemIndex Tab index. if -1 selected one is checked.
0255: * @return JTabbedPane instance or null if component was not found.
0256: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0257: */
0258: public static JTabbedPane findJTabbedPane(Container cont,
0259: String text, boolean ce, boolean ccs, int itemIndex) {
0260: return (findJTabbedPane(cont, text, ce, ccs, itemIndex, 0));
0261: }
0262:
0263: /**
0264: * Searches JTabbedPane object which component lies on.
0265: * @param comp Component to find JTabbedPane under.
0266: * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
0267: * @return JTabbedPane instance or null if component was not found.
0268: */
0269: public static JTabbedPane findJTabbedPaneUnder(Component comp,
0270: ComponentChooser chooser) {
0271: return ((JTabbedPane) findContainerUnder(comp,
0272: new JTabbedPaneFinder(chooser)));
0273: }
0274:
0275: /**
0276: * Searches JTabbedPane object which component lies on.
0277: * @param comp Component to find JTabbedPane under.
0278: * @return JTabbedPane instance or null if component was not found.
0279: */
0280: public static JTabbedPane findJTabbedPaneUnder(Component comp) {
0281: return (findJTabbedPaneUnder(comp, new JTabbedPaneFinder()));
0282: }
0283:
0284: /**
0285: * Waits JTabbedPane in container.
0286: * @param cont Container to search component in.
0287: * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
0288: * @param index Ordinal component index.
0289: * @return JTabbedPane instance.
0290: * @throws TimeoutExpiredException
0291: */
0292: public static JTabbedPane waitJTabbedPane(Container cont,
0293: ComponentChooser chooser, int index) {
0294: return ((JTabbedPane) waitComponent(cont,
0295: new JTabbedPaneFinder(chooser), index));
0296: }
0297:
0298: /**
0299: * Waits 0'th JTabbedPane in container.
0300: * @param cont Container to search component in.
0301: * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
0302: * @return JTabbedPane instance.
0303: * @throws TimeoutExpiredException
0304: */
0305: public static JTabbedPane waitJTabbedPane(Container cont,
0306: ComponentChooser chooser) {
0307: return (waitJTabbedPane(cont, chooser, 0));
0308: }
0309:
0310: /**
0311: * Waits JTabbedPane by tab title.
0312: * @param cont Container to search component in.
0313: * @param text Tooltip text. If null, contents is not checked.
0314: * @param ce Compare text exactly.
0315: * @param ccs Compare text case sensitively.
0316: * @param itemIndex Tab index. if -1 selected one is checked.
0317: * @param index Ordinal component index.
0318: * @return JTabbedPane instance.
0319: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0320: * @throws TimeoutExpiredException
0321: */
0322: public static JTabbedPane waitJTabbedPane(Container cont,
0323: String text, boolean ce, boolean ccs, int itemIndex,
0324: int index) {
0325: return (waitJTabbedPane(cont, new JTabbedPaneByItemFinder(text,
0326: itemIndex, new DefaultStringComparator(ce, ccs)), index));
0327: }
0328:
0329: /**
0330: * Waits JTabbedPane by tab title.
0331: * @param cont Container to search component in.
0332: * @param text Tooltip text. If null, contents is not checked.
0333: * @param ce Compare text exactly.
0334: * @param ccs Compare text case sensitively.
0335: * @param itemIndex Tab index. if -1 selected one is checked.
0336: * @return JTabbedPane instance.
0337: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0338: * @throws TimeoutExpiredException
0339: */
0340: public static JTabbedPane waitJTabbedPane(Container cont,
0341: String text, boolean ce, boolean ccs, int itemIndex) {
0342: return (waitJTabbedPane(cont, text, ce, ccs, itemIndex, 0));
0343: }
0344:
0345: public void setOutput(TestOut output) {
0346: super .setOutput(output.createErrorOutput());
0347: this .output = output;
0348: }
0349:
0350: public TestOut getOutput() {
0351: return (output);
0352: }
0353:
0354: public void copyEnvironment(Operator anotherOperator) {
0355: super .copyEnvironment(anotherOperator);
0356: driver = (ListDriver) DriverManager.getDriver(
0357: DriverManager.LIST_DRIVER_ID, getClass(),
0358: anotherOperator.getProperties());
0359: }
0360:
0361: /**
0362: * Searches tab index by tab title.
0363: * @param chooser page searching criteria
0364: * @return a page index.
0365: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0366: * @deprecated Use findPage(String) or findPage(String, StringComparator)
0367: */
0368: public int findPage(TabPageChooser chooser) {
0369: for (int i = 0; i < getTabCount(); i++) {
0370: if (chooser.checkPage(this , i)) {
0371: return (i);
0372: }
0373: }
0374: return (-1);
0375: }
0376:
0377: /**
0378: * Searches tab index by tab title.
0379: * @param title a page title.
0380: * @param comparator a string comparision algorithm
0381: * @return a page index.
0382: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0383: * @deprecated Use findPage(String) or findPage(String, StringComparator)
0384: */
0385: public int findPage(String title, StringComparator comparator) {
0386: return (findPage(new BySubStringTabPageChooser(title,
0387: comparator)));
0388: }
0389:
0390: /**
0391: * Searches tab index by tab title.
0392: * isCaptionEqual method is used to compare page title with
0393: * match.
0394: * @param title a page title.
0395: * @param ce Compare text exactly.
0396: * @param ccs Compare text case sensitively.
0397: * @return a page index.
0398: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0399: * @deprecated Use findPage(String) or findPage(String, StringComparator)
0400: */
0401: public int findPage(String title, boolean ce, boolean ccs) {
0402: return (findPage(title, new DefaultStringComparator(ce, ccs)));
0403: }
0404:
0405: /**
0406: * Searches tab index by tab title.
0407: * isCaptionEqual method is used to compare page title with
0408: * match.
0409: * Uses StringComparator assigned to this object.
0410: * @param title a page title.
0411: * @return a page index.
0412: */
0413: public int findPage(String title) {
0414: return (findPage(title, getComparator()));
0415: }
0416:
0417: /**
0418: * Selects tab.
0419: * @param index a page ordinal index.
0420: * @return a root corresponding to the page.
0421: */
0422: public Component selectPage(int index) {
0423: output.printLine("Selecting " + index
0424: + "'th page in tabbed pane\n :" + toStringSource());
0425: makeComponentVisible();
0426: driver.selectItem(this , index);
0427: if (getVerification()) {
0428: waitSelected(index);
0429: }
0430: return (getComponentAt(index));
0431: }
0432:
0433: /**
0434: * Selects tab.
0435: * @param chooser page searching criteria
0436: * @return a root corresponding to the page.
0437: */
0438: public Component selectPage(TabPageChooser chooser) {
0439: output.printLine("Selecting \"" + chooser.getDescription()
0440: + "\" page in tabbed pane\n :" + toStringSource());
0441: return (selectPage(waitPage(chooser)));
0442: }
0443:
0444: /**
0445: * Selects tab.
0446: * @param title a page title.
0447: * @param comparator a string comparision algorithm
0448: * @return a root corresponding to the page.
0449: */
0450: public Component selectPage(String title,
0451: StringComparator comparator) {
0452: return (selectPage(new BySubStringTabPageChooser(title,
0453: comparator)));
0454: }
0455:
0456: /**
0457: * Selects tab by tab title.
0458: * @param title a page title.
0459: * @param ce Compare text exactly.
0460: * @param ccs Compare text case sensitively.
0461: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0462: * @deprecated Use selectPage(String) or selectPage(String, StringComparator)
0463: * @return a root corresponding to the page.
0464: */
0465: public Component selectPage(String title, boolean ce, boolean ccs) {
0466: return (selectPage(title, new DefaultStringComparator(ce, ccs)));
0467: }
0468:
0469: /**
0470: * Selects tab by tab title.
0471: * Uses StringComparator assigned to this object.
0472: * @param title a page title.
0473: * @return a root corresponding to the page.
0474: */
0475: public Component selectPage(String title) {
0476: return (selectPage(title, getComparator()));
0477: }
0478:
0479: /**
0480: * Wait for a page to exist.
0481: * @param chooser page searching criteria
0482: * @return a page index.
0483: */
0484: public int waitPage(final TabPageChooser chooser) {
0485: waitState(new ComponentChooser() {
0486: public boolean checkComponent(Component comp) {
0487: return (findPage(chooser) > -1);
0488: }
0489:
0490: public String getDescription() {
0491: return ("Tabbed with " + chooser.getDescription() + " page.");
0492: }
0493: });
0494: return (findPage(chooser));
0495: }
0496:
0497: /**
0498: * Wait for a page to exist.
0499: * @param title a page title.
0500: * @param comparator a string comparision algorithm
0501: * @return a page index.
0502: */
0503: public int waitPage(String title, StringComparator comparator) {
0504: return (waitPage(new BySubStringTabPageChooser(title,
0505: comparator)));
0506: }
0507:
0508: /**
0509: * Wait for a page to exist.
0510: * @param title a page title.
0511: * @return a page index.
0512: */
0513: public int waitPage(String title) {
0514: return (waitPage(title, getComparator()));
0515: }
0516:
0517: /**
0518: * Waits for a page to be selected.
0519: * @param pageIndex an index of a page to be selected.
0520: */
0521: public void waitSelected(final int pageIndex) {
0522: getOutput().printLine(
0523: "Wait " + Integer.toString(pageIndex)
0524: + "'th page to be "
0525: + " selected in component \n : "
0526: + toStringSource());
0527: getOutput().printGolden(
0528: "Wait " + Integer.toString(pageIndex)
0529: + "'th page to be " + " selected");
0530: waitState(new ComponentChooser() {
0531: public boolean checkComponent(Component comp) {
0532: return (getSelectedIndex() == pageIndex);
0533: }
0534:
0535: public String getDescription() {
0536: return (Integer.toString(pageIndex) + "'th page has been selected");
0537: }
0538: });
0539: }
0540:
0541: /**
0542: * Waits for a page to be selected.
0543: * @param pageTitle a title of a page to be selected.
0544: */
0545: public void waitSelected(final String pageTitle) {
0546: waitSelected(findPage(pageTitle));
0547: }
0548:
0549: public Hashtable getDump() {
0550: Hashtable result = super .getDump();
0551: if (((JTabbedPane) getSource()).getSelectedIndex() != -1) {
0552: result.put(SELECTED_PAGE_DPROP, ((JTabbedPane) getSource())
0553: .getTitleAt(((JTabbedPane) getSource())
0554: .getSelectedIndex()));
0555: }
0556: String[] pages = new String[((JTabbedPane) getSource())
0557: .getTabCount()];
0558: for (int i = 0; i < ((JTabbedPane) getSource()).getTabCount(); i++) {
0559: pages[i] = ((JTabbedPane) getSource()).getTitleAt(i);
0560: }
0561: addToDump(result, PAGE_PREFIX_DPROP, pages);
0562: return (result);
0563: }
0564:
0565: ////////////////////////////////////////////////////////
0566: //Mapping //
0567:
0568: /**Maps <code>JTabbedPane.addChangeListener(ChangeListener)</code> through queue*/
0569: public void addChangeListener(final ChangeListener changeListener) {
0570: runMapping(new MapVoidAction("addChangeListener") {
0571: public void map() {
0572: ((JTabbedPane) getSource())
0573: .addChangeListener(changeListener);
0574: }
0575: });
0576: }
0577:
0578: /**Maps <code>JTabbedPane.addTab(String, Component)</code> through queue*/
0579: public void addTab(final String string, final Component component) {
0580: runMapping(new MapVoidAction("addTab") {
0581: public void map() {
0582: ((JTabbedPane) getSource()).addTab(string, component);
0583: }
0584: });
0585: }
0586:
0587: /**Maps <code>JTabbedPane.addTab(String, Icon, Component)</code> through queue*/
0588: public void addTab(final String string, final Icon icon,
0589: final Component component) {
0590: runMapping(new MapVoidAction("addTab") {
0591: public void map() {
0592: ((JTabbedPane) getSource()).addTab(string, icon,
0593: component);
0594: }
0595: });
0596: }
0597:
0598: /**Maps <code>JTabbedPane.addTab(String, Icon, Component, String)</code> through queue*/
0599: public void addTab(final String string, final Icon icon,
0600: final Component component, final String string1) {
0601: runMapping(new MapVoidAction("addTab") {
0602: public void map() {
0603: ((JTabbedPane) getSource()).addTab(string, icon,
0604: component, string1);
0605: }
0606: });
0607: }
0608:
0609: /**Maps <code>JTabbedPane.getBackgroundAt(int)</code> through queue*/
0610: public Color getBackgroundAt(final int i) {
0611: return ((Color) runMapping(new MapAction("getBackgroundAt") {
0612: public Object map() {
0613: return (((JTabbedPane) getSource()).getBackgroundAt(i));
0614: }
0615: }));
0616: }
0617:
0618: /**Maps <code>JTabbedPane.getBoundsAt(int)</code> through queue*/
0619: public Rectangle getBoundsAt(final int i) {
0620: return ((Rectangle) runMapping(new MapAction("getBoundsAt") {
0621: public Object map() {
0622: return (((JTabbedPane) getSource()).getBoundsAt(i));
0623: }
0624: }));
0625: }
0626:
0627: /**Maps <code>JTabbedPane.getComponentAt(int)</code> through queue*/
0628: public Component getComponentAt(final int i) {
0629: return ((Component) runMapping(new MapAction("getComponentAt") {
0630: public Object map() {
0631: return (((JTabbedPane) getSource()).getComponentAt(i));
0632: }
0633: }));
0634: }
0635:
0636: /**Maps <code>JTabbedPane.getDisabledIconAt(int)</code> through queue*/
0637: public Icon getDisabledIconAt(final int i) {
0638: return ((Icon) runMapping(new MapAction("getDisabledIconAt") {
0639: public Object map() {
0640: return (((JTabbedPane) getSource())
0641: .getDisabledIconAt(i));
0642: }
0643: }));
0644: }
0645:
0646: /**Maps <code>JTabbedPane.getForegroundAt(int)</code> through queue*/
0647: public Color getForegroundAt(final int i) {
0648: return ((Color) runMapping(new MapAction("getForegroundAt") {
0649: public Object map() {
0650: return (((JTabbedPane) getSource()).getForegroundAt(i));
0651: }
0652: }));
0653: }
0654:
0655: /**Maps <code>JTabbedPane.getIconAt(int)</code> through queue*/
0656: public Icon getIconAt(final int i) {
0657: return ((Icon) runMapping(new MapAction("getIconAt") {
0658: public Object map() {
0659: return (((JTabbedPane) getSource()).getIconAt(i));
0660: }
0661: }));
0662: }
0663:
0664: /**Maps <code>JTabbedPane.getModel()</code> through queue*/
0665: public SingleSelectionModel getModel() {
0666: return ((SingleSelectionModel) runMapping(new MapAction(
0667: "getModel") {
0668: public Object map() {
0669: return (((JTabbedPane) getSource()).getModel());
0670: }
0671: }));
0672: }
0673:
0674: /**Maps <code>JTabbedPane.getSelectedComponent()</code> through queue*/
0675: public Component getSelectedComponent() {
0676: return ((Component) runMapping(new MapAction(
0677: "getSelectedComponent") {
0678: public Object map() {
0679: return (((JTabbedPane) getSource())
0680: .getSelectedComponent());
0681: }
0682: }));
0683: }
0684:
0685: /**Maps <code>JTabbedPane.getSelectedIndex()</code> through queue*/
0686: public int getSelectedIndex() {
0687: return (runMapping(new MapIntegerAction("getSelectedIndex") {
0688: public int map() {
0689: return (((JTabbedPane) getSource()).getSelectedIndex());
0690: }
0691: }));
0692: }
0693:
0694: /**Maps <code>JTabbedPane.getTabCount()</code> through queue*/
0695: public int getTabCount() {
0696: return (runMapping(new MapIntegerAction("getTabCount") {
0697: public int map() {
0698: return (((JTabbedPane) getSource()).getTabCount());
0699: }
0700: }));
0701: }
0702:
0703: /**Maps <code>JTabbedPane.getTabPlacement()</code> through queue*/
0704: public int getTabPlacement() {
0705: return (runMapping(new MapIntegerAction("getTabPlacement") {
0706: public int map() {
0707: return (((JTabbedPane) getSource()).getTabPlacement());
0708: }
0709: }));
0710: }
0711:
0712: /**Maps <code>JTabbedPane.getTabRunCount()</code> through queue*/
0713: public int getTabRunCount() {
0714: return (runMapping(new MapIntegerAction("getTabRunCount") {
0715: public int map() {
0716: return (((JTabbedPane) getSource()).getTabRunCount());
0717: }
0718: }));
0719: }
0720:
0721: /**Maps <code>JTabbedPane.getTitleAt(int)</code> through queue*/
0722: public String getTitleAt(final int i) {
0723: return ((String) runMapping(new MapAction("getTitleAt") {
0724: public Object map() {
0725: return (((JTabbedPane) getSource()).getTitleAt(i));
0726: }
0727: }));
0728: }
0729:
0730: /**Maps <code>JTabbedPane.getUI()</code> through queue*/
0731: public TabbedPaneUI getUI() {
0732: return ((TabbedPaneUI) runMapping(new MapAction("getUI") {
0733: public Object map() {
0734: return (((JTabbedPane) getSource()).getUI());
0735: }
0736: }));
0737: }
0738:
0739: /**Maps <code>JTabbedPane.indexOfComponent(Component)</code> through queue*/
0740: public int indexOfComponent(final Component component) {
0741: return (runMapping(new MapIntegerAction("indexOfComponent") {
0742: public int map() {
0743: return (((JTabbedPane) getSource())
0744: .indexOfComponent(component));
0745: }
0746: }));
0747: }
0748:
0749: /**Maps <code>JTabbedPane.indexOfTab(String)</code> through queue*/
0750: public int indexOfTab(final String string) {
0751: return (runMapping(new MapIntegerAction("indexOfTab") {
0752: public int map() {
0753: return (((JTabbedPane) getSource()).indexOfTab(string));
0754: }
0755: }));
0756: }
0757:
0758: /**Maps <code>JTabbedPane.indexOfTab(Icon)</code> through queue*/
0759: public int indexOfTab(final Icon icon) {
0760: return (runMapping(new MapIntegerAction("indexOfTab") {
0761: public int map() {
0762: return (((JTabbedPane) getSource()).indexOfTab(icon));
0763: }
0764: }));
0765: }
0766:
0767: /**Maps <code>JTabbedPane.insertTab(String, Icon, Component, String, int)</code> through queue*/
0768: public void insertTab(final String string, final Icon icon,
0769: final Component component, final String string1, final int i) {
0770: runMapping(new MapVoidAction("insertTab") {
0771: public void map() {
0772: ((JTabbedPane) getSource()).insertTab(string, icon,
0773: component, string1, i);
0774: }
0775: });
0776: }
0777:
0778: /**Maps <code>JTabbedPane.isEnabledAt(int)</code> through queue*/
0779: public boolean isEnabledAt(final int i) {
0780: return (runMapping(new MapBooleanAction("isEnabledAt") {
0781: public boolean map() {
0782: return (((JTabbedPane) getSource()).isEnabledAt(i));
0783: }
0784: }));
0785: }
0786:
0787: /**Maps <code>JTabbedPane.removeChangeListener(ChangeListener)</code> through queue*/
0788: public void removeChangeListener(final ChangeListener changeListener) {
0789: runMapping(new MapVoidAction("removeChangeListener") {
0790: public void map() {
0791: ((JTabbedPane) getSource())
0792: .removeChangeListener(changeListener);
0793: }
0794: });
0795: }
0796:
0797: /**Maps <code>JTabbedPane.removeTabAt(int)</code> through queue*/
0798: public void removeTabAt(final int i) {
0799: runMapping(new MapVoidAction("removeTabAt") {
0800: public void map() {
0801: ((JTabbedPane) getSource()).removeTabAt(i);
0802: }
0803: });
0804: }
0805:
0806: /**Maps <code>JTabbedPane.setBackgroundAt(int, Color)</code> through queue*/
0807: public void setBackgroundAt(final int i, final Color color) {
0808: runMapping(new MapVoidAction("setBackgroundAt") {
0809: public void map() {
0810: ((JTabbedPane) getSource()).setBackgroundAt(i, color);
0811: }
0812: });
0813: }
0814:
0815: /**Maps <code>JTabbedPane.setComponentAt(int, Component)</code> through queue*/
0816: public void setComponentAt(final int i, final Component component) {
0817: runMapping(new MapVoidAction("setComponentAt") {
0818: public void map() {
0819: ((JTabbedPane) getSource())
0820: .setComponentAt(i, component);
0821: }
0822: });
0823: }
0824:
0825: /**Maps <code>JTabbedPane.setDisabledIconAt(int, Icon)</code> through queue*/
0826: public void setDisabledIconAt(final int i, final Icon icon) {
0827: runMapping(new MapVoidAction("setDisabledIconAt") {
0828: public void map() {
0829: ((JTabbedPane) getSource()).setDisabledIconAt(i, icon);
0830: }
0831: });
0832: }
0833:
0834: /**Maps <code>JTabbedPane.setEnabledAt(int, boolean)</code> through queue*/
0835: public void setEnabledAt(final int i, final boolean b) {
0836: runMapping(new MapVoidAction("setEnabledAt") {
0837: public void map() {
0838: ((JTabbedPane) getSource()).setEnabledAt(i, b);
0839: }
0840: });
0841: }
0842:
0843: /**Maps <code>JTabbedPane.setForegroundAt(int, Color)</code> through queue*/
0844: public void setForegroundAt(final int i, final Color color) {
0845: runMapping(new MapVoidAction("setForegroundAt") {
0846: public void map() {
0847: ((JTabbedPane) getSource()).setForegroundAt(i, color);
0848: }
0849: });
0850: }
0851:
0852: /**Maps <code>JTabbedPane.setIconAt(int, Icon)</code> through queue*/
0853: public void setIconAt(final int i, final Icon icon) {
0854: runMapping(new MapVoidAction("setIconAt") {
0855: public void map() {
0856: ((JTabbedPane) getSource()).setIconAt(i, icon);
0857: }
0858: });
0859: }
0860:
0861: /**Maps <code>JTabbedPane.setModel(SingleSelectionModel)</code> through queue*/
0862: public void setModel(final SingleSelectionModel singleSelectionModel) {
0863: runMapping(new MapVoidAction("setModel") {
0864: public void map() {
0865: ((JTabbedPane) getSource())
0866: .setModel(singleSelectionModel);
0867: }
0868: });
0869: }
0870:
0871: /**Maps <code>JTabbedPane.setSelectedComponent(Component)</code> through queue*/
0872: public void setSelectedComponent(final Component component) {
0873: runMapping(new MapVoidAction("setSelectedComponent") {
0874: public void map() {
0875: ((JTabbedPane) getSource())
0876: .setSelectedComponent(component);
0877: }
0878: });
0879: }
0880:
0881: /**Maps <code>JTabbedPane.setSelectedIndex(int)</code> through queue*/
0882: public void setSelectedIndex(final int i) {
0883: runMapping(new MapVoidAction("setSelectedIndex") {
0884: public void map() {
0885: ((JTabbedPane) getSource()).setSelectedIndex(i);
0886: }
0887: });
0888: }
0889:
0890: /**Maps <code>JTabbedPane.setTabPlacement(int)</code> through queue*/
0891: public void setTabPlacement(final int i) {
0892: runMapping(new MapVoidAction("setTabPlacement") {
0893: public void map() {
0894: ((JTabbedPane) getSource()).setTabPlacement(i);
0895: }
0896: });
0897: }
0898:
0899: /**Maps <code>JTabbedPane.setTitleAt(int, String)</code> through queue*/
0900: public void setTitleAt(final int i, final String string) {
0901: runMapping(new MapVoidAction("setTitleAt") {
0902: public void map() {
0903: ((JTabbedPane) getSource()).setTitleAt(i, string);
0904: }
0905: });
0906: }
0907:
0908: /**Maps <code>JTabbedPane.setUI(TabbedPaneUI)</code> through queue*/
0909: public void setUI(final TabbedPaneUI tabbedPaneUI) {
0910: runMapping(new MapVoidAction("setUI") {
0911: public void map() {
0912: ((JTabbedPane) getSource()).setUI(tabbedPaneUI);
0913: }
0914: });
0915: }
0916:
0917: //End of mapping //
0918: ////////////////////////////////////////////////////////
0919:
0920: /**
0921: * Specifies criteria for a tab page searching.
0922: */
0923: public interface TabPageChooser {
0924: /**
0925: * Should be true if a page is good.
0926: * @param oper Operator used to search item.
0927: * @param index Index of a page be checked.
0928: * @return true if a page fits the criteria.
0929: */
0930: public boolean checkPage(JTabbedPaneOperator oper, int index);
0931:
0932: /**
0933: * Page description.
0934: * @return a description.
0935: */
0936: public String getDescription();
0937: }
0938:
0939: /**
0940: * Exception is thrown if a nonexistent page is trying to be selected.
0941: */
0942: public class NoSuchPageException extends JemmyInputException {
0943: /**
0944: * Constructor.
0945: * @param item nonexistent page title.
0946: */
0947: public NoSuchPageException(String item) {
0948: super ("No such page as \"" + item + "\"", getSource());
0949: }
0950: }
0951:
0952: /**
0953: * Allows to find component by page title.
0954: */
0955: public static class JTabbedPaneByItemFinder implements
0956: ComponentChooser {
0957: String title;
0958: int itemIndex;
0959: StringComparator comparator;
0960:
0961: /**
0962: * Constructs JTabbedPaneByItemFinder.
0963: * @param lb a text pattern
0964: * @param ii page index to check. If equal to -1, selected page is checked.
0965: * @param comparator specifies string comparision algorithm.
0966: */
0967: public JTabbedPaneByItemFinder(String lb, int ii,
0968: StringComparator comparator) {
0969: title = lb;
0970: itemIndex = ii;
0971: this .comparator = comparator;
0972: }
0973:
0974: /**
0975: * Constructs JTabbedPaneByItemFinder.
0976: * @param lb a text pattern
0977: * @param ii page index to check. If equal to -1, selected page is checked.
0978: */
0979: public JTabbedPaneByItemFinder(String lb, int ii) {
0980: this (lb, ii, Operator.getDefaultStringComparator());
0981: }
0982:
0983: public boolean checkComponent(Component comp) {
0984: if (comp instanceof JTabbedPane) {
0985: if (title == null) {
0986: return (true);
0987: }
0988: JTabbedPaneOperator tpo = new JTabbedPaneOperator(
0989: (JTabbedPane) comp);
0990: if (tpo.getTabCount() > itemIndex) {
0991: int ii = itemIndex;
0992: if (ii == -1) {
0993: ii = tpo.getSelectedIndex();
0994: if (ii == -1) {
0995: return (false);
0996: }
0997: }
0998: return (comparator
0999: .equals(tpo.getTitleAt(ii), title));
1000: }
1001: }
1002: return (false);
1003: }
1004:
1005: public String getDescription() {
1006: return ("JTabbedPane with text \"" + title + "\" in "
1007: + (new Integer(itemIndex)).toString() + "'th item");
1008: }
1009: }
1010:
1011: /**
1012: * Checks component type.
1013: */
1014: public static class JTabbedPaneFinder extends Finder {
1015: /**
1016: * Constructs JTabbedPaneFinder.
1017: * @param sf other searching criteria.
1018: */
1019: public JTabbedPaneFinder(ComponentChooser sf) {
1020: super (JTabbedPane.class, sf);
1021: }
1022:
1023: /**
1024: * Constructs JTabbedPaneFinder.
1025: */
1026: public JTabbedPaneFinder() {
1027: super (JTabbedPane.class);
1028: }
1029: }
1030:
1031: private class BySubStringTabPageChooser implements TabPageChooser {
1032: String title;
1033: StringComparator comparator;
1034:
1035: public BySubStringTabPageChooser(String title,
1036: StringComparator comparator) {
1037: this .title = title;
1038: this .comparator = comparator;
1039: }
1040:
1041: public boolean checkPage(JTabbedPaneOperator oper, int index) {
1042: return (comparator.equals(oper.getTitleAt(index), title));
1043: }
1044:
1045: public String getDescription() {
1046: return ("Page having \"" + title + "\" title.");
1047: }
1048: }
1049:
1050: }
|