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: JInternalFrameOperator.java,v 1.13 2007/10/05 11:35:57 jskrivanek Exp $ $Revision: 1.13 $ $Date: 2007/10/05 11:35:57 $
0044: *
0045: */
0046:
0047: package org.netbeans.jemmy.operators;
0048:
0049: import org.netbeans.jemmy.ComponentSearcher;
0050: import org.netbeans.jemmy.ComponentChooser;
0051: import org.netbeans.jemmy.JemmyInputException;
0052: import org.netbeans.jemmy.JemmyProperties;
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.DriverManager;
0060: import org.netbeans.jemmy.drivers.FrameDriver;
0061: import org.netbeans.jemmy.drivers.InternalFrameDriver;
0062: import org.netbeans.jemmy.drivers.WindowDriver;
0063:
0064: import org.netbeans.jemmy.util.EmptyVisualizer;
0065:
0066: import java.awt.Component;
0067: import java.awt.Container;
0068: import java.awt.Rectangle;
0069:
0070: import java.beans.PropertyVetoException;
0071:
0072: import java.util.Hashtable;
0073:
0074: import javax.swing.Icon;
0075: import javax.swing.JButton;
0076: import javax.swing.JDesktopPane;
0077: import javax.swing.JInternalFrame;
0078: import javax.swing.JInternalFrame.JDesktopIcon;
0079: import javax.swing.JLayeredPane;
0080: import javax.swing.JMenuBar;
0081: import javax.swing.JScrollPane;
0082:
0083: import javax.swing.event.InternalFrameListener;
0084:
0085: import javax.swing.plaf.InternalFrameUI;
0086:
0087: import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
0088:
0089: /**
0090: * Class provides necessary functionality to operate with javax.swing.JInternalFrame component.
0091: *
0092: * Some methods can throw WrongInternalFrameStateException exception.
0093: *
0094: * <BR><BR>Timeouts used: <BR>
0095: * ComponentOperator.WaitComponentTimeout - time to wait component displayed <BR>
0096: * ComponentOperator.MouseClickTimeout - time between mouse pressing and releasing <BR>
0097: * AbstractButtonOperator.PushButtonTimeout - time between button pressing and releasing<BR>
0098: * JScrollBarOperator.WholeScrollTimeout - time for the whole scrolling <BR>.
0099: *
0100: * @see org.netbeans.jemmy.Timeouts
0101: * @see WrongInternalFrameStateException
0102: * @author Alexandre Iline (alexandre.iline@sun.com)
0103: */
0104:
0105: public class JInternalFrameOperator extends JComponentOperator
0106: implements Outputable, Timeoutable {
0107:
0108: /**
0109: * Identifier for a "title" property.
0110: * @see #getDump
0111: */
0112: public static final String TITLE_DPROP = "Title";
0113:
0114: /**
0115: * Identifier for a "state" property.
0116: * @see #getDump
0117: */
0118: public static final String STATE_DPROP = "State";
0119:
0120: /**
0121: * Identifier for a "normal" value of "state" property.
0122: * @see #getDump
0123: */
0124: public static final String STATE_NORMAL_DPROP_VALUE = "NORMAL";
0125:
0126: /**
0127: * Identifier for a "closed" value of "state" property.
0128: * @see #getDump
0129: */
0130: public static final String STATE_CLOSED_DPROP_VALUE = "CLOSED";
0131:
0132: /**
0133: * Identifier for a "iconified" value of "state" property.
0134: * @see #getDump
0135: */
0136: public static final String STATE_ICONIFIED_DPROP_VALUE = "ICONIFIED";
0137:
0138: /**
0139: * Identifier for a "maximized" value of "state" property.
0140: * @see #getDump
0141: */
0142: public static final String STATE_MAXIMAZED_DPROP_VALUE = "MAXIMIZED";
0143:
0144: /**
0145: * Identifier for a "resizable" property.
0146: * @see #getDump
0147: */
0148: public static final String IS_RESIZABLE_DPROP = "Resizable";
0149:
0150: /**
0151: * Identifier for a "selected" property.
0152: * @see #getDump
0153: */
0154: public static final String IS_SELECTED_DPROP = "Selected";
0155:
0156: /**
0157: * A minimizing button.
0158: */
0159: protected JButtonOperator minOper = null;
0160:
0161: /**
0162: * A maximizing button.
0163: */
0164: protected JButtonOperator maxOper = null;
0165:
0166: /**
0167: * A close button.
0168: */
0169: protected JButtonOperator closeOper = null;
0170:
0171: /**
0172: * A title operator.
0173: */
0174: protected ContainerOperator titleOperator = null;
0175: private TestOut output;
0176: private Timeouts timeouts;
0177: private JDesktopIconOperator iconOperator;
0178:
0179: WindowDriver wDriver;
0180: FrameDriver fDriver;
0181: InternalFrameDriver iDriver;
0182:
0183: /**
0184: * Constructor.
0185: * @param b a component
0186: */
0187: public JInternalFrameOperator(JInternalFrame b) {
0188: super (b);
0189: wDriver = DriverManager.getWindowDriver(getClass());
0190: fDriver = DriverManager.getFrameDriver(getClass());
0191: iDriver = DriverManager.getInternalFrameDriver(getClass());
0192: }
0193:
0194: /**
0195: * Constructs a JInternalFrameOperator object.
0196: * @param cont a container
0197: * @param chooser a component chooser specifying searching criteria.
0198: * @param index an index between appropriate ones.
0199: */
0200: public JInternalFrameOperator(ContainerOperator cont,
0201: ComponentChooser chooser, int index) {
0202: this ((JInternalFrame) cont.waitSubComponent(
0203: new JInternalFrameFinder(chooser), index));
0204: copyEnvironment(cont);
0205: }
0206:
0207: /**
0208: * Constructs a JInternalFrameOperator object.
0209: * @param cont a container
0210: * @param chooser a component chooser specifying searching criteria.
0211: */
0212: public JInternalFrameOperator(ContainerOperator cont,
0213: ComponentChooser chooser) {
0214: this (cont, chooser, 0);
0215: }
0216:
0217: /**
0218: * Constructor.
0219: * Waits component in container first.
0220: * Uses cont's timeout and output for waiting and to init operator.
0221: * @param cont a container
0222: * @param text Button text.
0223: * @param index Ordinal component index.
0224: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0225: *
0226: */
0227: public JInternalFrameOperator(ContainerOperator cont, String text,
0228: int index) {
0229: this (findOne(cont, text, index));
0230: copyEnvironment(cont);
0231: }
0232:
0233: /**
0234: * Constructor.
0235: * Waits component in container first.
0236: * Uses cont's timeout and output for waiting and to init operator.
0237: * @param cont a container
0238: * @param text Button text.
0239: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0240: *
0241: */
0242: public JInternalFrameOperator(ContainerOperator cont, String text) {
0243: this (cont, text, 0);
0244: }
0245:
0246: /**
0247: * Constructor.
0248: * Waits component in container first.
0249: * Uses cont's timeout and output for waiting and to init operator.
0250: * @param cont a container
0251: * @param index Ordinal component index.
0252: *
0253: */
0254: public JInternalFrameOperator(ContainerOperator cont, int index) {
0255: this ((JInternalFrame) waitComponent(cont,
0256: new JInternalFrameFinder(), index));
0257: copyEnvironment(cont);
0258: }
0259:
0260: /**
0261: * Constructor.
0262: * Waits component in container first.
0263: * Uses cont's timeout and output for waiting and to init operator.
0264: * @param cont a container
0265: *
0266: */
0267: public JInternalFrameOperator(ContainerOperator cont) {
0268: this (cont, 0);
0269: }
0270:
0271: /**
0272: * Searches JInternalframe in container.
0273: * @param cont Container to search component in.
0274: * @param chooser a component chooser specifying searching criteria.
0275: * @param index Ordinal component index.
0276: * @return JInternalframe instance or null if component was not found.
0277: */
0278: public static JInternalFrame findJInternalFrame(Container cont,
0279: ComponentChooser chooser, int index) {
0280: Component res = findComponent(cont, new JInternalFrameFinder(
0281: chooser), index);
0282: if (res instanceof JInternalFrame) {
0283: return ((JInternalFrame) res);
0284: } else if (res instanceof JInternalFrame.JDesktopIcon) {
0285: return (((JInternalFrame.JDesktopIcon) res)
0286: .getInternalFrame());
0287: } else {
0288: return (null);
0289: }
0290: }
0291:
0292: /**
0293: * Searches JInternalframe in container.
0294: * @param cont Container to search component in.
0295: * @param chooser a component chooser specifying searching criteria.
0296: * @return JInternalframe instance or null if component was not found.
0297: */
0298: public static JInternalFrame findJInternalFrame(Container cont,
0299: ComponentChooser chooser) {
0300: return (findJInternalFrame(cont, chooser, 0));
0301: }
0302:
0303: /**
0304: * Searches JInternalframe by title.
0305: * @param cont Container to search component in.
0306: * @param text Component text.
0307: * @param ce Compare text exactly.
0308: * @param ccs Compare text case sensitively.
0309: * @param index Ordinal component index.
0310: * @return JInternalframe instance or null if component was not found.
0311: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0312: */
0313: public static JInternalFrame findJInternalFrame(Container cont,
0314: String text, boolean ce, boolean ccs, int index) {
0315: return (findJInternalFrame(cont,
0316: new JInternalFrameByTitleFinder(text,
0317: new DefaultStringComparator(ce, ccs)), index));
0318: }
0319:
0320: /**
0321: * Searches JInternalframe by title.
0322: * @param cont Container to search component in.
0323: * @param text Component text.
0324: * @param ce Compare text exactly.
0325: * @param ccs Compare text case sensitively.
0326: * @return JInternalframe instance or null if component was not found.
0327: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0328: */
0329: public static JInternalFrame findJInternalFrame(Container cont,
0330: String text, boolean ce, boolean ccs) {
0331: return (findJInternalFrame(cont, text, ce, ccs, 0));
0332: }
0333:
0334: /**
0335: * Searches JInternalFrame object which component lies on.
0336: * @param comp Component to find JInternalFrame under.
0337: * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
0338: * @return JInternalFrame instance or null if component was not found.
0339: */
0340: public static JInternalFrame findJInternalFrameUnder(
0341: Component comp, ComponentChooser chooser) {
0342: return ((JInternalFrame) findContainerUnder(comp,
0343: new JInternalFrameFinder(chooser)));
0344: }
0345:
0346: /**
0347: * Searches JInternalFrame object which component lies on.
0348: * @param comp Component to find JInternalFrame under.
0349: * @return JInternalFrame instance or null if component was not found.
0350: */
0351: public static JInternalFrame findJInternalFrameUnder(Component comp) {
0352: return (findJInternalFrameUnder(comp,
0353: new JInternalFrameFinder()));
0354: }
0355:
0356: /**
0357: * Waits JInternalframe in container.
0358: * @param cont Container to search component in.
0359: * @param chooser a component chooser specifying searching criteria.
0360: * @param index Ordinal component index.
0361: * @return JInternalframe instance.
0362: *
0363: */
0364: public static JInternalFrame waitJInternalFrame(
0365: final Container cont, final ComponentChooser chooser,
0366: final int index) {
0367: Component res = waitComponent(cont, new JInternalFrameFinder(
0368: chooser), index);
0369: if (res instanceof JInternalFrame) {
0370: return ((JInternalFrame) res);
0371: } else if (res instanceof JInternalFrame.JDesktopIcon) {
0372: return (((JInternalFrame.JDesktopIcon) res)
0373: .getInternalFrame());
0374: } else {
0375: throw (new TimeoutExpiredException(chooser.getDescription()));
0376: }
0377: }
0378:
0379: /**
0380: * Waits JInternalframe in container.
0381: * @param cont Container to search component in.
0382: * @param chooser a component chooser specifying searching criteria.
0383: * @return JInternalframe instance.
0384: *
0385: */
0386: public static JInternalFrame waitJInternalFrame(Container cont,
0387: ComponentChooser chooser) {
0388: return (waitJInternalFrame(cont, chooser, 0));
0389: }
0390:
0391: /**
0392: * Waits JInternalframe by title.
0393: * @param cont Container to search component in.
0394: * @param text Component text.
0395: * @param ce Compare text exactly.
0396: * @param ccs Compare text case sensitively.
0397: * @param index Ordinal component index.
0398: * @return JInternalframe instance.
0399: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0400: *
0401: */
0402: public static JInternalFrame waitJInternalFrame(Container cont,
0403: String text, boolean ce, boolean ccs, int index) {
0404: return (waitJInternalFrame(cont,
0405: new JInternalFrameByTitleFinder(text,
0406: new DefaultStringComparator(ce, ccs)), index));
0407: }
0408:
0409: /**
0410: * Waits JInternalframe by title.
0411: * @param cont Container to search component in.
0412: * @param text Component text.
0413: * @param ce Compare text exactly.
0414: * @param ccs Compare text case sensitively.
0415: * @return JInternalframe instance.
0416: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0417: *
0418: */
0419: public static JInternalFrame waitJInternalFrame(Container cont,
0420: String text, boolean ce, boolean ccs) {
0421: return (waitJInternalFrame(cont, text, ce, ccs, 0));
0422: }
0423:
0424: public void setOutput(TestOut out) {
0425: output = out;
0426: super .setOutput(output.createErrorOutput());
0427: }
0428:
0429: public TestOut getOutput() {
0430: return (output);
0431: }
0432:
0433: public void setTimeouts(Timeouts times) {
0434: timeouts = times;
0435: super .setTimeouts(timeouts);
0436: }
0437:
0438: public Timeouts getTimeouts() {
0439: return (timeouts);
0440: }
0441:
0442: /**
0443: * Iconifies frame.
0444: * Note: frame should not be iconified and should be iconifiable.
0445: * @throws WrongInternalFrameStateException
0446: *
0447: */
0448: public void iconify() {
0449: output.printLine("Iconify JInternalFrame\n : "
0450: + toStringSource());
0451: output.printGolden("Iconify JInternalFrame \"" + getTitle()
0452: + "\"");
0453: checkIconified(false);
0454: makeComponentVisible();
0455: fDriver.iconify(this );
0456: if (getVerification()) {
0457: waitIcon(true);
0458: }
0459: }
0460:
0461: /**
0462: * Deiconifies frame.
0463: * Note: frame should be iconified.
0464: * @throws WrongInternalFrameStateException
0465: *
0466: */
0467: public void deiconify() {
0468: output.printLine("Deiconify JInternalFrame\n : "
0469: + toStringSource());
0470: output.printGolden("Deiconify JInternalFrame \"" + getTitle()
0471: + "\"");
0472: checkIconified(true);
0473: fDriver.deiconify(this );
0474: if (getVerification()) {
0475: waitIcon(false);
0476: }
0477: }
0478:
0479: /**
0480: * Maximizes frame.
0481: * Note: frame should not be iconified.
0482: *
0483: * @throws WrongInternalFrameStateException
0484: */
0485: public void maximize() {
0486: output.printLine("Maximize JInternalFrame\n : "
0487: + toStringSource());
0488: output.printGolden("Maximize JInternalFrame \"" + getTitle()
0489: + "\"");
0490: checkIconified(false);
0491: makeComponentVisible();
0492: fDriver.maximize(this );
0493: if (getVerification()) {
0494: waitMaximum(true);
0495: }
0496: }
0497:
0498: /**
0499: * Demaximizes frame.
0500: * Note: frame should not be iconified.
0501: *
0502: * @throws WrongInternalFrameStateException
0503: */
0504: public void demaximize() {
0505: output.printLine("Demaximize JInternalFrame\n : "
0506: + toStringSource());
0507: output.printGolden("Demaximize JInternalFrame \"" + getTitle()
0508: + "\"");
0509: checkIconified(false);
0510: makeComponentVisible();
0511: fDriver.demaximize(this );
0512: if (getVerification()) {
0513: waitMaximum(false);
0514: }
0515: }
0516:
0517: /**
0518: * Moves frame to new location.
0519: * Note: frame should not be iconified.
0520: * @param x X coordinate of a new frame location.
0521: * @param y Y coordinate of a new frame location.
0522: * @throws WrongInternalFrameStateException
0523: */
0524: public void move(int x, int y) {
0525: checkIconified(false);
0526: output.printLine("Move JInternalFrame to ("
0527: + Integer.toString(x) + "," + Integer.toString(y) + ")"
0528: + " position\n : " + toStringSource());
0529: output.printGolden("Move " + getTitle()
0530: + " JInternalFrame to (" + Integer.toString(x) + ","
0531: + Integer.toString(y) + ")" + " position");
0532: checkIconified(false);
0533: wDriver.move(this , x, y);
0534: }
0535:
0536: /**
0537: * Resizes frame.
0538: * Note: frame should not be iconified.
0539: * @param width New frame width.
0540: * @param height New frame height.
0541: * @throws WrongInternalFrameStateException
0542: */
0543: public void resize(int width, int height) {
0544: output.printLine("Resize JInternalFrame to ("
0545: + Integer.toString(width) + ","
0546: + Integer.toString(height) + ")" + " size\n : "
0547: + toStringSource());
0548: output.printGolden("Resize " + getTitle()
0549: + " JInternalFrame to (" + Integer.toString(width)
0550: + "," + Integer.toString(height) + ")" + " size");
0551: checkIconified(false);
0552: wDriver.resize(this , width, height);
0553: }
0554:
0555: /**
0556: * Activates frame.
0557: * Note: frame should not be iconified.
0558: * @throws WrongInternalFrameStateException
0559: */
0560: public void activate() {
0561: checkIconified(false);
0562: wDriver.activate(this );
0563: }
0564:
0565: /**
0566: * Closes the frame.
0567: */
0568: public void close() {
0569: checkIconified(false);
0570: wDriver.close(this );
0571: }
0572:
0573: /**
0574: * Scrolls to internal frame's rectangle.
0575: * @param x Horizontal rectangle coordinate
0576: * @param y Vertical rectangle coordinate
0577: * @param width rectangle width
0578: * @param height rectangle height
0579: *
0580: */
0581: public void scrollToRectangle(int x, int y, int width, int height) {
0582: output.printTrace("Scroll desktop pane to make \"" + getTitle()
0583: + "\" internal frame visible");
0584: output.printGolden("Scroll desktop pane to make \""
0585: + getTitle() + "\" internal frame visible");
0586: makeComponentVisible();
0587: Component cmp = isIcon() ? iconOperator.getSource()
0588: : getSource();
0589: //try to find JScrollPane under.
0590: JScrollPane scroll;
0591: if (isIcon()) {
0592: scroll = (JScrollPane) iconOperator
0593: .getContainer(new JScrollPaneOperator.JScrollPaneFinder(
0594: ComponentSearcher
0595: .getTrueChooser("JScrollPane")));
0596: } else {
0597: scroll = (JScrollPane) getContainer(new JScrollPaneOperator.JScrollPaneFinder(
0598: ComponentSearcher.getTrueChooser("JScrollPane")));
0599: }
0600: if (scroll == null) {
0601: return;
0602: }
0603: JScrollPaneOperator scroller = new JScrollPaneOperator(scroll);
0604: scroller.copyEnvironment(this );
0605: scroller.setVisualizer(new EmptyVisualizer());
0606: scroller.scrollToComponentRectangle(isIcon() ? iconOperator
0607: .getSource() : getSource(), x, y, width, height);
0608: }
0609:
0610: /**
0611: * Scrolls to internal frame's rectangle.
0612: * @param rect a rectangle to scroll to.
0613: */
0614: public void scrollToRectangle(Rectangle rect) {
0615: scrollToRectangle(rect.x, rect.y, rect.width, rect.height);
0616: }
0617:
0618: /**
0619: * Scrolls to internal frame.
0620: *
0621: */
0622: public void scrollToFrame() {
0623: if (isIcon()) {
0624: scrollToRectangle(0, 0, iconOperator.getWidth(),
0625: iconOperator.getHeight());
0626: } else {
0627: scrollToRectangle(0, 0, getWidth(), getHeight());
0628: }
0629: }
0630:
0631: /**
0632: * Waits for a minimize button inside the title pane.
0633: * @return a button operator
0634: */
0635: public JButtonOperator getMinimizeButton() {
0636: initOperators();
0637: return (minOper);
0638: }
0639:
0640: /**
0641: * Waits for a maximize button inside the title pane.
0642: * @return a button operator
0643: */
0644: public JButtonOperator getMaximizeButton() {
0645: initOperators();
0646: return (maxOper);
0647: }
0648:
0649: /**
0650: * Waits for a close button inside the title pane.
0651: * @return a button operator
0652: */
0653: public JButtonOperator getCloseButton() {
0654: initOperators();
0655: return (closeOper);
0656: }
0657:
0658: /**
0659: * Waits for the title pane.
0660: * @return a button operator
0661: */
0662: public ContainerOperator getTitleOperator() {
0663: initOperators();
0664: return (titleOperator);
0665: }
0666:
0667: /**
0668: * Creates an operator for an desktop icon.
0669: * @return an icon operator.
0670: */
0671: public JDesktopIconOperator getIconOperator() {
0672: initOperators();
0673: return (iconOperator);
0674: }
0675:
0676: /**
0677: * Waits for the frame to be iconified or deiconified.
0678: * @param icon whether the frame needs to be iconified.
0679: */
0680: public void waitIcon(final boolean icon) {
0681: waitState(new ComponentChooser() {
0682: public boolean checkComponent(Component comp) {
0683: return (((JInternalFrame) comp).isIcon() == icon);
0684: }
0685:
0686: public String getDescription() {
0687: return ("Iconified JInternalFrame");
0688: }
0689: });
0690: }
0691:
0692: /**
0693: * Waits for the frame to be maximized or demaximized.
0694: * @param maximum whether the frame needs to be maximized.
0695: */
0696: public void waitMaximum(final boolean maximum) {
0697: waitState(new ComponentChooser() {
0698: public boolean checkComponent(Component comp) {
0699: return (((JInternalFrame) comp).isMaximum() == maximum);
0700: }
0701:
0702: public String getDescription() {
0703: return ("Maximizied JInternalFrame");
0704: }
0705: });
0706: }
0707:
0708: /**
0709: * Returns information about component.
0710: */
0711: public Hashtable getDump() {
0712: Hashtable result = super .getDump();
0713: result.put(TITLE_DPROP, ((JInternalFrame) getSource())
0714: .getTitle());
0715: String state = STATE_NORMAL_DPROP_VALUE;
0716: if (((JInternalFrame) getSource()).isClosed()) {
0717: state = STATE_CLOSED_DPROP_VALUE;
0718: } else if (((JInternalFrame) getSource()).isIcon()) {
0719: state = STATE_ICONIFIED_DPROP_VALUE;
0720: } else if (((JInternalFrame) getSource()).isMaximum()) {
0721: state = STATE_MAXIMAZED_DPROP_VALUE;
0722: }
0723: result.put(STATE_DPROP, state);
0724: result.put(IS_RESIZABLE_DPROP, ((JInternalFrame) getSource())
0725: .isResizable() ? "true" : "false");
0726: result.put(IS_SELECTED_DPROP, ((JInternalFrame) getSource())
0727: .isSelected() ? "true" : "false");
0728: return (result);
0729: }
0730:
0731: ////////////////////////////////////////////////////////
0732: //Mapping //
0733:
0734: /**Maps <code>JInternalFrame.addInternalFrameListener(InternalFrameListener)</code> through queue*/
0735: public void addInternalFrameListener(
0736: final InternalFrameListener internalFrameListener) {
0737: runMapping(new MapVoidAction("addInternalFrameListener") {
0738: public void map() {
0739: ((JInternalFrame) getSource())
0740: .addInternalFrameListener(internalFrameListener);
0741: }
0742: });
0743: }
0744:
0745: /**Maps <code>JInternalFrame.dispose()</code> through queue*/
0746: public void dispose() {
0747: runMapping(new MapVoidAction("dispose") {
0748: public void map() {
0749: ((JInternalFrame) getSource()).dispose();
0750: }
0751: });
0752: }
0753:
0754: /**Maps <code>JInternalFrame.getContentPane()</code> through queue*/
0755: public Container getContentPane() {
0756: return ((Container) runMapping(new MapAction("getContentPane") {
0757: public Object map() {
0758: return (((JInternalFrame) getSource()).getContentPane());
0759: }
0760: }));
0761: }
0762:
0763: /**Maps <code>JInternalFrame.getDefaultCloseOperation()</code> through queue*/
0764: public int getDefaultCloseOperation() {
0765: return (runMapping(new MapIntegerAction(
0766: "getDefaultCloseOperation") {
0767: public int map() {
0768: return (((JInternalFrame) getSource())
0769: .getDefaultCloseOperation());
0770: }
0771: }));
0772: }
0773:
0774: /**Maps <code>JInternalFrame.getDesktopIcon()</code> through queue*/
0775: public JDesktopIcon getDesktopIcon() {
0776: return ((JDesktopIcon) runMapping(new MapAction(
0777: "getDesktopIcon") {
0778: public Object map() {
0779: return (((JInternalFrame) getSource()).getDesktopIcon());
0780: }
0781: }));
0782: }
0783:
0784: /**Maps <code>JInternalFrame.getDesktopPane()</code> through queue*/
0785: public JDesktopPane getDesktopPane() {
0786: return ((JDesktopPane) runMapping(new MapAction(
0787: "getDesktopPane") {
0788: public Object map() {
0789: return (((JInternalFrame) getSource()).getDesktopPane());
0790: }
0791: }));
0792: }
0793:
0794: /**Maps <code>JInternalFrame.getFrameIcon()</code> through queue*/
0795: public Icon getFrameIcon() {
0796: return ((Icon) runMapping(new MapAction("getFrameIcon") {
0797: public Object map() {
0798: return (((JInternalFrame) getSource()).getFrameIcon());
0799: }
0800: }));
0801: }
0802:
0803: /**Maps <code>JInternalFrame.getGlassPane()</code> through queue*/
0804: public Component getGlassPane() {
0805: return ((Component) runMapping(new MapAction("getGlassPane") {
0806: public Object map() {
0807: return (((JInternalFrame) getSource()).getGlassPane());
0808: }
0809: }));
0810: }
0811:
0812: /**Maps <code>JInternalFrame.getJMenuBar()</code> through queue*/
0813: public JMenuBar getJMenuBar() {
0814: return ((JMenuBar) runMapping(new MapAction("getJMenuBar") {
0815: public Object map() {
0816: return (((JInternalFrame) getSource()).getJMenuBar());
0817: }
0818: }));
0819: }
0820:
0821: /**Maps <code>JInternalFrame.getLayer()</code> through queue*/
0822: public int getLayer() {
0823: return (runMapping(new MapIntegerAction("getLayer") {
0824: public int map() {
0825: return (((JInternalFrame) getSource()).getLayer());
0826: }
0827: }));
0828: }
0829:
0830: /**Maps <code>JInternalFrame.getLayeredPane()</code> through queue*/
0831: public JLayeredPane getLayeredPane() {
0832: return ((JLayeredPane) runMapping(new MapAction(
0833: "getLayeredPane") {
0834: public Object map() {
0835: return (((JInternalFrame) getSource()).getLayeredPane());
0836: }
0837: }));
0838: }
0839:
0840: /**Maps <code>JInternalFrame.getTitle()</code> through queue*/
0841: public String getTitle() {
0842: return ((String) runMapping(new MapAction("getTitle") {
0843: public Object map() {
0844: return (((JInternalFrame) getSource()).getTitle());
0845: }
0846: }));
0847: }
0848:
0849: /**Maps <code>JInternalFrame.getUI()</code> through queue*/
0850: public InternalFrameUI getUI() {
0851: return ((InternalFrameUI) runMapping(new MapAction("getUI") {
0852: public Object map() {
0853: return (((JInternalFrame) getSource()).getUI());
0854: }
0855: }));
0856: }
0857:
0858: /**Maps <code>JInternalFrame.getWarningString()</code> through queue*/
0859: public String getWarningString() {
0860: return ((String) runMapping(new MapAction("getWarningString") {
0861: public Object map() {
0862: return (((JInternalFrame) getSource())
0863: .getWarningString());
0864: }
0865: }));
0866: }
0867:
0868: /**Maps <code>JInternalFrame.isClosable()</code> through queue*/
0869: public boolean isClosable() {
0870: return (runMapping(new MapBooleanAction("isClosable") {
0871: public boolean map() {
0872: return (((JInternalFrame) getSource()).isClosable());
0873: }
0874: }));
0875: }
0876:
0877: /**Maps <code>JInternalFrame.isClosed()</code> through queue*/
0878: public boolean isClosed() {
0879: return (runMapping(new MapBooleanAction("isClosed") {
0880: public boolean map() {
0881: return (((JInternalFrame) getSource()).isClosed());
0882: }
0883: }));
0884: }
0885:
0886: /**Maps <code>JInternalFrame.isIcon()</code> through queue*/
0887: public boolean isIcon() {
0888: return (runMapping(new MapBooleanAction("isIcon") {
0889: public boolean map() {
0890: return (((JInternalFrame) getSource()).isIcon());
0891: }
0892: }));
0893: }
0894:
0895: /**Maps <code>JInternalFrame.isIconifiable()</code> through queue*/
0896: public boolean isIconifiable() {
0897: return (runMapping(new MapBooleanAction("isIconifiable") {
0898: public boolean map() {
0899: return (((JInternalFrame) getSource()).isIconifiable());
0900: }
0901: }));
0902: }
0903:
0904: /**Maps <code>JInternalFrame.isMaximizable()</code> through queue*/
0905: public boolean isMaximizable() {
0906: return (runMapping(new MapBooleanAction("isMaximizable") {
0907: public boolean map() {
0908: return (((JInternalFrame) getSource()).isMaximizable());
0909: }
0910: }));
0911: }
0912:
0913: /**Maps <code>JInternalFrame.isMaximum()</code> through queue*/
0914: public boolean isMaximum() {
0915: return (runMapping(new MapBooleanAction("isMaximum") {
0916: public boolean map() {
0917: return (((JInternalFrame) getSource()).isMaximum());
0918: }
0919: }));
0920: }
0921:
0922: /**Maps <code>JInternalFrame.isResizable()</code> through queue*/
0923: public boolean isResizable() {
0924: return (runMapping(new MapBooleanAction("isResizable") {
0925: public boolean map() {
0926: return (((JInternalFrame) getSource()).isResizable());
0927: }
0928: }));
0929: }
0930:
0931: /**Maps <code>JInternalFrame.isSelected()</code> through queue*/
0932: public boolean isSelected() {
0933: return (runMapping(new MapBooleanAction("isSelected") {
0934: public boolean map() {
0935: return (((JInternalFrame) getSource()).isSelected());
0936: }
0937: }));
0938: }
0939:
0940: /**Maps <code>JInternalFrame.moveToBack()</code> through queue*/
0941: public void moveToBack() {
0942: runMapping(new MapVoidAction("moveToBack") {
0943: public void map() {
0944: ((JInternalFrame) getSource()).moveToBack();
0945: }
0946: });
0947: }
0948:
0949: /**Maps <code>JInternalFrame.moveToFront()</code> through queue*/
0950: public void moveToFront() {
0951: runMapping(new MapVoidAction("moveToFront") {
0952: public void map() {
0953: ((JInternalFrame) getSource()).moveToFront();
0954: }
0955: });
0956: }
0957:
0958: /**Maps <code>JInternalFrame.pack()</code> through queue*/
0959: public void pack() {
0960: runMapping(new MapVoidAction("pack") {
0961: public void map() {
0962: ((JInternalFrame) getSource()).pack();
0963: }
0964: });
0965: }
0966:
0967: /**Maps <code>JInternalFrame.removeInternalFrameListener(InternalFrameListener)</code> through queue*/
0968: public void removeInternalFrameListener(
0969: final InternalFrameListener internalFrameListener) {
0970: runMapping(new MapVoidAction("removeInternalFrameListener") {
0971: public void map() {
0972: ((JInternalFrame) getSource())
0973: .removeInternalFrameListener(internalFrameListener);
0974: }
0975: });
0976: }
0977:
0978: /**Maps <code>JInternalFrame.setClosable(boolean)</code> through queue*/
0979: public void setClosable(final boolean b) {
0980: runMapping(new MapVoidAction("setClosable") {
0981: public void map() {
0982: ((JInternalFrame) getSource()).setClosable(b);
0983: }
0984: });
0985: }
0986:
0987: /**Maps <code>JInternalFrame.setClosed(boolean)</code> through queue*/
0988: public void setClosed(final boolean b) {
0989: runMapping(new MapVoidAction("setClosed") {
0990: public void map() throws PropertyVetoException {
0991: ((JInternalFrame) getSource()).setClosed(b);
0992: }
0993: });
0994: }
0995:
0996: /**Maps <code>JInternalFrame.setContentPane(Container)</code> through queue*/
0997: public void setContentPane(final Container container) {
0998: runMapping(new MapVoidAction("setContentPane") {
0999: public void map() {
1000: ((JInternalFrame) getSource())
1001: .setContentPane(container);
1002: }
1003: });
1004: }
1005:
1006: /**Maps <code>JInternalFrame.setDefaultCloseOperation(int)</code> through queue*/
1007: public void setDefaultCloseOperation(final int i) {
1008: runMapping(new MapVoidAction("setDefaultCloseOperation") {
1009: public void map() {
1010: ((JInternalFrame) getSource())
1011: .setDefaultCloseOperation(i);
1012: }
1013: });
1014: }
1015:
1016: /**Maps <code>JInternalFrame.setDesktopIcon(JDesktopIcon)</code> through queue*/
1017: public void setDesktopIcon(final JDesktopIcon jDesktopIcon) {
1018: runMapping(new MapVoidAction("setDesktopIcon") {
1019: public void map() {
1020: ((JInternalFrame) getSource())
1021: .setDesktopIcon(jDesktopIcon);
1022: }
1023: });
1024: }
1025:
1026: /**Maps <code>JInternalFrame.setFrameIcon(Icon)</code> through queue*/
1027: public void setFrameIcon(final Icon icon) {
1028: runMapping(new MapVoidAction("setFrameIcon") {
1029: public void map() {
1030: ((JInternalFrame) getSource()).setFrameIcon(icon);
1031: }
1032: });
1033: }
1034:
1035: /**Maps <code>JInternalFrame.setGlassPane(Component)</code> through queue*/
1036: public void setGlassPane(final Component component) {
1037: runMapping(new MapVoidAction("setGlassPane") {
1038: public void map() {
1039: ((JInternalFrame) getSource()).setGlassPane(component);
1040: }
1041: });
1042: }
1043:
1044: /**Maps <code>JInternalFrame.setIcon(boolean)</code> through queue*/
1045: public void setIcon(final boolean b) {
1046: runMapping(new MapVoidAction("setIcon") {
1047: public void map() throws PropertyVetoException {
1048: ((JInternalFrame) getSource()).setIcon(b);
1049: }
1050: });
1051: }
1052:
1053: /**Maps <code>JInternalFrame.setIconifiable(boolean)</code> through queue*/
1054: public void setIconifiable(final boolean b) {
1055: runMapping(new MapVoidAction("setIconifiable") {
1056: public void map() {
1057: ((JInternalFrame) getSource()).setIconifiable(b);
1058: }
1059: });
1060: }
1061:
1062: /**Maps <code>JInternalFrame.setJMenuBar(JMenuBar)</code> through queue*/
1063: public void setJMenuBar(final JMenuBar jMenuBar) {
1064: runMapping(new MapVoidAction("setJMenuBar") {
1065: public void map() {
1066: ((JInternalFrame) getSource()).setJMenuBar(jMenuBar);
1067: }
1068: });
1069: }
1070:
1071: /**Maps <code>JInternalFrame.setLayer(Integer)</code> through queue*/
1072: public void setLayer(final Integer integer) {
1073: runMapping(new MapVoidAction("setLayer") {
1074: public void map() {
1075: ((JInternalFrame) getSource()).setLayer(integer);
1076: }
1077: });
1078: }
1079:
1080: /**Maps <code>JInternalFrame.setLayeredPane(JLayeredPane)</code> through queue*/
1081: public void setLayeredPane(final JLayeredPane jLayeredPane) {
1082: runMapping(new MapVoidAction("setLayeredPane") {
1083: public void map() {
1084: ((JInternalFrame) getSource())
1085: .setLayeredPane(jLayeredPane);
1086: }
1087: });
1088: }
1089:
1090: /**Maps <code>JInternalFrame.setMaximizable(boolean)</code> through queue*/
1091: public void setMaximizable(final boolean b) {
1092: runMapping(new MapVoidAction("setMaximizable") {
1093: public void map() {
1094: ((JInternalFrame) getSource()).setMaximizable(b);
1095: }
1096: });
1097: }
1098:
1099: /**Maps <code>JInternalFrame.setMaximum(boolean)</code> through queue*/
1100: public void setMaximum(final boolean b) {
1101: runMapping(new MapVoidAction("setMaximum") {
1102: public void map() throws PropertyVetoException {
1103: ((JInternalFrame) getSource()).setMaximum(b);
1104: }
1105: });
1106: }
1107:
1108: /**Maps <code>JInternalFrame.setResizable(boolean)</code> through queue*/
1109: public void setResizable(final boolean b) {
1110: runMapping(new MapVoidAction("setResizable") {
1111: public void map() {
1112: ((JInternalFrame) getSource()).setResizable(b);
1113: }
1114: });
1115: }
1116:
1117: /**Maps <code>JInternalFrame.setSelected(boolean)</code> through queue*/
1118: public void setSelected(final boolean b) {
1119: runMapping(new MapVoidAction("setSelected") {
1120: public void map() throws PropertyVetoException {
1121: ((JInternalFrame) getSource()).setSelected(b);
1122: }
1123: });
1124: }
1125:
1126: /**Maps <code>JInternalFrame.setTitle(String)</code> through queue*/
1127: public void setTitle(final String string) {
1128: runMapping(new MapVoidAction("setTitle") {
1129: public void map() {
1130: ((JInternalFrame) getSource()).setTitle(string);
1131: }
1132: });
1133: }
1134:
1135: /**Maps <code>JInternalFrame.setUI(InternalFrameUI)</code> through queue*/
1136: public void setUI(final InternalFrameUI internalFrameUI) {
1137: runMapping(new MapVoidAction("setUI") {
1138: public void map() {
1139: ((JInternalFrame) getSource()).setUI(internalFrameUI);
1140: }
1141: });
1142: }
1143:
1144: /**Maps <code>JInternalFrame.toBack()</code> through queue*/
1145: public void toBack() {
1146: runMapping(new MapVoidAction("toBack") {
1147: public void map() {
1148: ((JInternalFrame) getSource()).toBack();
1149: }
1150: });
1151: }
1152:
1153: /**Maps <code>JInternalFrame.toFront()</code> through queue*/
1154: public void toFront() {
1155: runMapping(new MapVoidAction("toFront") {
1156: public void map() {
1157: ((JInternalFrame) getSource()).toFront();
1158: }
1159: });
1160: }
1161:
1162: //End of mapping //
1163: ////////////////////////////////////////////////////////
1164:
1165: /**
1166: * Uses InternalframeDriver to get a title pane.
1167: * @return a title pane.
1168: */
1169: protected Container findTitlePane() {
1170: return ((Container) iDriver.getTitlePane(this ));
1171: }
1172:
1173: /**
1174: * Initiaites suboperators.
1175: */
1176: protected void initOperators() {
1177: iconOperator = new JDesktopIconOperator(
1178: ((JInternalFrame) getSource()).getDesktopIcon());
1179: iconOperator.copyEnvironment(this );
1180: Container titlePane = findTitlePane();
1181: if (!isIcon() && titlePane != null) {
1182: if (titleOperator == null) {
1183: titleOperator = new ContainerOperator(titlePane);
1184: int bttCount = 0;
1185: if (getContainer(new ComponentChooser() {
1186: public boolean checkComponent(Component comp) {
1187: return (comp instanceof JDesktopPane);
1188: }
1189:
1190: public String getDescription() {
1191: return ("Desctop pane");
1192: }
1193: }) != null) {
1194: minOper = new JButtonOperator(titleOperator,
1195: bttCount);
1196: bttCount++;
1197: if (((JInternalFrame) getSource()).isMaximizable()) {
1198: maxOper = new JButtonOperator(titleOperator,
1199: bttCount);
1200: bttCount++;
1201: } else {
1202: maxOper = null;
1203: }
1204: } else {
1205: minOper = null;
1206: maxOper = null;
1207: }
1208: if (isClosable()) {
1209: closeOper = new JButtonOperator(titleOperator,
1210: bttCount);
1211: } else {
1212: closeOper = null;
1213: }
1214: }
1215: } else {
1216: titleOperator = null;
1217: minOper = null;
1218: maxOper = null;
1219: closeOper = null;
1220: }
1221: }
1222:
1223: //throw exception if state is wrong
1224: private void checkIconified(boolean shouldBeIconified) {
1225: if (shouldBeIconified && !isIcon() || !shouldBeIconified
1226: && isIcon()) {
1227: throw (new WrongInternalFrameStateException(
1228: "JInternal frame should "
1229: + (shouldBeIconified ? "" : "not")
1230: + " be iconified to produce this operation",
1231: getSource()));
1232: }
1233: }
1234:
1235: private static JInternalFrame findOne(ContainerOperator cont,
1236: String text, int index) {
1237: Component source = waitComponent(cont,
1238: new JInternalFrameByTitleFinder(text, cont
1239: .getComparator()), index);
1240: if (source instanceof JInternalFrame) {
1241: return ((JInternalFrame) source);
1242: } else if (source instanceof JInternalFrame.JDesktopIcon) {
1243: return (((JInternalFrame.JDesktopIcon) source)
1244: .getInternalFrame());
1245: } else {
1246: throw (new TimeoutExpiredException(
1247: "No internal frame was found"));
1248: }
1249: }
1250:
1251: /**
1252: * Exception can be throwht if as a result of an attempt to produce
1253: * operation for the frame in incorrect state.
1254: * Like activate iconified frame, for example.
1255: */
1256: public class WrongInternalFrameStateException extends
1257: JemmyInputException {
1258: /**
1259: * Constructs a JInternalFrameOperator$WrongInternalFrameStateException object.
1260: * @param message an exception message.
1261: * @param comp an internal frame.
1262: */
1263: public WrongInternalFrameStateException(String message,
1264: Component comp) {
1265: super (message, comp);
1266: }
1267: }
1268:
1269: /**
1270: * Allows to find component by title.
1271: */
1272: public static class JInternalFrameByTitleFinder implements
1273: ComponentChooser {
1274: String label;
1275: StringComparator comparator;
1276:
1277: /**
1278: * Constructs JInternalFrameByTitleFinder.
1279: * @param lb a text pattern
1280: * @param comparator specifies string comparision algorithm.
1281: */
1282: public JInternalFrameByTitleFinder(String lb,
1283: StringComparator comparator) {
1284: label = lb;
1285: this .comparator = comparator;
1286: }
1287:
1288: /**
1289: * Constructs JInternalFrameByTitleFinder.
1290: * @param lb a text pattern
1291: */
1292: public JInternalFrameByTitleFinder(String lb) {
1293: this (lb, Operator.getDefaultStringComparator());
1294: }
1295:
1296: public boolean checkComponent(Component comp) {
1297: if (comp instanceof JInternalFrame
1298: || comp instanceof JInternalFrame.JDesktopIcon) {
1299: JInternalFrame frame = null;
1300: if (comp instanceof JInternalFrame) {
1301: frame = (JInternalFrame) comp;
1302: } else {
1303: JDesktopIconOperator io = new JDesktopIconOperator(
1304: (JInternalFrame.JDesktopIcon) comp);
1305: frame = io.getInternalFrame();
1306: }
1307: if (frame.getTitle() != null) {
1308: return (comparator.equals(frame.getTitle(), label));
1309: }
1310: }
1311: return (false);
1312: }
1313:
1314: public String getDescription() {
1315: return ("JInternalFrame with title \"" + label + "\"");
1316: }
1317: }
1318:
1319: /**
1320: * Class to operate with javax.swing.JInternalFrame.JDesktopIconOperator component.
1321: */
1322: public static class JDesktopIconOperator extends JComponentOperator
1323: implements Outputable, Timeoutable {
1324:
1325: private TestOut output;
1326: private Timeouts timeouts;
1327:
1328: /**
1329: * Constructs JDesktopIconOperator.
1330: * @param b a component
1331: */
1332: public JDesktopIconOperator(JInternalFrame.JDesktopIcon b) {
1333: super (b);
1334: setOutput(JemmyProperties.getCurrentOutput());
1335: setTimeouts(JemmyProperties.getCurrentTimeouts());
1336: }
1337:
1338: public void setOutput(TestOut out) {
1339: output = out;
1340: super .setOutput(output.createErrorOutput());
1341: }
1342:
1343: public TestOut getOutput() {
1344: return (output);
1345: }
1346:
1347: public void setTimeouts(Timeouts times) {
1348: timeouts = times;
1349: super .setTimeouts(timeouts);
1350: }
1351:
1352: public Timeouts getTimeouts() {
1353: return (timeouts);
1354: }
1355:
1356: /**
1357: * Creates an operator for the correspondent intenal frame.
1358: * @return an operator.
1359: */
1360: public JInternalFrame getInternalFrame() {
1361: return ((JInternalFrame) getEventDispatcher()
1362: .invokeExistingMethod("getInternalFrame", null,
1363: null, output));
1364: }
1365:
1366: /**
1367: * Pushs the deiconifying button.
1368: */
1369: public void pushButton() {
1370: new JButtonOperator(this ).push();
1371: }
1372: }
1373:
1374: /**
1375: * Checks component type.
1376: */
1377: public static class JInternalFrameFinder implements
1378: ComponentChooser {
1379: ComponentChooser sf = null;
1380:
1381: /**
1382: * Constructs JInternalFrameFinder.
1383: * @param sf other searching criteria.
1384: */
1385: public JInternalFrameFinder(ComponentChooser sf) {
1386: this .sf = sf;
1387: }
1388:
1389: /**
1390: * Constructs JInternalFrameFinder.
1391: */
1392: public JInternalFrameFinder() {
1393: this (
1394: ComponentSearcher
1395: .getTrueChooser("JInternalFrame or JInternalFrame.JDesktopIcon"));
1396: }
1397:
1398: public boolean checkComponent(Component comp) {
1399: return ((comp instanceof JInternalFrame || comp instanceof JInternalFrame.JDesktopIcon) && sf
1400: .checkComponent(comp));
1401: }
1402:
1403: public String getDescription() {
1404: return (sf.getDescription());
1405: }
1406: }
1407:
1408: }
|