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: JComponentOperator.java,v 1.13 2007/10/05 11:35:41 jskrivanek Exp $ $Revision: 1.13 $ $Date: 2007/10/05 11:35:41 $
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.JemmyProperties;
0052: import org.netbeans.jemmy.Outputable;
0053: import org.netbeans.jemmy.TestOut;
0054: import org.netbeans.jemmy.Timeoutable;
0055: import org.netbeans.jemmy.TimeoutExpiredException;
0056: import org.netbeans.jemmy.Timeouts;
0057: import org.netbeans.jemmy.Waitable;
0058: import org.netbeans.jemmy.Waiter;
0059:
0060: import java.awt.Component;
0061: import java.awt.Container;
0062: import java.awt.Dimension;
0063: import java.awt.Insets;
0064: import java.awt.Point;
0065: import java.awt.Rectangle;
0066: import java.awt.Window;
0067:
0068: import java.awt.event.ActionListener;
0069: import java.awt.event.MouseEvent;
0070:
0071: import java.beans.VetoableChangeListener;
0072:
0073: import java.util.Hashtable;
0074:
0075: import javax.accessibility.AccessibleContext;
0076:
0077: import javax.swing.JComponent;
0078: import javax.swing.JInternalFrame;
0079: import javax.swing.JRootPane;
0080: import javax.swing.JToolTip;
0081: import javax.swing.KeyStroke;
0082:
0083: import javax.swing.border.Border;
0084:
0085: import javax.swing.event.AncestorListener;
0086:
0087: /**
0088: * <BR><BR>Timeouts used: <BR>
0089: * JComponentOperator.WaitToolTipTimeout - time to wait tool tip displayed <BR>
0090: * JComponentOperator.ShowToolTipTimeout - time to show tool tip <BR>
0091: * ComponentOperator.WaitComponentTimeout - time to wait component displayed <BR>.
0092: *
0093: * @see org.netbeans.jemmy.Timeouts
0094: *
0095: * @author Alexandre Iline (alexandre.iline@sun.com)
0096: *
0097: */
0098:
0099: public class JComponentOperator extends ContainerOperator implements
0100: Timeoutable, Outputable {
0101:
0102: /**
0103: * Identifier for a "tooltip text" property.
0104: * @see #getDump
0105: */
0106: public static final String TOOLTIP_TEXT_DPROP = "Tooltip text";
0107: public static final String A11Y_DATA = "Accessible data (yes/no)";
0108: public static final String A11Y_NAME_DPROP = "Accessible name";
0109: public static final String A11Y_DESCRIPTION_DPROP = "Accessible decription";
0110:
0111: private final static long WAIT_TOOL_TIP_TIMEOUT = 10000;
0112: private final static long SHOW_TOOL_TIP_TIMEOUT = 0;
0113:
0114: private Timeouts timeouts;
0115: private TestOut output;
0116:
0117: /**
0118: * Constructor.
0119: * @param b a component
0120: */
0121: public JComponentOperator(JComponent b) {
0122: super (b);
0123: }
0124:
0125: /**
0126: * Constructs a JComponentOperator object.
0127: * @param cont a container
0128: * @param chooser a component chooser specifying searching criteria.
0129: * @param index an index between appropriate ones.
0130: */
0131: public JComponentOperator(ContainerOperator cont,
0132: ComponentChooser chooser, int index) {
0133: this ((JComponent) cont.waitSubComponent(new JComponentFinder(
0134: chooser), index));
0135: copyEnvironment(cont);
0136: }
0137:
0138: /**
0139: * Constructs a JComponentOperator object.
0140: * @param cont a container
0141: * @param chooser a component chooser specifying searching criteria.
0142: */
0143: public JComponentOperator(ContainerOperator cont,
0144: ComponentChooser chooser) {
0145: this (cont, chooser, 0);
0146: }
0147:
0148: /**
0149: * Constructor.
0150: * Waits component in container first.
0151: * Uses cont's timeout and output for waiting and to init operator.
0152: * @param cont Operator pointing a container to search component in.
0153: * @param index Ordinal component index.
0154: * @throws TimeoutExpiredException
0155: */
0156: public JComponentOperator(ContainerOperator cont, int index) {
0157: this ((JComponent) waitComponent(cont, new JComponentFinder(
0158: ComponentSearcher.getTrueChooser("Any JComponent")),
0159: index));
0160: copyEnvironment(cont);
0161: }
0162:
0163: /**
0164: * Constructor.
0165: * Waits component in container first.
0166: * Uses cont's timeout and output for waiting and to init operator.
0167: * @param cont Operator pointing a container to search component in.
0168: * @throws TimeoutExpiredException
0169: */
0170: public JComponentOperator(ContainerOperator cont) {
0171: this (cont, 0);
0172: }
0173:
0174: /**
0175: * Searches JComponent in container.
0176: * @param cont Container to search component in.
0177: * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
0178: * @param index Ordinal component index.
0179: * @return JComponent instance or null if component was not found.
0180: */
0181: public static JComponent findJComponent(Container cont,
0182: ComponentChooser chooser, int index) {
0183: return ((JComponent) findComponent(cont, new JComponentFinder(
0184: chooser), index));
0185: }
0186:
0187: /**
0188: * Searches 0'th JComponent in container.
0189: * @param cont Container to search component in.
0190: * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
0191: * @return JComponent instance or null if component was not found.
0192: */
0193: public static JComponent findJComponent(Container cont,
0194: ComponentChooser chooser) {
0195: return (findJComponent(cont, chooser, 0));
0196: }
0197:
0198: /**
0199: * Searches JComponent by tooltip text.
0200: * @param cont Container to search component in.
0201: * @param toolTipText Tooltip text. If null, contents is not checked.
0202: * @param ce Compare text exactly.
0203: * @param ccs Compare text case sensitively.
0204: * @param index Ordinal component index.
0205: * @return JComponent instance or null if component was not found.
0206: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0207: */
0208: public static JComponent findJComponent(Container cont,
0209: String toolTipText, boolean ce, boolean ccs, int index) {
0210: return (findJComponent(cont, new JComponentByTipFinder(
0211: toolTipText, new DefaultStringComparator(ce, ccs)),
0212: index));
0213: }
0214:
0215: /**
0216: * Searches JComponent by tooltip text.
0217: * @param cont Container to search component in.
0218: * @param toolTipText Tooltip text. If null, contents is not checked.
0219: * @param ce Compare text exactly.
0220: * @param ccs Compare text case sensitively.
0221: * @return JComponent instance or null if component was not found.
0222: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0223: */
0224: public static JComponent findJComponent(Container cont,
0225: String toolTipText, boolean ce, boolean ccs) {
0226: return (findJComponent(cont, toolTipText, ce, ccs, 0));
0227: }
0228:
0229: /**
0230: * Waits JComponent in container.
0231: * @param cont Container to search component in.
0232: * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
0233: * @param index Ordinal component index.
0234: * @return JComponent instance or null if component was not found.
0235: * @throws TimeoutExpiredException
0236: */
0237: public static JComponent waitJComponent(Container cont,
0238: ComponentChooser chooser, final int index) {
0239: return ((JComponent) waitComponent(cont, new JComponentFinder(
0240: chooser), index));
0241: }
0242:
0243: /**
0244: * Waits 0'th JComponent in container.
0245: * @param cont Container to search component in.
0246: * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
0247: * @return JComponent instance or null if component was not found.
0248: * @throws TimeoutExpiredException
0249: */
0250: public static JComponent waitJComponent(Container cont,
0251: ComponentChooser chooser) {
0252: return (waitJComponent(cont, chooser, 0));
0253: }
0254:
0255: /**
0256: * Waits JComponent by tooltip text.
0257: * @param cont Container to search component in.
0258: * @param toolTipText Tooltip text. If null, contents is not checked.
0259: * @param ce Compare text exactly.
0260: * @param ccs Compare text case sensitively.
0261: * @param index Ordinal component index.
0262: * @return JComponent instance or null if component was not found.
0263: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0264: * @throws TimeoutExpiredException
0265: */
0266: public static JComponent waitJComponent(Container cont,
0267: String toolTipText, boolean ce, boolean ccs, int index) {
0268: return (waitJComponent(cont, new JComponentByTipFinder(
0269: toolTipText, new DefaultStringComparator(ce, ccs)),
0270: index));
0271: }
0272:
0273: /**
0274: * Waits JComponent by tooltip text.
0275: * @param cont Container to search component in.
0276: * @param toolTipText Tooltip text. If null, contents is not checked.
0277: * @param ce Compare text exactly.
0278: * @param ccs Compare text case sensitively.
0279: * @return JComponent instance or null if component was not found.
0280: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0281: * @throws TimeoutExpiredException
0282: */
0283: public static JComponent waitJComponent(Container cont,
0284: String toolTipText, boolean ce, boolean ccs) {
0285: return (waitJComponent(cont, toolTipText, ce, ccs, 0));
0286: }
0287:
0288: static {
0289: Timeouts.initDefault("JComponentOperator.WaitToolTipTimeout",
0290: WAIT_TOOL_TIP_TIMEOUT);
0291: Timeouts.initDefault("JComponentOperator.ShowToolTipTimeout",
0292: SHOW_TOOL_TIP_TIMEOUT);
0293: }
0294:
0295: public void setTimeouts(Timeouts timeouts) {
0296: super .setTimeouts(timeouts);
0297: this .timeouts = timeouts;
0298: }
0299:
0300: public Timeouts getTimeouts() {
0301: return (timeouts);
0302: }
0303:
0304: public void setOutput(TestOut out) {
0305: output = out;
0306: super .setOutput(output.createErrorOutput());
0307: }
0308:
0309: public TestOut getOutput() {
0310: return (output);
0311: }
0312:
0313: public int getCenterXForClick() {
0314: Rectangle rect = getVisibleRect();
0315: return ((int) rect.getX() + (int) rect.getWidth() / 2);
0316: }
0317:
0318: public int getCenterYForClick() {
0319: Rectangle rect = getVisibleRect();
0320: return ((int) rect.getY() + (int) rect.getHeight() / 2);
0321: }
0322:
0323: /**
0324: * Showes tool tip.
0325: * @return JToolTip component.
0326: * @throws TimeoutExpiredException
0327: */
0328: public JToolTip showToolTip() {
0329: enterMouse();
0330: moveMouse(getCenterXForClick(), getCenterYForClick());
0331: return (waitToolTip());
0332: }
0333:
0334: public JToolTip waitToolTip() {
0335: return ((JToolTip) waitComponent(WindowOperator.waitWindow(
0336: new JToolTipWindowFinder(), 0, getTimeouts(),
0337: getOutput()), new JToolTipFinder(), 0, getTimeouts(),
0338: getOutput()));
0339: }
0340:
0341: /**
0342: * Looks for a first window-like container.
0343: * @return either WindowOperator of JInternalFrameOperator
0344: */
0345: public ContainerOperator getWindowContainerOperator() {
0346: Component resultComp;
0347: if (getSource() instanceof Window) {
0348: resultComp = getSource();
0349: } else {
0350: resultComp = getContainer(new ComponentChooser() {
0351: public boolean checkComponent(Component comp) {
0352: return (comp instanceof Window || comp instanceof JInternalFrame);
0353: }
0354:
0355: public String getDescription() {
0356: return ("");
0357: }
0358: });
0359: }
0360: ContainerOperator result;
0361: if (resultComp instanceof Window) {
0362: result = new WindowOperator((Window) resultComp);
0363: } else {
0364: result = new ContainerOperator((Container) resultComp);
0365: }
0366: result.copyEnvironment(this );
0367: return (result);
0368: }
0369:
0370: public Hashtable getDump() {
0371: Hashtable result = super .getDump();
0372: if (getToolTipText() != null) {
0373: result.put(TOOLTIP_TEXT_DPROP, getToolTipText());
0374: }
0375: //System.out.println("Dump a11y = " + System.getProperty("jemmy.dump.a11y"));
0376: if (System.getProperty("jemmy.dump.a11y") != null
0377: && System.getProperty("jemmy.dump.a11y").equals("on")) {
0378: AccessibleContext a11y = ((JComponent) getSource())
0379: .getAccessibleContext();
0380: if (a11y != null) {
0381: result.put(A11Y_DATA, "yes");
0382: String accName = (a11y.getAccessibleName() == null) ? "null"
0383: : a11y.getAccessibleName();
0384: String accDesc = (a11y.getAccessibleDescription() == null) ? "null"
0385: : a11y.getAccessibleDescription();
0386: result.put(A11Y_NAME_DPROP, accName);
0387: result.put(A11Y_DESCRIPTION_DPROP, accDesc);
0388: } else {
0389: result.put(A11Y_DATA, "no");
0390: }
0391: }
0392: return (result);
0393: }
0394:
0395: ////////////////////////////////////////////////////////
0396: //Mapping //
0397:
0398: /**Maps <code>JComponent.addAncestorListener(AncestorListener)</code> through queue*/
0399: public void addAncestorListener(
0400: final AncestorListener ancestorListener) {
0401: runMapping(new MapVoidAction("addAncestorListener") {
0402: public void map() {
0403: ((JComponent) getSource())
0404: .addAncestorListener(ancestorListener);
0405: }
0406: });
0407: }
0408:
0409: /**Maps <code>JComponent.addVetoableChangeListener(VetoableChangeListener)</code> through queue*/
0410: public void addVetoableChangeListener(
0411: final VetoableChangeListener vetoableChangeListener) {
0412: runMapping(new MapVoidAction("addVetoableChangeListener") {
0413: public void map() {
0414: ((JComponent) getSource())
0415: .addVetoableChangeListener(vetoableChangeListener);
0416: }
0417: });
0418: }
0419:
0420: /**Maps <code>JComponent.computeVisibleRect(Rectangle)</code> through queue*/
0421: public void computeVisibleRect(final Rectangle rectangle) {
0422: runMapping(new MapVoidAction("computeVisibleRect") {
0423: public void map() {
0424: ((JComponent) getSource())
0425: .computeVisibleRect(rectangle);
0426: }
0427: });
0428: }
0429:
0430: /**Maps <code>JComponent.createToolTip()</code> through queue*/
0431: public JToolTip createToolTip() {
0432: return ((JToolTip) runMapping(new MapAction("createToolTip") {
0433: public Object map() {
0434: return (((JComponent) getSource()).createToolTip());
0435: }
0436: }));
0437: }
0438:
0439: /**Maps <code>JComponent.firePropertyChange(String, byte, byte)</code> through queue*/
0440: public void firePropertyChange(final String string, final byte b,
0441: final byte b1) {
0442: runMapping(new MapVoidAction("firePropertyChange") {
0443: public void map() {
0444: ((JComponent) getSource()).firePropertyChange(string,
0445: b, b1);
0446: }
0447: });
0448: }
0449:
0450: /**Maps <code>JComponent.firePropertyChange(String, char, char)</code> through queue*/
0451: public void firePropertyChange(final String string, final char c,
0452: final char c1) {
0453: runMapping(new MapVoidAction("firePropertyChange") {
0454: public void map() {
0455: ((JComponent) getSource()).firePropertyChange(string,
0456: c, c1);
0457: }
0458: });
0459: }
0460:
0461: /**Maps <code>JComponent.firePropertyChange(String, double, double)</code> through queue*/
0462: public void firePropertyChange(final String string, final double d,
0463: final double d1) {
0464: runMapping(new MapVoidAction("firePropertyChange") {
0465: public void map() {
0466: ((JComponent) getSource()).firePropertyChange(string,
0467: d, d1);
0468: }
0469: });
0470: }
0471:
0472: /**Maps <code>JComponent.firePropertyChange(String, float, float)</code> through queue*/
0473: public void firePropertyChange(final String string, final float f,
0474: final float f1) {
0475: runMapping(new MapVoidAction("firePropertyChange") {
0476: public void map() {
0477: ((JComponent) getSource()).firePropertyChange(string,
0478: f, f1);
0479: }
0480: });
0481: }
0482:
0483: /**Maps <code>JComponent.firePropertyChange(String, int, int)</code> through queue*/
0484: public void firePropertyChange(final String string, final int i,
0485: final int i1) {
0486: runMapping(new MapVoidAction("firePropertyChange") {
0487: public void map() {
0488: ((JComponent) getSource()).firePropertyChange(string,
0489: i, i1);
0490: }
0491: });
0492: }
0493:
0494: /**Maps <code>JComponent.firePropertyChange(String, long, long)</code> through queue*/
0495: public void firePropertyChange(final String string, final long l,
0496: final long l1) {
0497: runMapping(new MapVoidAction("firePropertyChange") {
0498: public void map() {
0499: ((JComponent) getSource()).firePropertyChange(string,
0500: l, l1);
0501: }
0502: });
0503: }
0504:
0505: /**Maps <code>JComponent.firePropertyChange(String, short, short)</code> through queue*/
0506: public void firePropertyChange(final String string, final short s,
0507: final short s1) {
0508: runMapping(new MapVoidAction("firePropertyChange") {
0509: public void map() {
0510: ((JComponent) getSource()).firePropertyChange(string,
0511: s, s1);
0512: }
0513: });
0514: }
0515:
0516: /**Maps <code>JComponent.firePropertyChange(String, boolean, boolean)</code> through queue*/
0517: public void firePropertyChange(final String string,
0518: final boolean b, final boolean b1) {
0519: runMapping(new MapVoidAction("firePropertyChange") {
0520: public void map() {
0521: ((JComponent) getSource()).firePropertyChange(string,
0522: b, b1);
0523: }
0524: });
0525: }
0526:
0527: /**Maps <code>JComponent.getAccessibleContext()</code> through queue*/
0528: public AccessibleContext getAccessibleContext() {
0529: return ((AccessibleContext) runMapping(new MapAction(
0530: "getAccessibleContext") {
0531: public Object map() {
0532: return (((JComponent) getSource())
0533: .getAccessibleContext());
0534: }
0535: }));
0536: }
0537:
0538: /**Maps <code>JComponent.getActionForKeyStroke(KeyStroke)</code> through queue*/
0539: public ActionListener getActionForKeyStroke(
0540: final KeyStroke keyStroke) {
0541: return ((ActionListener) runMapping(new MapAction(
0542: "getActionForKeyStroke") {
0543: public Object map() {
0544: return (((JComponent) getSource())
0545: .getActionForKeyStroke(keyStroke));
0546: }
0547: }));
0548: }
0549:
0550: /**Maps <code>JComponent.getAutoscrolls()</code> through queue*/
0551: public boolean getAutoscrolls() {
0552: return (runMapping(new MapBooleanAction("getAutoscrolls") {
0553: public boolean map() {
0554: return (((JComponent) getSource()).getAutoscrolls());
0555: }
0556: }));
0557: }
0558:
0559: /**Maps <code>JComponent.getBorder()</code> through queue*/
0560: public Border getBorder() {
0561: return ((Border) runMapping(new MapAction("getBorder") {
0562: public Object map() {
0563: return (((JComponent) getSource()).getBorder());
0564: }
0565: }));
0566: }
0567:
0568: /**Maps <code>JComponent.getClientProperty(Object)</code> through queue*/
0569: public Object getClientProperty(final Object object) {
0570: return ((Object) runMapping(new MapAction("getClientProperty") {
0571: public Object map() {
0572: return (((JComponent) getSource())
0573: .getClientProperty(object));
0574: }
0575: }));
0576: }
0577:
0578: /**Maps <code>JComponent.getConditionForKeyStroke(KeyStroke)</code> through queue*/
0579: public int getConditionForKeyStroke(final KeyStroke keyStroke) {
0580: return (runMapping(new MapIntegerAction(
0581: "getConditionForKeyStroke") {
0582: public int map() {
0583: return (((JComponent) getSource())
0584: .getConditionForKeyStroke(keyStroke));
0585: }
0586: }));
0587: }
0588:
0589: /**Maps <code>JComponent.getDebugGraphicsOptions()</code> through queue*/
0590: public int getDebugGraphicsOptions() {
0591: return (runMapping(new MapIntegerAction(
0592: "getDebugGraphicsOptions") {
0593: public int map() {
0594: return (((JComponent) getSource())
0595: .getDebugGraphicsOptions());
0596: }
0597: }));
0598: }
0599:
0600: /**Maps <code>JComponent.getInsets(Insets)</code> through queue*/
0601: public Insets getInsets(final Insets insets) {
0602: return ((Insets) runMapping(new MapAction("getInsets") {
0603: public Object map() {
0604: return (((JComponent) getSource()).getInsets(insets));
0605: }
0606: }));
0607: }
0608:
0609: /**Maps <code>JComponent.getNextFocusableComponent()</code> through queue*/
0610: public Component getNextFocusableComponent() {
0611: return ((Component) runMapping(new MapAction(
0612: "getNextFocusableComponent") {
0613: public Object map() {
0614: return (((JComponent) getSource())
0615: .getNextFocusableComponent());
0616: }
0617: }));
0618: }
0619:
0620: /**Maps <code>JComponent.getRegisteredKeyStrokes()</code> through queue*/
0621: public KeyStroke[] getRegisteredKeyStrokes() {
0622: return ((KeyStroke[]) runMapping(new MapAction(
0623: "getRegisteredKeyStrokes") {
0624: public Object map() {
0625: return (((JComponent) getSource())
0626: .getRegisteredKeyStrokes());
0627: }
0628: }));
0629: }
0630:
0631: /**Maps <code>JComponent.getRootPane()</code> through queue*/
0632: public JRootPane getRootPane() {
0633: return ((JRootPane) runMapping(new MapAction("getRootPane") {
0634: public Object map() {
0635: return (((JComponent) getSource()).getRootPane());
0636: }
0637: }));
0638: }
0639:
0640: /**Maps <code>JComponent.getToolTipLocation(MouseEvent)</code> through queue*/
0641: public Point getToolTipLocation(final MouseEvent mouseEvent) {
0642: return ((Point) runMapping(new MapAction("getToolTipLocation") {
0643: public Object map() {
0644: return (((JComponent) getSource())
0645: .getToolTipLocation(mouseEvent));
0646: }
0647: }));
0648: }
0649:
0650: /**Maps <code>JComponent.getToolTipText()</code> through queue*/
0651: public String getToolTipText() {
0652: return ((String) runMapping(new MapAction("getToolTipText") {
0653: public Object map() {
0654: return (((JComponent) getSource()).getToolTipText());
0655: }
0656: }));
0657: }
0658:
0659: /**Maps <code>JComponent.getToolTipText(MouseEvent)</code> through queue*/
0660: public String getToolTipText(final MouseEvent mouseEvent) {
0661: return ((String) runMapping(new MapAction("getToolTipText") {
0662: public Object map() {
0663: return (((JComponent) getSource())
0664: .getToolTipText(mouseEvent));
0665: }
0666: }));
0667: }
0668:
0669: /**Maps <code>JComponent.getTopLevelAncestor()</code> through queue*/
0670: public Container getTopLevelAncestor() {
0671: return ((Container) runMapping(new MapAction(
0672: "getTopLevelAncestor") {
0673: public Object map() {
0674: return (((JComponent) getSource())
0675: .getTopLevelAncestor());
0676: }
0677: }));
0678: }
0679:
0680: /**Maps <code>JComponent.getUIClassID()</code> through queue*/
0681: public String getUIClassID() {
0682: return ((String) runMapping(new MapAction("getUIClassID") {
0683: public Object map() {
0684: return (((JComponent) getSource()).getUIClassID());
0685: }
0686: }));
0687: }
0688:
0689: /**Maps <code>JComponent.getVisibleRect()</code> through queue*/
0690: public Rectangle getVisibleRect() {
0691: return ((Rectangle) runMapping(new MapAction("getVisibleRect") {
0692: public Object map() {
0693: return (((JComponent) getSource()).getVisibleRect());
0694: }
0695: }));
0696: }
0697:
0698: /**Maps <code>JComponent.grabFocus()</code> through queue*/
0699: public void grabFocus() {
0700: runMapping(new MapVoidAction("grabFocus") {
0701: public void map() {
0702: ((JComponent) getSource()).grabFocus();
0703: }
0704: });
0705: }
0706:
0707: /**Maps <code>JComponent.isFocusCycleRoot()</code> through queue*/
0708: public boolean isFocusCycleRoot() {
0709: return (runMapping(new MapBooleanAction("isFocusCycleRoot") {
0710: public boolean map() {
0711: return (((JComponent) getSource()).isFocusCycleRoot());
0712: }
0713: }));
0714: }
0715:
0716: /**Maps <code>JComponent.isManagingFocus()</code> through queue*/
0717: public boolean isManagingFocus() {
0718: return (runMapping(new MapBooleanAction("isManagingFocus") {
0719: public boolean map() {
0720: return (((JComponent) getSource()).isManagingFocus());
0721: }
0722: }));
0723: }
0724:
0725: /**Maps <code>JComponent.isOptimizedDrawingEnabled()</code> through queue*/
0726: public boolean isOptimizedDrawingEnabled() {
0727: return (runMapping(new MapBooleanAction(
0728: "isOptimizedDrawingEnabled") {
0729: public boolean map() {
0730: return (((JComponent) getSource())
0731: .isOptimizedDrawingEnabled());
0732: }
0733: }));
0734: }
0735:
0736: /**Maps <code>JComponent.isPaintingTile()</code> through queue*/
0737: public boolean isPaintingTile() {
0738: return (runMapping(new MapBooleanAction("isPaintingTile") {
0739: public boolean map() {
0740: return (((JComponent) getSource()).isPaintingTile());
0741: }
0742: }));
0743: }
0744:
0745: /**Maps <code>JComponent.isRequestFocusEnabled()</code> through queue*/
0746: public boolean isRequestFocusEnabled() {
0747: return (runMapping(new MapBooleanAction("isRequestFocusEnabled") {
0748: public boolean map() {
0749: return (((JComponent) getSource())
0750: .isRequestFocusEnabled());
0751: }
0752: }));
0753: }
0754:
0755: /**Maps <code>JComponent.isValidateRoot()</code> through queue*/
0756: public boolean isValidateRoot() {
0757: return (runMapping(new MapBooleanAction("isValidateRoot") {
0758: public boolean map() {
0759: return (((JComponent) getSource()).isValidateRoot());
0760: }
0761: }));
0762: }
0763:
0764: /**Maps <code>JComponent.paintImmediately(int, int, int, int)</code> through queue*/
0765: public void paintImmediately(final int i, final int i1,
0766: final int i2, final int i3) {
0767: runMapping(new MapVoidAction("paintImmediately") {
0768: public void map() {
0769: ((JComponent) getSource()).paintImmediately(i, i1, i2,
0770: i3);
0771: }
0772: });
0773: }
0774:
0775: /**Maps <code>JComponent.paintImmediately(Rectangle)</code> through queue*/
0776: public void paintImmediately(final Rectangle rectangle) {
0777: runMapping(new MapVoidAction("paintImmediately") {
0778: public void map() {
0779: ((JComponent) getSource()).paintImmediately(rectangle);
0780: }
0781: });
0782: }
0783:
0784: /**Maps <code>JComponent.putClientProperty(Object, Object)</code> through queue*/
0785: public void putClientProperty(final Object object,
0786: final Object object1) {
0787: runMapping(new MapVoidAction("putClientProperty") {
0788: public void map() {
0789: ((JComponent) getSource()).putClientProperty(object,
0790: object1);
0791: }
0792: });
0793: }
0794:
0795: /**Maps <code>JComponent.registerKeyboardAction(ActionListener, String, KeyStroke, int)</code> through queue*/
0796: public void registerKeyboardAction(
0797: final ActionListener actionListener, final String string,
0798: final KeyStroke keyStroke, final int i) {
0799: runMapping(new MapVoidAction("registerKeyboardAction") {
0800: public void map() {
0801: ((JComponent) getSource()).registerKeyboardAction(
0802: actionListener, string, keyStroke, i);
0803: }
0804: });
0805: }
0806:
0807: /**Maps <code>JComponent.registerKeyboardAction(ActionListener, KeyStroke, int)</code> through queue*/
0808: public void registerKeyboardAction(
0809: final ActionListener actionListener,
0810: final KeyStroke keyStroke, final int i) {
0811: runMapping(new MapVoidAction("registerKeyboardAction") {
0812: public void map() {
0813: ((JComponent) getSource()).registerKeyboardAction(
0814: actionListener, keyStroke, i);
0815: }
0816: });
0817: }
0818:
0819: /**Maps <code>JComponent.removeAncestorListener(AncestorListener)</code> through queue*/
0820: public void removeAncestorListener(
0821: final AncestorListener ancestorListener) {
0822: runMapping(new MapVoidAction("removeAncestorListener") {
0823: public void map() {
0824: ((JComponent) getSource())
0825: .removeAncestorListener(ancestorListener);
0826: }
0827: });
0828: }
0829:
0830: /**Maps <code>JComponent.removeVetoableChangeListener(VetoableChangeListener)</code> through queue*/
0831: public void removeVetoableChangeListener(
0832: final VetoableChangeListener vetoableChangeListener) {
0833: runMapping(new MapVoidAction("removeVetoableChangeListener") {
0834: public void map() {
0835: ((JComponent) getSource())
0836: .removeVetoableChangeListener(vetoableChangeListener);
0837: }
0838: });
0839: }
0840:
0841: /**Maps <code>JComponent.repaint(Rectangle)</code> through queue*/
0842: public void repaint(final Rectangle rectangle) {
0843: runMapping(new MapVoidAction("repaint") {
0844: public void map() {
0845: ((JComponent) getSource()).repaint(rectangle);
0846: }
0847: });
0848: }
0849:
0850: /**Maps <code>JComponent.requestDefaultFocus()</code> through queue*/
0851: public boolean requestDefaultFocus() {
0852: return (runMapping(new MapBooleanAction("requestDefaultFocus") {
0853: public boolean map() {
0854: return (((JComponent) getSource())
0855: .requestDefaultFocus());
0856: }
0857: }));
0858: }
0859:
0860: /**Maps <code>JComponent.resetKeyboardActions()</code> through queue*/
0861: public void resetKeyboardActions() {
0862: runMapping(new MapVoidAction("resetKeyboardActions") {
0863: public void map() {
0864: ((JComponent) getSource()).resetKeyboardActions();
0865: }
0866: });
0867: }
0868:
0869: /**Maps <code>JComponent.revalidate()</code> through queue*/
0870: public void revalidate() {
0871: runMapping(new MapVoidAction("revalidate") {
0872: public void map() {
0873: ((JComponent) getSource()).revalidate();
0874: }
0875: });
0876: }
0877:
0878: /**Maps <code>JComponent.scrollRectToVisible(Rectangle)</code> through queue*/
0879: public void scrollRectToVisible(final Rectangle rectangle) {
0880: runMapping(new MapVoidAction("scrollRectToVisible") {
0881: public void map() {
0882: ((JComponent) getSource())
0883: .scrollRectToVisible(rectangle);
0884: }
0885: });
0886: }
0887:
0888: /**Maps <code>JComponent.setAlignmentX(float)</code> through queue*/
0889: public void setAlignmentX(final float f) {
0890: runMapping(new MapVoidAction("setAlignmentX") {
0891: public void map() {
0892: ((JComponent) getSource()).setAlignmentX(f);
0893: }
0894: });
0895: }
0896:
0897: /**Maps <code>JComponent.setAlignmentY(float)</code> through queue*/
0898: public void setAlignmentY(final float f) {
0899: runMapping(new MapVoidAction("setAlignmentY") {
0900: public void map() {
0901: ((JComponent) getSource()).setAlignmentY(f);
0902: }
0903: });
0904: }
0905:
0906: /**Maps <code>JComponent.setAutoscrolls(boolean)</code> through queue*/
0907: public void setAutoscrolls(final boolean b) {
0908: runMapping(new MapVoidAction("setAutoscrolls") {
0909: public void map() {
0910: ((JComponent) getSource()).setAutoscrolls(b);
0911: }
0912: });
0913: }
0914:
0915: /**Maps <code>JComponent.setBorder(Border)</code> through queue*/
0916: public void setBorder(final Border border) {
0917: runMapping(new MapVoidAction("setBorder") {
0918: public void map() {
0919: ((JComponent) getSource()).setBorder(border);
0920: }
0921: });
0922: }
0923:
0924: /**Maps <code>JComponent.setDebugGraphicsOptions(int)</code> through queue*/
0925: public void setDebugGraphicsOptions(final int i) {
0926: runMapping(new MapVoidAction("setDebugGraphicsOptions") {
0927: public void map() {
0928: ((JComponent) getSource()).setDebugGraphicsOptions(i);
0929: }
0930: });
0931: }
0932:
0933: /**Maps <code>JComponent.setDoubleBuffered(boolean)</code> through queue*/
0934: public void setDoubleBuffered(final boolean b) {
0935: runMapping(new MapVoidAction("setDoubleBuffered") {
0936: public void map() {
0937: ((JComponent) getSource()).setDoubleBuffered(b);
0938: }
0939: });
0940: }
0941:
0942: /**Maps <code>JComponent.setMaximumSize(Dimension)</code> through queue*/
0943: public void setMaximumSize(final Dimension dimension) {
0944: runMapping(new MapVoidAction("setMaximumSize") {
0945: public void map() {
0946: ((JComponent) getSource()).setMaximumSize(dimension);
0947: }
0948: });
0949: }
0950:
0951: /**Maps <code>JComponent.setMinimumSize(Dimension)</code> through queue*/
0952: public void setMinimumSize(final Dimension dimension) {
0953: runMapping(new MapVoidAction("setMinimumSize") {
0954: public void map() {
0955: ((JComponent) getSource()).setMinimumSize(dimension);
0956: }
0957: });
0958: }
0959:
0960: /**Maps <code>JComponent.setNextFocusableComponent(Component)</code> through queue*/
0961: public void setNextFocusableComponent(final Component component) {
0962: runMapping(new MapVoidAction("setNextFocusableComponent") {
0963: public void map() {
0964: ((JComponent) getSource())
0965: .setNextFocusableComponent(component);
0966: }
0967: });
0968: }
0969:
0970: /**Maps <code>JComponent.setOpaque(boolean)</code> through queue*/
0971: public void setOpaque(final boolean b) {
0972: runMapping(new MapVoidAction("setOpaque") {
0973: public void map() {
0974: ((JComponent) getSource()).setOpaque(b);
0975: }
0976: });
0977: }
0978:
0979: /**Maps <code>JComponent.setPreferredSize(Dimension)</code> through queue*/
0980: public void setPreferredSize(final Dimension dimension) {
0981: runMapping(new MapVoidAction("setPreferredSize") {
0982: public void map() {
0983: ((JComponent) getSource()).setPreferredSize(dimension);
0984: }
0985: });
0986: }
0987:
0988: /**Maps <code>JComponent.setRequestFocusEnabled(boolean)</code> through queue*/
0989: public void setRequestFocusEnabled(final boolean b) {
0990: runMapping(new MapVoidAction("setRequestFocusEnabled") {
0991: public void map() {
0992: ((JComponent) getSource()).setRequestFocusEnabled(b);
0993: }
0994: });
0995: }
0996:
0997: /**Maps <code>JComponent.setToolTipText(String)</code> through queue*/
0998: public void setToolTipText(final String string) {
0999: runMapping(new MapVoidAction("setToolTipText") {
1000: public void map() {
1001: ((JComponent) getSource()).setToolTipText(string);
1002: }
1003: });
1004: }
1005:
1006: /**Maps <code>JComponent.unregisterKeyboardAction(KeyStroke)</code> through queue*/
1007: public void unregisterKeyboardAction(final KeyStroke keyStroke) {
1008: runMapping(new MapVoidAction("unregisterKeyboardAction") {
1009: public void map() {
1010: ((JComponent) getSource())
1011: .unregisterKeyboardAction(keyStroke);
1012: }
1013: });
1014: }
1015:
1016: /**Maps <code>JComponent.updateUI()</code> through queue*/
1017: public void updateUI() {
1018: runMapping(new MapVoidAction("updateUI") {
1019: public void map() {
1020: ((JComponent) getSource()).updateUI();
1021: }
1022: });
1023: }
1024:
1025: //End of mapping //
1026: ////////////////////////////////////////////////////////
1027:
1028: /**
1029: * Allows to find component by tooltip.
1030: */
1031: public static class JComponentByTipFinder implements
1032: ComponentChooser {
1033: String label;
1034:
1035: StringComparator comparator;
1036: boolean compareExactly;
1037: boolean compareCaseSensitive;
1038:
1039: /**
1040: * Constructs JComponentByTipFinder.
1041: * @param lb a text pattern
1042: * @param comparator specifies string comparision algorithm.
1043: */
1044: public JComponentByTipFinder(String lb,
1045: StringComparator comparator) {
1046: label = lb;
1047: this .comparator = comparator;
1048: }
1049:
1050: /**
1051: * Constructs JComponentByTipFinder.
1052: * @param lb a text pattern
1053: */
1054: public JComponentByTipFinder(String lb) {
1055: this (lb, Operator.getDefaultStringComparator());
1056: }
1057:
1058: public boolean checkComponent(Component comp) {
1059: if (comp instanceof JComponent) {
1060: if (((JComponent) comp).getToolTipText() != null) {
1061: return (comparator.equals(((JComponent) comp)
1062: .getToolTipText(), label));
1063: }
1064: }
1065: return (false);
1066: }
1067:
1068: public String getDescription() {
1069: return ("JComponent with tool tip \"" + label + "\"");
1070: }
1071: }
1072:
1073: /**
1074: * Checks component type.
1075: */
1076: public static class JComponentFinder extends Finder {
1077: /**
1078: * Constructs JComponentFinder.
1079: * @param sf other searching criteria.
1080: */
1081: public JComponentFinder(ComponentChooser sf) {
1082: super (JComponent.class, sf);
1083: }
1084:
1085: /**
1086: * Constructs JComponentFinder.
1087: */
1088: public JComponentFinder() {
1089: super (JComponent.class);
1090: }
1091: }
1092:
1093: class JToolTipWindowFinder implements ComponentChooser {
1094: ComponentChooser ppFinder;
1095:
1096: public JToolTipWindowFinder() {
1097: ppFinder = new ComponentChooser() {
1098: public boolean checkComponent(Component comp) {
1099: return (comp.isShowing() && comp.isVisible() && comp instanceof JToolTip);
1100: }
1101:
1102: public String getDescription() {
1103: return ("A tool tip");
1104: }
1105: };
1106: }
1107:
1108: public boolean checkComponent(Component comp) {
1109: if (comp.isShowing() && comp instanceof Window) {
1110: ComponentSearcher cs = new ComponentSearcher(
1111: (Container) comp);
1112: cs.setOutput(JemmyProperties.getCurrentOutput()
1113: .createErrorOutput());
1114: return (cs.findComponent(ppFinder) != null);
1115: }
1116: return (false);
1117: }
1118:
1119: public String getDescription() {
1120: return ("A tool tip window");
1121: }
1122: }
1123:
1124: class JToolTipFinder extends Finder {
1125: public JToolTipFinder(ComponentChooser sf) {
1126: super (JToolTip.class, sf);
1127: }
1128:
1129: public JToolTipFinder() {
1130: super (JToolTip.class);
1131: }
1132: }
1133: }
|