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$ $Revision$ $Date$
0044: *
0045: */
0046:
0047: package org.netbeans.jemmy.operators;
0048:
0049: import org.netbeans.jemmy.Action;
0050: import org.netbeans.jemmy.ComponentChooser;
0051: import org.netbeans.jemmy.ComponentSearcher;
0052: import org.netbeans.jemmy.JemmyException;
0053: import org.netbeans.jemmy.Outputable;
0054: import org.netbeans.jemmy.TestOut;
0055: import org.netbeans.jemmy.Timeoutable;
0056: import org.netbeans.jemmy.TimeoutExpiredException;
0057: import org.netbeans.jemmy.Timeouts;
0058:
0059: import org.netbeans.jemmy.drivers.ButtonDriver;
0060: import org.netbeans.jemmy.drivers.DriverManager;
0061:
0062: import java.awt.Component;
0063: import java.awt.Container;
0064: import java.awt.Insets;
0065:
0066: import java.awt.event.ActionListener;
0067: import java.awt.event.ItemListener;
0068:
0069: import java.util.Hashtable;
0070:
0071: import javax.swing.AbstractButton;
0072: import javax.swing.ButtonModel;
0073: import javax.swing.Icon;
0074:
0075: import javax.swing.event.ChangeListener;
0076:
0077: import javax.swing.plaf.ButtonUI;
0078:
0079: /**
0080: *
0081: * <BR><BR>Timeouts used: <BR>
0082: * AbstractButtonOperator.PushButtonTimeout - time between button pressing and releasing<BR>
0083: * ComponentOperator.WaitComponentTimeout - time to wait button displayed <BR>
0084: * ComponentOperator.WaitComponentEnabledTimeout - time to wait button enabled <BR>
0085: * ComponentOperator.WaitStateTimeout - time to wait for text <BR>.
0086: *
0087: * @see org.netbeans.jemmy.Timeouts
0088: *
0089: * @author Alexandre Iline (alexandre.iline@sun.com)
0090: *
0091: */
0092:
0093: public class AbstractButtonOperator extends JComponentOperator
0094: implements Timeoutable, Outputable {
0095:
0096: /**
0097: * Identifier for a text property.
0098: * @see #getDump
0099: */
0100: public static final String TEXT_DPROP = "Text";
0101:
0102: /**
0103: * Identifier for a selected text property.
0104: * @see #getDump
0105: */
0106: public static final String IS_SELECTED_DPROP = "Selected";
0107:
0108: /**
0109: * Default value for AbstractButtonOperator.PushButtonTimeout timeout.
0110: */
0111: private final static long PUSH_BUTTON_TIMEOUT = 0;
0112:
0113: private Timeouts timeouts;
0114: private TestOut output;
0115:
0116: ButtonDriver driver;
0117:
0118: /**
0119: * Constructor.
0120: * @param b The <code>java.awt.AbstractButton</code> managed by
0121: * this instance.
0122: */
0123: public AbstractButtonOperator(AbstractButton b) {
0124: super (b);
0125: driver = DriverManager.getButtonDriver(getClass());
0126: }
0127:
0128: /**
0129: * Constructs an AbstractButtonOperator object.
0130: * @param cont container
0131: * @param chooser a component chooser specifying searching criteria.
0132: * @param index an index between appropriate ones.
0133: */
0134: public AbstractButtonOperator(ContainerOperator cont,
0135: ComponentChooser chooser, int index) {
0136: this ((AbstractButton) cont.waitSubComponent(
0137: new AbstractButtonFinder(chooser), index));
0138: copyEnvironment(cont);
0139: }
0140:
0141: /**
0142: * Constructs an AbstractButtonOperator object.
0143: * @param cont container
0144: * @param chooser a component chooser specifying searching criteria.
0145: */
0146: public AbstractButtonOperator(ContainerOperator cont,
0147: ComponentChooser chooser) {
0148: this (cont, chooser, 0);
0149: }
0150:
0151: /**
0152: * Constructor.
0153: * Waits for a component in a container to show. The component is
0154: * identified as the <code>index+1</code>'th
0155: * <code>javax.swing.AbstractButton</code> that shows, lies below
0156: * the container in the display containment hierarchy,
0157: * and that has the desired text. Uses cont's timeout and output
0158: * for waiting and to init this operator.
0159: * @param cont The operator for a container containing the sought for button.
0160: * @param text Button text.
0161: * @param index Ordinal component index. The first component has <code>index</code> 0.
0162: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0163: * @throws TimeoutExpiredException
0164: */
0165: public AbstractButtonOperator(ContainerOperator cont, String text,
0166: int index) {
0167: this ((AbstractButton) waitComponent(cont,
0168: new AbstractButtonByLabelFinder(text, cont
0169: .getComparator()), index));
0170: copyEnvironment(cont);
0171: }
0172:
0173: /**
0174: * Constructor.
0175: * Waits for a component in a container to show. The component is
0176: * identified as the first
0177: * <code>javax.swing.AbstractButton</code> that shows, lies below
0178: * the container in the display containment hierarchy,
0179: * and that has the desired text. Uses cont's timeout and output
0180: * for waiting and to init this operator.
0181: * @param cont The operator for a container containing the sought for button.
0182: * @param text Button text.
0183: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0184: * @throws TimeoutExpiredException
0185: */
0186: public AbstractButtonOperator(ContainerOperator cont, String text) {
0187: this (cont, text, 0);
0188: }
0189:
0190: /**
0191: * Constructor.
0192: * Waits component in container first.
0193: * Uses cont's timeout and output for waiting and to init operator.
0194: * @param cont The operator for a container containing the sought for button.
0195: * @param index Ordinal component index.
0196: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0197: * @throws TimeoutExpiredException
0198: */
0199: public AbstractButtonOperator(ContainerOperator cont, int index) {
0200: this ((AbstractButton) waitComponent(cont,
0201: new AbstractButtonFinder(), index));
0202: copyEnvironment(cont);
0203: }
0204:
0205: /**
0206: * Constructor.
0207: * Waits component in container first.
0208: * Uses cont's timeout and output for waiting and to init operator.
0209: * @param cont The operator for a container containing the sought for button.
0210: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0211: * @throws TimeoutExpiredException
0212: */
0213: public AbstractButtonOperator(ContainerOperator cont) {
0214: this (cont, 0);
0215: }
0216:
0217: /**
0218: * Searches AbstractButton in a container.
0219: * @param cont Container in which to search for the component. The container
0220: * lies above the component in the display containment hierarchy. The containment
0221: * need not be direct.
0222: * @param chooser org.netbeans.jemmy.ComponentChooser implementation, defining and
0223: * applying search criteria.
0224: * @param index Ordinal component index. The first <code>index</code> is 0.
0225: * @return AbstractButton instance or null if component was not found.
0226: */
0227: public static AbstractButton findAbstractButton(Container cont,
0228: ComponentChooser chooser, int index) {
0229: return ((AbstractButton) findComponent(cont,
0230: new AbstractButtonFinder(chooser), index));
0231: }
0232:
0233: /**
0234: * Searches for the first AbstractButton in a container.
0235: * @param cont Container in which to search for the component. The container
0236: * lies above the component in the display containment hierarchy. The containment
0237: * need not be direct.
0238: * @param chooser org.netbeans.jemmy.ComponentChooser implementation, defining and
0239: * applying search criteria.
0240: * @return AbstractButton instance or null if component was not found.
0241: */
0242: public static AbstractButton findAbstractButton(Container cont,
0243: ComponentChooser chooser) {
0244: return (findAbstractButton(cont, chooser, 0));
0245: }
0246:
0247: /**
0248: * Searches AbstractButton by text.
0249: * @param cont Container to search component in.
0250: * @param text Button text. If null, contents is not checked.
0251: * @param ce Compare text exactly.
0252: * @param ccs Compare text case sensitively.
0253: * @param index Ordinal component index.
0254: * @return AbstractButton instance or null if component was not found.
0255: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0256: */
0257: public static AbstractButton findAbstractButton(Container cont,
0258: String text, boolean ce, boolean ccs, int index) {
0259: return (findAbstractButton(cont,
0260: new AbstractButtonByLabelFinder(text,
0261: new DefaultStringComparator(ce, ccs)), index));
0262: }
0263:
0264: /**
0265: * Searches AbstractButton by text.
0266: * @param cont Container to search component in.
0267: * @param text Button text. If null, contents is not checked.
0268: * @param ce Compare text exactly.
0269: * @param ccs Compare text case sensitively.
0270: * @return AbstractButton instance or null if component was not found.
0271: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0272: */
0273: public static AbstractButton findAbstractButton(Container cont,
0274: String text, boolean ce, boolean ccs) {
0275: return (findAbstractButton(cont, text, ce, ccs, 0));
0276: }
0277:
0278: /**
0279: * Waits AbstractButton in container.
0280: * @param cont Container to search component in.
0281: * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
0282: * @param index Ordinal component index.
0283: * @return AbstractButton instance.
0284: * @throws TimeoutExpiredException
0285: */
0286: public static AbstractButton waitAbstractButton(Container cont,
0287: ComponentChooser chooser, int index) {
0288: return ((AbstractButton) waitComponent(cont,
0289: new AbstractButtonFinder(chooser), index));
0290: }
0291:
0292: /**
0293: * Waits 0'th AbstractButton in container.
0294: * @param cont Container to search component in.
0295: * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
0296: * @return AbstractButton instance.
0297: * @throws TimeoutExpiredException
0298: */
0299: public static AbstractButton waitAbstractButton(Container cont,
0300: ComponentChooser chooser) {
0301: return (waitAbstractButton(cont, chooser, 0));
0302: }
0303:
0304: /**
0305: * Waits AbstractButton by text.
0306: * @param cont Container to search component in.
0307: * @param text Button text. If null, contents is not checked.
0308: * @param ce Compare text exactly.
0309: * @param ccs Compare text case sensitively.
0310: * @param index Ordinal component index.
0311: * @return AbstractButton instance.
0312: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0313: * @throws TimeoutExpiredException
0314: */
0315: public static AbstractButton waitAbstractButton(Container cont,
0316: String text, boolean ce, boolean ccs, int index) {
0317: return (waitAbstractButton(cont,
0318: new AbstractButtonByLabelFinder(text,
0319: new DefaultStringComparator(ce, ccs)), index));
0320: }
0321:
0322: /**
0323: * Waits AbstractButton by text.
0324: * @param cont Container to search component in.
0325: * @param text Button text. If null, contents is not checked.
0326: * @param ce Compare text exactly.
0327: * @param ccs Compare text case sensitively.
0328: * @return AbstractButton instance.
0329: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0330: * @throws TimeoutExpiredException
0331: */
0332: public static AbstractButton waitAbstractButton(Container cont,
0333: String text, boolean ce, boolean ccs) {
0334: return (waitAbstractButton(cont, text, ce, ccs, 0));
0335: }
0336:
0337: static {
0338: Timeouts.initDefault(
0339: "AbstractButtonOperator.PushButtonTimeout",
0340: PUSH_BUTTON_TIMEOUT);
0341: }
0342:
0343: public void setTimeouts(Timeouts timeouts) {
0344: super .setTimeouts(timeouts);
0345: this .timeouts = timeouts;
0346: }
0347:
0348: public Timeouts getTimeouts() {
0349: return (timeouts);
0350: }
0351:
0352: public void setOutput(TestOut out) {
0353: output = out;
0354: super .setOutput(output.createErrorOutput());
0355: }
0356:
0357: public TestOut getOutput() {
0358: return (output);
0359: }
0360:
0361: public void copyEnvironment(Operator anotherOperator) {
0362: super .copyEnvironment(anotherOperator);
0363: driver = DriverManager.getButtonDriver(this );
0364: }
0365:
0366: /**
0367: * Pushs the button using a ButtonDriver registered for this operator.
0368: */
0369: public void push() {
0370: output.printLine("Push button\n :" + toStringSource());
0371: output.printGolden("Push button");
0372: makeComponentVisible();
0373: try {
0374: waitComponentEnabled();
0375: } catch (InterruptedException e) {
0376: throw (new JemmyException("Interrupted", e));
0377: }
0378: driver.push(this );
0379: }
0380:
0381: /**
0382: * Runs <code>push()</code> method in a separate thread.
0383: */
0384: public void pushNoBlock() {
0385: produceNoBlocking(new NoBlockingAction("Button pushing") {
0386: public Object doAction(Object param) {
0387: push();
0388: return (null);
0389: }
0390: });
0391: }
0392:
0393: /**
0394: * Changes selection if necessary.
0395: * Uses <code>push()</code> method in order to do so.
0396: * @param selected a button selection.
0397: */
0398: public void changeSelection(boolean selected) {
0399: if (isSelected() != selected) {
0400: push();
0401: }
0402: if (getVerification()) {
0403: waitSelected(selected);
0404: }
0405: }
0406:
0407: /**
0408: * Runs <code>changeSelection(boolean)</code> method in a separate thread.
0409: * @param selected a button selection.
0410: */
0411: public void changeSelectionNoBlock(boolean selected) {
0412: produceNoBlocking(new NoBlockingAction(
0413: "Button selection changing") {
0414: public Object doAction(Object param) {
0415: changeSelection(((Boolean) param).booleanValue());
0416: return (null);
0417: }
0418: }, selected ? Boolean.TRUE : Boolean.FALSE);
0419: }
0420:
0421: /**
0422: * Press the button by mouse.
0423: * @throws TimeoutExpiredException
0424: */
0425: public void press() {
0426: output.printLine("Press button\n :" + toStringSource());
0427: output.printGolden("Press button");
0428: makeComponentVisible();
0429: try {
0430: waitComponentEnabled();
0431: } catch (InterruptedException e) {
0432: throw (new JemmyException("Interrupted", e));
0433: }
0434: driver.press(this );
0435: }
0436:
0437: /**
0438: * Releases the button by mouse.
0439: * @throws TimeoutExpiredException
0440: */
0441: public void release() {
0442: output.printLine("Release button\n :" + toStringSource());
0443: output.printGolden("Release button");
0444: try {
0445: waitComponentEnabled();
0446: } catch (InterruptedException e) {
0447: throw (new JemmyException("Interrupted", e));
0448: }
0449: driver.release(this );
0450: }
0451:
0452: /**
0453: * Waits for button to be selected.
0454: * @param selected a button selection.
0455: */
0456: public void waitSelected(final boolean selected) {
0457: getOutput().printLine(
0458: "Wait button to be selected \n : "
0459: + toStringSource());
0460: getOutput().printGolden("Wait button to be selected");
0461: waitState(new ComponentChooser() {
0462: public boolean checkComponent(Component comp) {
0463: return (isSelected() == selected);
0464: }
0465:
0466: public String getDescription() {
0467: return ("Items has been " + (selected ? "" : "un") + "selected");
0468: }
0469: });
0470: }
0471:
0472: /**
0473: * Waits for text. Uses getComparator() comparator.
0474: * @param text Text to wait for.
0475: */
0476: public void waitText(String text) {
0477: getOutput().printLine(
0478: "Wait \"" + text + "\" text in component \n : "
0479: + toStringSource());
0480: getOutput().printGolden("Wait \"" + text + "\" text");
0481: waitState(new AbstractButtonByLabelFinder(text, getComparator()));
0482: }
0483:
0484: /**
0485: * Returns information about component.
0486: */
0487: public Hashtable getDump() {
0488: Hashtable result = super .getDump();
0489: if (((AbstractButton) getSource()).getText() != null) {
0490: result.put(TEXT_DPROP, ((AbstractButton) getSource())
0491: .getText());
0492: }
0493: result.put(IS_SELECTED_DPROP, ((AbstractButton) getSource())
0494: .isSelected() ? "true" : "false");
0495: return (result);
0496: }
0497:
0498: ////////////////////////////////////////////////////////
0499: //Mapping //
0500:
0501: /**Maps <code>AbstractButton.addActionListener(ActionListener)</code> through queue*/
0502: public void addActionListener(final ActionListener actionListener) {
0503: runMapping(new MapVoidAction("addActionListener") {
0504: public void map() {
0505: ((AbstractButton) getSource())
0506: .addActionListener(actionListener);
0507: }
0508: });
0509: }
0510:
0511: /**Maps <code>AbstractButton.addChangeListener(ChangeListener)</code> through queue*/
0512: public void addChangeListener(final ChangeListener changeListener) {
0513: runMapping(new MapVoidAction("addChangeListener") {
0514: public void map() {
0515: ((AbstractButton) getSource())
0516: .addChangeListener(changeListener);
0517: }
0518: });
0519: }
0520:
0521: /**Maps <code>AbstractButton.addItemListener(ItemListener)</code> through queue*/
0522: public void addItemListener(final ItemListener itemListener) {
0523: runMapping(new MapVoidAction("addItemListener") {
0524: public void map() {
0525: ((AbstractButton) getSource())
0526: .addItemListener(itemListener);
0527: }
0528: });
0529: }
0530:
0531: /**Maps <code>AbstractButton.doClick()</code> through queue*/
0532: public void doClick() {
0533: runMapping(new MapVoidAction("doClick") {
0534: public void map() {
0535: ((AbstractButton) getSource()).doClick();
0536: }
0537: });
0538: }
0539:
0540: /**Maps <code>AbstractButton.doClick(int)</code> through queue*/
0541: public void doClick(final int i) {
0542: runMapping(new MapVoidAction("doClick") {
0543: public void map() {
0544: ((AbstractButton) getSource()).doClick(i);
0545: }
0546: });
0547: }
0548:
0549: /**Maps <code>AbstractButton.getActionCommand()</code> through queue*/
0550: public String getActionCommand() {
0551: return ((String) runMapping(new MapAction("getActionCommand") {
0552: public Object map() {
0553: return (((AbstractButton) getSource())
0554: .getActionCommand());
0555: }
0556: }));
0557: }
0558:
0559: /**Maps <code>AbstractButton.getDisabledIcon()</code> through queue*/
0560: public Icon getDisabledIcon() {
0561: return ((Icon) runMapping(new MapAction("getDisabledIcon") {
0562: public Object map() {
0563: return (((AbstractButton) getSource())
0564: .getDisabledIcon());
0565: }
0566: }));
0567: }
0568:
0569: /**Maps <code>AbstractButton.getDisabledSelectedIcon()</code> through queue*/
0570: public Icon getDisabledSelectedIcon() {
0571: return ((Icon) runMapping(new MapAction(
0572: "getDisabledSelectedIcon") {
0573: public Object map() {
0574: return (((AbstractButton) getSource())
0575: .getDisabledSelectedIcon());
0576: }
0577: }));
0578: }
0579:
0580: /**Maps <code>AbstractButton.getHorizontalAlignment()</code> through queue*/
0581: public int getHorizontalAlignment() {
0582: return (runMapping(new MapIntegerAction(
0583: "getHorizontalAlignment") {
0584: public int map() {
0585: return (((AbstractButton) getSource())
0586: .getHorizontalAlignment());
0587: }
0588: }));
0589: }
0590:
0591: /**Maps <code>AbstractButton.getHorizontalTextPosition()</code> through queue*/
0592: public int getHorizontalTextPosition() {
0593: return (runMapping(new MapIntegerAction(
0594: "getHorizontalTextPosition") {
0595: public int map() {
0596: return (((AbstractButton) getSource())
0597: .getHorizontalTextPosition());
0598: }
0599: }));
0600: }
0601:
0602: /**Maps <code>AbstractButton.getIcon()</code> through queue*/
0603: public Icon getIcon() {
0604: return ((Icon) runMapping(new MapAction("getIcon") {
0605: public Object map() {
0606: return (((AbstractButton) getSource()).getIcon());
0607: }
0608: }));
0609: }
0610:
0611: /**Maps <code>AbstractButton.getMargin()</code> through queue*/
0612: public Insets getMargin() {
0613: return ((Insets) runMapping(new MapAction("getMargin") {
0614: public Object map() {
0615: return (((AbstractButton) getSource()).getMargin());
0616: }
0617: }));
0618: }
0619:
0620: /**Maps <code>AbstractButton.getMnemonic()</code> through queue*/
0621: public int getMnemonic() {
0622: return (runMapping(new MapIntegerAction("getMnemonic") {
0623: public int map() {
0624: return (((AbstractButton) getSource()).getMnemonic());
0625: }
0626: }));
0627: }
0628:
0629: /**Maps <code>AbstractButton.getModel()</code> through queue*/
0630: public ButtonModel getModel() {
0631: return ((ButtonModel) runMapping(new MapAction("getModel") {
0632: public Object map() {
0633: return (((AbstractButton) getSource()).getModel());
0634: }
0635: }));
0636: }
0637:
0638: /**Maps <code>AbstractButton.getPressedIcon()</code> through queue*/
0639: public Icon getPressedIcon() {
0640: return ((Icon) runMapping(new MapAction("getPressedIcon") {
0641: public Object map() {
0642: return (((AbstractButton) getSource()).getPressedIcon());
0643: }
0644: }));
0645: }
0646:
0647: /**Maps <code>AbstractButton.getRolloverIcon()</code> through queue*/
0648: public Icon getRolloverIcon() {
0649: return ((Icon) runMapping(new MapAction("getRolloverIcon") {
0650: public Object map() {
0651: return (((AbstractButton) getSource())
0652: .getRolloverIcon());
0653: }
0654: }));
0655: }
0656:
0657: /**Maps <code>AbstractButton.getRolloverSelectedIcon()</code> through queue*/
0658: public Icon getRolloverSelectedIcon() {
0659: return ((Icon) runMapping(new MapAction(
0660: "getRolloverSelectedIcon") {
0661: public Object map() {
0662: return (((AbstractButton) getSource())
0663: .getRolloverSelectedIcon());
0664: }
0665: }));
0666: }
0667:
0668: /**Maps <code>AbstractButton.getSelectedIcon()</code> through queue*/
0669: public Icon getSelectedIcon() {
0670: return ((Icon) runMapping(new MapAction("getSelectedIcon") {
0671: public Object map() {
0672: return (((AbstractButton) getSource())
0673: .getSelectedIcon());
0674: }
0675: }));
0676: }
0677:
0678: /**Maps <code>AbstractButton.getSelectedObjects()</code> through queue*/
0679: public Object[] getSelectedObjects() {
0680: return ((Object[]) runMapping(new MapAction(
0681: "getSelectedObjects") {
0682: public Object map() {
0683: return (((AbstractButton) getSource())
0684: .getSelectedObjects());
0685: }
0686: }));
0687: }
0688:
0689: /**Maps <code>AbstractButton.getText()</code> through queue*/
0690: public String getText() {
0691: return ((String) runMapping(new MapAction("getText") {
0692: public Object map() {
0693: return (((AbstractButton) getSource()).getText());
0694: }
0695: }));
0696: }
0697:
0698: /**Maps <code>AbstractButton.getUI()</code> through queue*/
0699: public ButtonUI getUI() {
0700: return ((ButtonUI) runMapping(new MapAction("getUI") {
0701: public Object map() {
0702: return (((AbstractButton) getSource()).getUI());
0703: }
0704: }));
0705: }
0706:
0707: /**Maps <code>AbstractButton.getVerticalAlignment()</code> through queue*/
0708: public int getVerticalAlignment() {
0709: return (runMapping(new MapIntegerAction("getVerticalAlignment") {
0710: public int map() {
0711: return (((AbstractButton) getSource())
0712: .getVerticalAlignment());
0713: }
0714: }));
0715: }
0716:
0717: /**Maps <code>AbstractButton.getVerticalTextPosition()</code> through queue*/
0718: public int getVerticalTextPosition() {
0719: return (runMapping(new MapIntegerAction(
0720: "getVerticalTextPosition") {
0721: public int map() {
0722: return (((AbstractButton) getSource())
0723: .getVerticalTextPosition());
0724: }
0725: }));
0726: }
0727:
0728: /**Maps <code>AbstractButton.isBorderPainted()</code> through queue*/
0729: public boolean isBorderPainted() {
0730: return (runMapping(new MapBooleanAction("isBorderPainted") {
0731: public boolean map() {
0732: return (((AbstractButton) getSource())
0733: .isBorderPainted());
0734: }
0735: }));
0736: }
0737:
0738: /**Maps <code>AbstractButton.isContentAreaFilled()</code> through queue*/
0739: public boolean isContentAreaFilled() {
0740: return (runMapping(new MapBooleanAction("isContentAreaFilled") {
0741: public boolean map() {
0742: return (((AbstractButton) getSource())
0743: .isContentAreaFilled());
0744: }
0745: }));
0746: }
0747:
0748: /**Maps <code>AbstractButton.isFocusPainted()</code> through queue*/
0749: public boolean isFocusPainted() {
0750: return (runMapping(new MapBooleanAction("isFocusPainted") {
0751: public boolean map() {
0752: return (((AbstractButton) getSource()).isFocusPainted());
0753: }
0754: }));
0755: }
0756:
0757: /**Maps <code>AbstractButton.isRolloverEnabled()</code> through queue*/
0758: public boolean isRolloverEnabled() {
0759: return (runMapping(new MapBooleanAction("isRolloverEnabled") {
0760: public boolean map() {
0761: return (((AbstractButton) getSource())
0762: .isRolloverEnabled());
0763: }
0764: }));
0765: }
0766:
0767: /**Maps <code>AbstractButton.isSelected()</code> through queue*/
0768: public boolean isSelected() {
0769: return (runMapping(new MapBooleanAction("isSelected") {
0770: public boolean map() {
0771: return (((AbstractButton) getSource()).isSelected());
0772: }
0773: }));
0774: }
0775:
0776: /**Maps <code>AbstractButton.removeActionListener(ActionListener)</code> through queue*/
0777: public void removeActionListener(final ActionListener actionListener) {
0778: runMapping(new MapVoidAction("removeActionListener") {
0779: public void map() {
0780: ((AbstractButton) getSource())
0781: .removeActionListener(actionListener);
0782: }
0783: });
0784: }
0785:
0786: /**Maps <code>AbstractButton.removeChangeListener(ChangeListener)</code> through queue*/
0787: public void removeChangeListener(final ChangeListener changeListener) {
0788: runMapping(new MapVoidAction("removeChangeListener") {
0789: public void map() {
0790: ((AbstractButton) getSource())
0791: .removeChangeListener(changeListener);
0792: }
0793: });
0794: }
0795:
0796: /**Maps <code>AbstractButton.removeItemListener(ItemListener)</code> through queue*/
0797: public void removeItemListener(final ItemListener itemListener) {
0798: runMapping(new MapVoidAction("removeItemListener") {
0799: public void map() {
0800: ((AbstractButton) getSource())
0801: .removeItemListener(itemListener);
0802: }
0803: });
0804: }
0805:
0806: /**Maps <code>AbstractButton.setActionCommand(String)</code> through queue*/
0807: public void setActionCommand(final String string) {
0808: runMapping(new MapVoidAction("setActionCommand") {
0809: public void map() {
0810: ((AbstractButton) getSource()).setActionCommand(string);
0811: }
0812: });
0813: }
0814:
0815: /**Maps <code>AbstractButton.setBorderPainted(boolean)</code> through queue*/
0816: public void setBorderPainted(final boolean b) {
0817: runMapping(new MapVoidAction("setBorderPainted") {
0818: public void map() {
0819: ((AbstractButton) getSource()).setBorderPainted(b);
0820: }
0821: });
0822: }
0823:
0824: /**Maps <code>AbstractButton.setContentAreaFilled(boolean)</code> through queue*/
0825: public void setContentAreaFilled(final boolean b) {
0826: runMapping(new MapVoidAction("setContentAreaFilled") {
0827: public void map() {
0828: ((AbstractButton) getSource()).setContentAreaFilled(b);
0829: }
0830: });
0831: }
0832:
0833: /**Maps <code>AbstractButton.setDisabledIcon(Icon)</code> through queue*/
0834: public void setDisabledIcon(final Icon icon) {
0835: runMapping(new MapVoidAction("setDisabledIcon") {
0836: public void map() {
0837: ((AbstractButton) getSource()).setDisabledIcon(icon);
0838: }
0839: });
0840: }
0841:
0842: /**Maps <code>AbstractButton.setDisabledSelectedIcon(Icon)</code> through queue*/
0843: public void setDisabledSelectedIcon(final Icon icon) {
0844: runMapping(new MapVoidAction("setDisabledSelectedIcon") {
0845: public void map() {
0846: ((AbstractButton) getSource())
0847: .setDisabledSelectedIcon(icon);
0848: }
0849: });
0850: }
0851:
0852: /**Maps <code>AbstractButton.setFocusPainted(boolean)</code> through queue*/
0853: public void setFocusPainted(final boolean b) {
0854: runMapping(new MapVoidAction("setFocusPainted") {
0855: public void map() {
0856: ((AbstractButton) getSource()).setFocusPainted(b);
0857: }
0858: });
0859: }
0860:
0861: /**Maps <code>AbstractButton.setHorizontalAlignment(int)</code> through queue*/
0862: public void setHorizontalAlignment(final int i) {
0863: runMapping(new MapVoidAction("setHorizontalAlignment") {
0864: public void map() {
0865: ((AbstractButton) getSource())
0866: .setHorizontalAlignment(i);
0867: }
0868: });
0869: }
0870:
0871: /**Maps <code>AbstractButton.setHorizontalTextPosition(int)</code> through queue*/
0872: public void setHorizontalTextPosition(final int i) {
0873: runMapping(new MapVoidAction("setHorizontalTextPosition") {
0874: public void map() {
0875: ((AbstractButton) getSource())
0876: .setHorizontalTextPosition(i);
0877: }
0878: });
0879: }
0880:
0881: /**Maps <code>AbstractButton.setIcon(Icon)</code> through queue*/
0882: public void setIcon(final Icon icon) {
0883: runMapping(new MapVoidAction("setIcon") {
0884: public void map() {
0885: ((AbstractButton) getSource()).setIcon(icon);
0886: }
0887: });
0888: }
0889:
0890: /**Maps <code>AbstractButton.setMargin(Insets)</code> through queue*/
0891: public void setMargin(final Insets insets) {
0892: runMapping(new MapVoidAction("setMargin") {
0893: public void map() {
0894: ((AbstractButton) getSource()).setMargin(insets);
0895: }
0896: });
0897: }
0898:
0899: /**Maps <code>AbstractButton.setMnemonic(char)</code> through queue*/
0900: public void setMnemonic(final char c) {
0901: runMapping(new MapVoidAction("setMnemonic") {
0902: public void map() {
0903: ((AbstractButton) getSource()).setMnemonic(c);
0904: }
0905: });
0906: }
0907:
0908: /**Maps <code>AbstractButton.setMnemonic(int)</code> through queue*/
0909: public void setMnemonic(final int i) {
0910: runMapping(new MapVoidAction("setMnemonic") {
0911: public void map() {
0912: ((AbstractButton) getSource()).setMnemonic(i);
0913: }
0914: });
0915: }
0916:
0917: /**Maps <code>AbstractButton.setModel(ButtonModel)</code> through queue*/
0918: public void setModel(final ButtonModel buttonModel) {
0919: runMapping(new MapVoidAction("setModel") {
0920: public void map() {
0921: ((AbstractButton) getSource()).setModel(buttonModel);
0922: }
0923: });
0924: }
0925:
0926: /**Maps <code>AbstractButton.setPressedIcon(Icon)</code> through queue*/
0927: public void setPressedIcon(final Icon icon) {
0928: runMapping(new MapVoidAction("setPressedIcon") {
0929: public void map() {
0930: ((AbstractButton) getSource()).setPressedIcon(icon);
0931: }
0932: });
0933: }
0934:
0935: /**Maps <code>AbstractButton.setRolloverEnabled(boolean)</code> through queue*/
0936: public void setRolloverEnabled(final boolean b) {
0937: runMapping(new MapVoidAction("setRolloverEnabled") {
0938: public void map() {
0939: ((AbstractButton) getSource()).setRolloverEnabled(b);
0940: }
0941: });
0942: }
0943:
0944: /**Maps <code>AbstractButton.setRolloverIcon(Icon)</code> through queue*/
0945: public void setRolloverIcon(final Icon icon) {
0946: runMapping(new MapVoidAction("setRolloverIcon") {
0947: public void map() {
0948: ((AbstractButton) getSource()).setRolloverIcon(icon);
0949: }
0950: });
0951: }
0952:
0953: /**Maps <code>AbstractButton.setRolloverSelectedIcon(Icon)</code> through queue*/
0954: public void setRolloverSelectedIcon(final Icon icon) {
0955: runMapping(new MapVoidAction("setRolloverSelectedIcon") {
0956: public void map() {
0957: ((AbstractButton) getSource())
0958: .setRolloverSelectedIcon(icon);
0959: }
0960: });
0961: }
0962:
0963: /**Maps <code>AbstractButton.setSelected(boolean)</code> through queue*/
0964: public void setSelected(final boolean b) {
0965: runMapping(new MapVoidAction("setSelected") {
0966: public void map() {
0967: ((AbstractButton) getSource()).setSelected(b);
0968: }
0969: });
0970: }
0971:
0972: /**Maps <code>AbstractButton.setSelectedIcon(Icon)</code> through queue*/
0973: public void setSelectedIcon(final Icon icon) {
0974: runMapping(new MapVoidAction("setSelectedIcon") {
0975: public void map() {
0976: ((AbstractButton) getSource()).setSelectedIcon(icon);
0977: }
0978: });
0979: }
0980:
0981: /**Maps <code>AbstractButton.setText(String)</code> through queue*/
0982: public void setText(final String string) {
0983: runMapping(new MapVoidAction("setText") {
0984: public void map() {
0985: ((AbstractButton) getSource()).setText(string);
0986: }
0987: });
0988: }
0989:
0990: /**Maps <code>AbstractButton.setUI(ButtonUI)</code> through queue*/
0991: public void setUI(final ButtonUI buttonUI) {
0992: runMapping(new MapVoidAction("setUI") {
0993: public void map() {
0994: ((AbstractButton) getSource()).setUI(buttonUI);
0995: }
0996: });
0997: }
0998:
0999: /**Maps <code>AbstractButton.setVerticalAlignment(int)</code> through queue*/
1000: public void setVerticalAlignment(final int i) {
1001: runMapping(new MapVoidAction("setVerticalAlignment") {
1002: public void map() {
1003: ((AbstractButton) getSource()).setVerticalAlignment(i);
1004: }
1005: });
1006: }
1007:
1008: /**Maps <code>AbstractButton.setVerticalTextPosition(int)</code> through queue*/
1009: public void setVerticalTextPosition(final int i) {
1010: runMapping(new MapVoidAction("setVerticalTextPosition") {
1011: public void map() {
1012: ((AbstractButton) getSource())
1013: .setVerticalTextPosition(i);
1014: }
1015: });
1016: }
1017:
1018: //End of mapping //
1019: ////////////////////////////////////////////////////////
1020:
1021: /**
1022: * Allows to find component by text.
1023: */
1024: public static class AbstractButtonByLabelFinder implements
1025: ComponentChooser {
1026: String label;
1027: StringComparator comparator;
1028:
1029: /**
1030: * Constructs AbstractButtonByLabelFinder.
1031: * @param lb a text pattern
1032: * @param comparator specifies string comparision algorithm.
1033: */
1034: public AbstractButtonByLabelFinder(String lb,
1035: StringComparator comparator) {
1036: label = lb;
1037: this .comparator = comparator;
1038: }
1039:
1040: /**
1041: * Constructs AbstractButtonByLabelFinder.
1042: * @param lb a text pattern
1043: */
1044: public AbstractButtonByLabelFinder(String lb) {
1045: this (lb, Operator.getDefaultStringComparator());
1046: }
1047:
1048: public boolean checkComponent(Component comp) {
1049: if (comp instanceof AbstractButton) {
1050: if (((AbstractButton) comp).getText() != null) {
1051: return (comparator.equals(((AbstractButton) comp)
1052: .getText(), label));
1053: }
1054: }
1055: return (false);
1056: }
1057:
1058: public String getDescription() {
1059: return ("AbstractButton with text \"" + label + "\"");
1060: }
1061: }
1062:
1063: /**
1064: * Checks component type.
1065: */
1066: public static class AbstractButtonFinder extends Finder {
1067: /**
1068: * Constructs AbstractButtonFinder.
1069: * @param sf other searching criteria.
1070: */
1071: public AbstractButtonFinder(ComponentChooser sf) {
1072: super (AbstractButton.class, sf);
1073: }
1074:
1075: /**
1076: * Constructs AbstractButtonFinder.
1077: */
1078: public AbstractButtonFinder() {
1079: super (AbstractButton.class);
1080: }
1081: }
1082: }
|