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: JFileChooserOperator.java,v 1.13 2007/10/05 11:35:47 jskrivanek Exp $ $Revision: 1.13 $ $Date: 2007/10/05 11:35:47 $
0044: *
0045: */
0046:
0047: package org.netbeans.jemmy.operators;
0048:
0049: import java.awt.Component;
0050: import java.awt.Container;
0051: import java.awt.Window;
0052:
0053: import java.awt.event.ActionListener;
0054:
0055: import java.io.File;
0056:
0057: import javax.swing.ComboBoxModel;
0058: import javax.swing.Icon;
0059: import javax.swing.JButton;
0060: import javax.swing.JComboBox;
0061: import javax.swing.JComponent;
0062: import javax.swing.JDialog;
0063: import javax.swing.JFileChooser;
0064: import javax.swing.JList;
0065: import javax.swing.JTextField;
0066: import javax.swing.JToggleButton;
0067: import javax.swing.JButton;
0068: import javax.swing.ListModel;
0069:
0070: import javax.swing.filechooser.FileFilter;
0071: import javax.swing.filechooser.FileSystemView;
0072: import javax.swing.filechooser.FileView;
0073:
0074: import javax.swing.plaf.FileChooserUI;
0075:
0076: import org.netbeans.jemmy.ComponentChooser;
0077: import org.netbeans.jemmy.ComponentSearcher;
0078: import org.netbeans.jemmy.JemmyException;
0079: import org.netbeans.jemmy.JemmyProperties;
0080: import org.netbeans.jemmy.Outputable;
0081: import org.netbeans.jemmy.TestOut;
0082: import org.netbeans.jemmy.Timeoutable;
0083: import org.netbeans.jemmy.TimeoutExpiredException;
0084: import org.netbeans.jemmy.Timeouts;
0085: import org.netbeans.jemmy.Waiter;
0086: import org.netbeans.jemmy.Waitable;
0087:
0088: /**
0089: *
0090: * Class provides methods to cover main JFileChooser component functionality.
0091: * @author Alexandre Iline (alexandre.iline@sun.com)
0092: *
0093: */
0094:
0095: public class JFileChooserOperator extends JComponentOperator implements
0096: Timeoutable, Outputable {
0097:
0098: private final static long WAIT_LIST_PAINTED_TIMEOUT = 60000;
0099:
0100: private Timeouts timeouts;
0101: private TestOut output;
0102: private ComponentSearcher innerSearcher;
0103:
0104: /**
0105: * Constructor.
0106: * @param comp a component
0107: */
0108: public JFileChooserOperator(JFileChooser comp) {
0109: super (comp);
0110: innerSearcher = new ComponentSearcher(comp);
0111: setTimeouts(JemmyProperties.getProperties().getTimeouts());
0112: setOutput(JemmyProperties.getProperties().getOutput());
0113: }
0114:
0115: /**
0116: * Constructor.
0117: * Waits component first.
0118: * Constructor can be used in complicated cases when
0119: * output or timeouts should differ from default.
0120: * @param env an operator to get environment from.
0121: */
0122: public JFileChooserOperator(Operator env) {
0123: this ((JFileChooser) waitComponent(JDialogOperator.waitJDialog(
0124: new JFileChooserJDialogFinder(env.getOutput()), 0, env
0125: .getTimeouts(), env.getOutput()),
0126: new JFileChooserFinder(), 0, env.getTimeouts(), env
0127: .getOutput()));
0128: copyEnvironment(env);
0129: }
0130:
0131: /**
0132: * Constructor.
0133: * Waits component first.
0134: */
0135: public JFileChooserOperator() {
0136: this (getEnvironmentOperator());
0137: }
0138:
0139: /**
0140: * Searches currently opened JDilog with JFileChooser inside.
0141: * @return a component instance
0142: */
0143: public static JDialog findJFileChooserDialog() {
0144: return (JDialogOperator
0145: .findJDialog(new JFileChooserJDialogFinder(
0146: JemmyProperties.getCurrentOutput())));
0147: }
0148:
0149: /**
0150: * Waits currently opened JDilog with JFileChooser inside.
0151: * @return a component instance
0152: */
0153: public static JDialog waitJFileChooserDialog() {
0154: return (JDialogOperator
0155: .waitJDialog(new JFileChooserJDialogFinder(
0156: JemmyProperties.getCurrentOutput())));
0157: }
0158:
0159: /**
0160: * Searches JFileChooser in container.
0161: * @param cont a container
0162: * @return a component instance
0163: */
0164: public static JFileChooser findJFileChooser(Container cont) {
0165: return ((JFileChooser) findComponent(cont,
0166: new JFileChooserFinder()));
0167: }
0168:
0169: /**
0170: * Searches JFileChooser in container.
0171: * @param cont a container
0172: * @return a component instance
0173: */
0174: public static JFileChooser waitJFileChooser(Container cont) {
0175: return ((JFileChooser) waitComponent(cont,
0176: new JFileChooserFinder()));
0177: }
0178:
0179: /**
0180: * Searches currently opened JFileChooser.
0181: * @return a component instance
0182: */
0183: public static JFileChooser findJFileChooser() {
0184: return (findJFileChooser(findJFileChooserDialog()));
0185: }
0186:
0187: /**
0188: * Waits currently opened JFileChooser.
0189: * @return a component instance
0190: */
0191: public static JFileChooser waitJFileChooser() {
0192: return (waitJFileChooser(waitJFileChooserDialog()));
0193: }
0194:
0195: static {
0196: Timeouts.initDefault(
0197: "JFileChooserOperator.WaitListPaintedTimeout",
0198: WAIT_LIST_PAINTED_TIMEOUT);
0199: }
0200:
0201: public void setTimeouts(Timeouts timeouts) {
0202: super .setTimeouts(timeouts);
0203: this .timeouts = timeouts;
0204: }
0205:
0206: public Timeouts getTimeouts() {
0207: return (timeouts);
0208: }
0209:
0210: public void setOutput(TestOut out) {
0211: output = out;
0212: super .setOutput(output.createErrorOutput());
0213: if (innerSearcher != null) {
0214: innerSearcher.setOutput(output.createErrorOutput());
0215: }
0216: }
0217:
0218: public TestOut getOutput() {
0219: return (output);
0220: }
0221:
0222: /**
0223: * Returns combo box containing path (upper).
0224: * @return JComboBox being used to show directories.
0225: */
0226: public JComboBox getPathCombo() {
0227: return (getCombo(0));
0228: }
0229:
0230: /**
0231: * Returns combo box containing file types (lower).
0232: * @return JComboBox being used to show file types.
0233: */
0234: public JComboBox getFileTypesCombo() {
0235: return (getCombo(1));
0236: }
0237:
0238: /**
0239: * Returns approve button.
0240: * @return an approve button.
0241: */
0242: public JButton getApproveButton() {
0243: String aText = getApproveButtonText();
0244: if (aText == null)
0245: aText = getUI().getApproveButtonText(
0246: (JFileChooser) getSource());
0247: if (aText != null) {
0248: return ((JButton) innerSearcher
0249: .findComponent(new ButtonFinder(aText)));
0250: } else {
0251: throw (new JemmyException(
0252: "JFileChooser.getApproveButtonText() "
0253: + "and getUI().getApproveButtonText "
0254: + "return null"));
0255: }
0256: }
0257:
0258: /**
0259: * Returns cancel button.
0260: * @return a cancel button.
0261: */
0262: public JButton getCancelButton() {
0263: return ((JButton) innerSearcher.findComponent(
0264: new ComponentChooser() {
0265: public boolean checkComponent(Component comp) {
0266: return (comp != null
0267: && comp instanceof JButton
0268: && comp.getParent() != null
0269: && !(comp.getParent() instanceof JComboBox)
0270: && ((JButton) comp).getText() != null && ((JButton) comp)
0271: .getText().length() != 0);
0272: }
0273:
0274: public String getDescription() {
0275: return ("JButton");
0276: }
0277: }, 1));
0278: }
0279:
0280: /**
0281: * Returns "Home" button.
0282: * @return a "home" button.
0283: */
0284: public JButton getHomeButton() {
0285: return (getNoTextButton(1));
0286: }
0287:
0288: /**
0289: * Returns "Up One Level" button.
0290: * @return a "Up One Level" button.
0291: */
0292: public JButton getUpLevelButton() {
0293: return (getNoTextButton(0));
0294: }
0295:
0296: /**
0297: * Returns a toggle button being used to switch to list view.
0298: * @return a "list mode" button.
0299: */
0300: public JToggleButton getListToggleButton() {
0301: return (getToggleButton(0));
0302: }
0303:
0304: /**
0305: * Returns a toggle button being used to switch to detals view.
0306: * @return a "list mode" button.
0307: */
0308: public JToggleButton getDetailsToggleButton() {
0309: return (getToggleButton(1));
0310: }
0311:
0312: /**
0313: * Returns field which can be used to type path.
0314: * @return a text field being used for path typing.
0315: */
0316: public JTextField getPathField() {
0317: return ((JTextField) innerSearcher
0318: .findComponent(new ComponentChooser() {
0319: public boolean checkComponent(Component comp) {
0320: return (comp != null && comp instanceof JTextField);
0321: }
0322:
0323: public String getDescription() {
0324: return ("JTextField");
0325: }
0326: }));
0327: }
0328:
0329: /**
0330: * Returns file list.
0331: * @return a list being used to display directory content.
0332: */
0333: public JList getFileList() {
0334: return ((JList) innerSearcher
0335: .findComponent(new ComponentChooser() {
0336: public boolean checkComponent(Component comp) {
0337: return (comp != null && comp instanceof JList);
0338: }
0339:
0340: public String getDescription() {
0341: return ("JList");
0342: }
0343: }));
0344: }
0345:
0346: /**
0347: * Pushes approve button.
0348: */
0349: public void approve() {
0350: getQueueTool().waitEmpty();
0351: output.printTrace("Push approve button in JFileChooser\n : "
0352: + toStringSource());
0353: JButtonOperator approveOper = new JButtonOperator(
0354: getApproveButton());
0355: approveOper.copyEnvironment(this );
0356: approveOper.setOutput(output.createErrorOutput());
0357: approveOper.push();
0358: }
0359:
0360: /**
0361: * Pushes cancel button.
0362: */
0363: public void cancel() {
0364: output.printTrace("Push cancel button in JFileChooser\n : "
0365: + toStringSource());
0366: JButtonOperator cancelOper = new JButtonOperator(
0367: getCancelButton());
0368: cancelOper.copyEnvironment(this );
0369: cancelOper.setOutput(output.createErrorOutput());
0370: cancelOper.push();
0371: }
0372:
0373: /**
0374: * Types file name into text field and pushes approve button.
0375: * @param fileName a file to choose.
0376: */
0377: public void chooseFile(String fileName) {
0378: getQueueTool().waitEmpty();
0379: output.printTrace("Choose file by JFileChooser\n : "
0380: + fileName + "\n : " + toStringSource());
0381: JTextFieldOperator fieldOper = new JTextFieldOperator(
0382: getPathField());
0383: fieldOper.copyEnvironment(this );
0384: fieldOper.setOutput(output.createErrorOutput());
0385: //workaround
0386: fieldOper.setText(fileName);
0387: //fieldOper.clearText();
0388: //fieldOper.typeText(fileName);
0389: //approveSelection();
0390: approve();
0391: }
0392:
0393: /**
0394: * Pushes "Up One Level" button.
0395: * @return new current directory
0396: */
0397: public File goUpLevel() {
0398: getQueueTool().waitEmpty();
0399: output.printTrace("Go up level in JFileChooser\n : "
0400: + toStringSource());
0401: //workaround
0402: setCurrentDirectory(getCurrentDirectory().getParentFile());
0403: //JButtonOperator upOper = new JButtonOperator(getUpLevelButton());
0404: //upOper.copyEnvironment(this);
0405: //upOper.setOutput(output.createErrorOutput());
0406: //upOper.push();
0407: waitPainted(-1);
0408: return (getCurrentDirectory());
0409: }
0410:
0411: /**
0412: * Pushes "Home" button.
0413: * @return new current directory
0414: */
0415: public File goHome() {
0416: getQueueTool().waitEmpty();
0417: output.printTrace("Go home in JFileChooser\n : "
0418: + toStringSource());
0419: JButtonOperator homeOper = new JButtonOperator(getHomeButton());
0420: homeOper.copyEnvironment(this );
0421: homeOper.setOutput(output.createErrorOutput());
0422: homeOper.push();
0423: waitPainted(-1);
0424: return (getCurrentDirectory());
0425: }
0426:
0427: /**
0428: * Clicks on file in the list.
0429: * @param index Ordinal file index.
0430: * @param clickCount click count
0431: */
0432: public void clickOnFile(int index, int clickCount) {
0433: getQueueTool().waitEmpty();
0434: output
0435: .printTrace("Click " + Integer.toString(clickCount)
0436: + "times on " + Integer.toString(index)
0437: + "`th file in JFileChooser\n : "
0438: + toStringSource());
0439: JListOperator listOper = new JListOperator(getFileList());
0440: waitPainted(index);
0441: listOper.copyEnvironment(this );
0442: listOper.setOutput(output.createErrorOutput());
0443: listOper.clickOnItem(index, clickCount);
0444: }
0445:
0446: /**
0447: * Clicks on file in the list.
0448: * @param file File name (foo.c). Do not use full path (/tmp/foo.c) here.
0449: * @param comparator a comparator defining string comparision criteria
0450: * @param clickCount click count
0451: */
0452: public void clickOnFile(String file, StringComparator comparator,
0453: int clickCount) {
0454: output.printTrace("Click " + Integer.toString(clickCount)
0455: + "times on \"" + file
0456: + "\" file in JFileChooser\n : " + toStringSource());
0457: clickOnFile(findFileIndex(file, comparator), clickCount);
0458: }
0459:
0460: /**
0461: * Clicks on file in the list.
0462: * @param file File name (foo.c). Do not use full path (/tmp/foo.c) here.
0463: * @param ce Compare exactly. If true, text can be a substring of caption.
0464: * @param cc Compare case sensitively. If true, both text and caption are
0465: * @param clickCount click count
0466: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0467: * @deprecated Use clickOnFile(String, int) or clickOnFile(String, StringComparator, int)
0468: */
0469: public void clickOnFile(String file, boolean ce, boolean cc,
0470: int clickCount) {
0471: clickOnFile(file, new DefaultStringComparator(ce, cc),
0472: clickCount);
0473: }
0474:
0475: /**
0476: * Clicks on file in the list.
0477: * @param file File name (foo.c). Do not use full path (/tmp/foo.c) here.
0478: * @param clickCount click count
0479: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0480: */
0481: public void clickOnFile(String file, int clickCount) {
0482: clickOnFile(file, getComparator(), clickCount);
0483: }
0484:
0485: /**
0486: * Clicks on file in the list.
0487: * @param file File name (foo.c). Do not use full path (/tmp/foo.c) here.
0488: * @param comparator a comparator defining string comparision criteria
0489: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0490: */
0491: public void clickOnFile(String file, StringComparator comparator) {
0492: clickOnFile(file, comparator, 1);
0493: }
0494:
0495: /**
0496: * Clicks 1 time on file in the list.
0497: * @param file File name (foo.c). Do not use full path (/tmp/foo.c) here.
0498: * @param ce Compare exactly. If true, text can be a substring of caption.
0499: * @param cc Compare case sensitively. If true, both text and caption are
0500: * @see #clickOnFile
0501: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0502: * @deprecated Use clickOnFile(String) or clickOnFile(String, StringComparator)
0503: */
0504: public void clickOnFile(String file, boolean ce, boolean cc) {
0505: clickOnFile(file, ce, cc, 1);
0506: }
0507:
0508: /**
0509: * Clicks 1 time on file in the list.
0510: * @param file File name (foo.c). Do not use full path (/tmp/foo.c) here.
0511: * @see #clickOnFile
0512: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0513: */
0514: public void clickOnFile(String file) {
0515: clickOnFile(file, 1);
0516: }
0517:
0518: /**
0519: * Enters into subdirectory.
0520: * @param dir A directory to enter into.
0521: * @param comparator a comparator defining string comparision criteria
0522: * @return new current directory
0523: */
0524: public File enterSubDir(String dir, StringComparator comparator) {
0525: getQueueTool().waitEmpty();
0526: selectFile(dir, comparator);
0527: int index = findFileIndex(dir, comparator);
0528: waitPainted(index);
0529: setCurrentDirectory(getSelectedFile());
0530: return (getCurrentDirectory());
0531: }
0532:
0533: /**
0534: * Enters into subdir curently displayed in the list.
0535: * @param dir Directory name (tmp1). Do not use full path (/tmp/tmp1) here.
0536: * @param ce Compare exactly. If true, text can be a substring of caption.
0537: * @param cc Compare case sensitively. If true, both text and caption are
0538: * @return new current directory
0539: * @see #clickOnFile
0540: * @deprecated Use enterSubDir(String) or enterSubDir(String, StringComparator)
0541: */
0542: public File enterSubDir(String dir, boolean ce, boolean cc) {
0543: return (enterSubDir(dir, new DefaultStringComparator(ce, cc)));
0544: }
0545:
0546: /**
0547: * Enters into subdir curently displayed in the list.
0548: * @param dir Directory name (tmp1). Do not use full path (/tmp/tmp1) here.
0549: * @return new current directory
0550: * @see #clickOnFile
0551: */
0552: public File enterSubDir(String dir) {
0553: return (enterSubDir(dir, getComparator()));
0554: }
0555:
0556: /**
0557: * Selects a file curently in the list.
0558: * @param file File name (foo.c). Do not use full path (/tmp/foo.c) here.
0559: * @param comparator a comparator defining string comparision criteria
0560: * @see #clickOnFile
0561: */
0562: public void selectFile(String file, StringComparator comparator) {
0563: getQueueTool().waitEmpty();
0564: int index = findFileIndex(file, comparator);
0565: JListOperator listOper = new JListOperator(getFileList());
0566: waitPainted(index);
0567: listOper.copyEnvironment(this );
0568: listOper.setOutput(output.createErrorOutput());
0569: listOper.setSelectedIndex(index);
0570: }
0571:
0572: /**
0573: * Selects a file curently in the list.
0574: * @param file File name (foo.c). Do not use full path (/tmp/foo.c) here.
0575: * @param ce Compare exactly. If true, text can be a substring of caption.
0576: * @param cc Compare case sensitively. If true, both text and caption are
0577: * @see #clickOnFile
0578: * @deprecated Use selectFile(String) or selectFile(String, StringComparator)
0579: */
0580: public void selectFile(String file, boolean ce, boolean cc) {
0581: clickOnFile(file, ce, cc);
0582: }
0583:
0584: /**
0585: * Selects a file curently in the list.
0586: * @param file File name (foo.c). Do not use full path (/tmp/foo.c) here.
0587: * @see #clickOnFile
0588: */
0589: public void selectFile(String file) {
0590: clickOnFile(file);
0591: }
0592:
0593: /**
0594: * Selects directory from the combo box above.
0595: * @param dir Directory name (tmp1). Do not use full path (/tmp/tmp1) here.
0596: * @param comparator a comparator defining string comparision criteria
0597: */
0598: public void selectPathDirectory(String dir,
0599: StringComparator comparator) {
0600: getQueueTool().waitEmpty();
0601: output.printTrace("Select \"" + dir
0602: + "\" directory in JFileChooser\n : "
0603: + toStringSource());
0604: JComboBoxOperator comboOper = new JComboBoxOperator(
0605: getPathCombo());
0606: comboOper.copyEnvironment(this );
0607: comboOper.setOutput(output.createErrorOutput());
0608: //workaround
0609: comboOper.setSelectedIndex(findDirIndex(dir, comparator));
0610: //comboOper.selectItem(findDirIndex(dir, comparator));
0611: waitPainted(-1);
0612: }
0613:
0614: /**
0615: * Selects directory from the combo box above.
0616: * @param dir Directory name (tmp1). Do not use full path (/tmp/tmp1) here.
0617: * @param ce Compare exactly. If true, text can be a substring of caption.
0618: * @param cc Compare case sensitively. If true, both text and caption are
0619: * @deprecated Use selectPathDirectory(String) or selectPathDirectory(String, StringComparator)
0620: */
0621: public void selectPathDirectory(String dir, boolean ce, boolean cc) {
0622: selectPathDirectory(dir, new DefaultStringComparator(ce, cc));
0623: }
0624:
0625: /**
0626: * Selects directory from the combo box above.
0627: * @param dir Directory name (tmp1). Do not use full path (/tmp/tmp1) here.
0628: */
0629: public void selectPathDirectory(String dir) {
0630: selectPathDirectory(dir, getComparator());
0631: }
0632:
0633: /**
0634: * Selects file type from the combo box below.
0635: * @param filter a pattern for choosing a file type.
0636: * @param comparator a comparator defining string comparision criteria
0637: */
0638: public void selectFileType(String filter,
0639: StringComparator comparator) {
0640: getQueueTool().waitEmpty();
0641: output.printTrace("Select \"" + filter
0642: + "\" file type in JFileChooser\n : "
0643: + toStringSource());
0644: JComboBoxOperator comboOper = new JComboBoxOperator(
0645: getFileTypesCombo());
0646: comboOper.copyEnvironment(this );
0647: comboOper.setOutput(output.createErrorOutput());
0648: //workaround
0649: comboOper
0650: .setSelectedIndex(findFileTypeIndex(filter, comparator));
0651: // comboOper.selectItem(findFileTypeIndex(filter, comparator));
0652: waitPainted(-1);
0653: }
0654:
0655: /**
0656: * Selects file type from the combo box below.
0657: * @param filter a pattern for choosing a file type.
0658: * @param ce Compare exactly. If true, text can be a substring of caption.
0659: * @param cc Compare case sensitively. If true, both text and caption are
0660: * @deprecated Use selectFileType(String) or selectFileType(String, StringComparator)
0661: */
0662: public void selectFileType(String filter, boolean ce, boolean cc) {
0663: selectFileType(filter, new DefaultStringComparator(ce, cc));
0664: }
0665:
0666: /**
0667: * Selects file type from the combo box below.
0668: * @param filter a pattern for choosing a file type.
0669: */
0670: public void selectFileType(String filter) {
0671: selectFileType(filter, getComparator());
0672: }
0673:
0674: /**
0675: * Checks if file is currently displayed in the list.
0676: * @param file File name (foo.c). Do not use full path (/tmp/foo.c) here.
0677: * @param comparator a comparator defining string comparision criteria
0678: * @return true if file is displayed.
0679: */
0680: public boolean checkFileDisplayed(String file,
0681: StringComparator comparator) {
0682: waitPainted(-1);
0683: return (findFileIndex(file, comparator) != -1);
0684: }
0685:
0686: /**
0687: * Checks if file is currently displayed in the list.
0688: * @param file File name (foo.c). Do not use full path (/tmp/foo.c) here.
0689: * @param ce Compare exactly. If true, text can be a substring of caption.
0690: * @param cc Compare case sensitively. If true, both text and caption are
0691: * @return true if file is displayed.
0692: * @deprecated Use checkFileDisplayed(String) or checkFileDisplayed(String, StringComparator)
0693: */
0694: public boolean checkFileDisplayed(String file, boolean ce,
0695: boolean cc) {
0696: return (checkFileDisplayed(file, new DefaultStringComparator(
0697: ce, cc)));
0698: }
0699:
0700: /**
0701: * Checks if file is currently displayed in the list.
0702: * @param file File name (foo.c). Do not use full path (/tmp/foo.c) here.
0703: * @return true if file is displayed.
0704: */
0705: public boolean checkFileDisplayed(String file) {
0706: return (checkFileDisplayed(file, getComparator()));
0707: }
0708:
0709: /**
0710: * Return count of files currently displayed.
0711: * @return a number of items in the file list.
0712: */
0713: public int getFileCount() {
0714: waitPainted(-1);
0715: return (getFileList().getModel().getSize());
0716: }
0717:
0718: /**
0719: * Return files currently displayed.
0720: * @return an array of items from the file list.
0721: */
0722: public File[] getFiles() {
0723: waitPainted(-1);
0724: ListModel listModel = getFileList().getModel();
0725: File[] result = new File[listModel.getSize()];
0726: for (int i = 0; i < listModel.getSize(); i++) {
0727: result[i] = (File) listModel.getElementAt(i);
0728: }
0729: return (result);
0730: }
0731:
0732: /**
0733: * Waits for the file list to have required number of items.
0734: * @param count Number of files to wait.
0735: */
0736: public void waitFileCount(final int count) {
0737: waitState(new ComponentChooser() {
0738: public boolean checkComponent(Component comp) {
0739: return (getFileCount() == count);
0740: }
0741:
0742: public String getDescription() {
0743: return ("Count of files to be equal " + Integer
0744: .toString(count));
0745: }
0746: });
0747: }
0748:
0749: /**
0750: * Waits for a file to be displayed in the file list.
0751: * @param fileName a file to wait.
0752: */
0753: public void waitFileDisplayed(final String fileName) {
0754: waitState(new ComponentChooser() {
0755: public boolean checkComponent(Component comp) {
0756: return (checkFileDisplayed(fileName));
0757: }
0758:
0759: public String getDescription() {
0760: return ("\"" + fileName + "\"file to be displayed");
0761: }
0762: });
0763: }
0764:
0765: ////////////////////////////////////////////////////////
0766: //Mapping //
0767:
0768: /**Maps <code>JFileChooser.accept(File)</code> through queue*/
0769: public boolean accept(final File file) {
0770: return (runMapping(new MapBooleanAction("accept") {
0771: public boolean map() {
0772: return (((JFileChooser) getSource()).accept(file));
0773: }
0774: }));
0775: }
0776:
0777: /**Maps <code>JFileChooser.addActionListener(ActionListener)</code> through queue*/
0778: public void addActionListener(final ActionListener actionListener) {
0779: runMapping(new MapVoidAction("addActionListener") {
0780: public void map() {
0781: ((JFileChooser) getSource())
0782: .addActionListener(actionListener);
0783: }
0784: });
0785: }
0786:
0787: /**Maps <code>JFileChooser.addChoosableFileFilter(FileFilter)</code> through queue*/
0788: public void addChoosableFileFilter(final FileFilter fileFilter) {
0789: runMapping(new MapVoidAction("addChoosableFileFilter") {
0790: public void map() {
0791: ((JFileChooser) getSource())
0792: .addChoosableFileFilter(fileFilter);
0793: }
0794: });
0795: }
0796:
0797: /**Maps <code>JFileChooser.approveSelection()</code> through queue*/
0798: public void approveSelection() {
0799: runMapping(new MapVoidAction("approveSelection") {
0800: public void map() {
0801: ((JFileChooser) getSource()).approveSelection();
0802: }
0803: });
0804: }
0805:
0806: /**Maps <code>JFileChooser.cancelSelection()</code> through queue*/
0807: public void cancelSelection() {
0808: runMapping(new MapVoidAction("cancelSelection") {
0809: public void map() {
0810: ((JFileChooser) getSource()).cancelSelection();
0811: }
0812: });
0813: }
0814:
0815: /**Maps <code>JFileChooser.changeToParentDirectory()</code> through queue*/
0816: public void changeToParentDirectory() {
0817: runMapping(new MapVoidAction("changeToParentDirectory") {
0818: public void map() {
0819: ((JFileChooser) getSource()).changeToParentDirectory();
0820: }
0821: });
0822: }
0823:
0824: /**Maps <code>JFileChooser.ensureFileIsVisible(File)</code> through queue*/
0825: public void ensureFileIsVisible(final File file) {
0826: runMapping(new MapVoidAction("ensureFileIsVisible") {
0827: public void map() {
0828: ((JFileChooser) getSource()).ensureFileIsVisible(file);
0829: }
0830: });
0831: }
0832:
0833: /**Maps <code>JFileChooser.getAcceptAllFileFilter()</code> through queue*/
0834: public FileFilter getAcceptAllFileFilter() {
0835: return ((FileFilter) runMapping(new MapAction(
0836: "getAcceptAllFileFilter") {
0837: public Object map() {
0838: return (((JFileChooser) getSource())
0839: .getAcceptAllFileFilter());
0840: }
0841: }));
0842: }
0843:
0844: /**Maps <code>JFileChooser.getAccessory()</code> through queue*/
0845: public JComponent getAccessory() {
0846: return ((JComponent) runMapping(new MapAction("getAccessory") {
0847: public Object map() {
0848: return (((JFileChooser) getSource()).getAccessory());
0849: }
0850: }));
0851: }
0852:
0853: /**Maps <code>JFileChooser.getApproveButtonMnemonic()</code> through queue*/
0854: public int getApproveButtonMnemonic() {
0855: return (runMapping(new MapIntegerAction(
0856: "getApproveButtonMnemonic") {
0857: public int map() {
0858: return (((JFileChooser) getSource())
0859: .getApproveButtonMnemonic());
0860: }
0861: }));
0862: }
0863:
0864: /**Maps <code>JFileChooser.getApproveButtonText()</code> through queue*/
0865: public String getApproveButtonText() {
0866: return ((String) runMapping(new MapAction(
0867: "getApproveButtonText") {
0868: public Object map() {
0869: return (((JFileChooser) getSource())
0870: .getApproveButtonText());
0871: }
0872: }));
0873: }
0874:
0875: /**Maps <code>JFileChooser.getApproveButtonToolTipText()</code> through queue*/
0876: public String getApproveButtonToolTipText() {
0877: return ((String) runMapping(new MapAction(
0878: "getApproveButtonToolTipText") {
0879: public Object map() {
0880: return (((JFileChooser) getSource())
0881: .getApproveButtonToolTipText());
0882: }
0883: }));
0884: }
0885:
0886: /**Maps <code>JFileChooser.getChoosableFileFilters()</code> through queue*/
0887: public FileFilter[] getChoosableFileFilters() {
0888: return ((FileFilter[]) runMapping(new MapAction(
0889: "getChoosableFileFilters") {
0890: public Object map() {
0891: return (((JFileChooser) getSource())
0892: .getChoosableFileFilters());
0893: }
0894: }));
0895: }
0896:
0897: /**Maps <code>JFileChooser.getCurrentDirectory()</code> through queue*/
0898: public File getCurrentDirectory() {
0899: return ((File) runMapping(new MapAction("getCurrentDirectory") {
0900: public Object map() {
0901: return (((JFileChooser) getSource())
0902: .getCurrentDirectory());
0903: }
0904: }));
0905: }
0906:
0907: /**Maps <code>JFileChooser.getDescription(File)</code> through queue*/
0908: public String getDescription(final File file) {
0909: return ((String) runMapping(new MapAction("getDescription") {
0910: public Object map() {
0911: return (((JFileChooser) getSource())
0912: .getDescription(file));
0913: }
0914: }));
0915: }
0916:
0917: /**Maps <code>JFileChooser.getDialogTitle()</code> through queue*/
0918: public String getDialogTitle() {
0919: return ((String) runMapping(new MapAction("getDialogTitle") {
0920: public Object map() {
0921: return (((JFileChooser) getSource()).getDialogTitle());
0922: }
0923: }));
0924: }
0925:
0926: /**Maps <code>JFileChooser.getDialogType()</code> through queue*/
0927: public int getDialogType() {
0928: return (runMapping(new MapIntegerAction("getDialogType") {
0929: public int map() {
0930: return (((JFileChooser) getSource()).getDialogType());
0931: }
0932: }));
0933: }
0934:
0935: /**Maps <code>JFileChooser.getFileFilter()</code> through queue*/
0936: public FileFilter getFileFilter() {
0937: return ((FileFilter) runMapping(new MapAction("getFileFilter") {
0938: public Object map() {
0939: return (((JFileChooser) getSource()).getFileFilter());
0940: }
0941: }));
0942: }
0943:
0944: /**Maps <code>JFileChooser.getFileSelectionMode()</code> through queue*/
0945: public int getFileSelectionMode() {
0946: return (runMapping(new MapIntegerAction("getFileSelectionMode") {
0947: public int map() {
0948: return (((JFileChooser) getSource())
0949: .getFileSelectionMode());
0950: }
0951: }));
0952: }
0953:
0954: /**Maps <code>JFileChooser.getFileSystemView()</code> through queue*/
0955: public FileSystemView getFileSystemView() {
0956: return ((FileSystemView) runMapping(new MapAction(
0957: "getFileSystemView") {
0958: public Object map() {
0959: return (((JFileChooser) getSource())
0960: .getFileSystemView());
0961: }
0962: }));
0963: }
0964:
0965: /**Maps <code>JFileChooser.getFileView()</code> through queue*/
0966: public FileView getFileView() {
0967: return ((FileView) runMapping(new MapAction("getFileView") {
0968: public Object map() {
0969: return (((JFileChooser) getSource()).getFileView());
0970: }
0971: }));
0972: }
0973:
0974: /**Maps <code>JFileChooser.getIcon(File)</code> through queue*/
0975: public Icon getIcon(final File file) {
0976: return ((Icon) runMapping(new MapAction("getIcon") {
0977: public Object map() {
0978: return (((JFileChooser) getSource()).getIcon(file));
0979: }
0980: }));
0981: }
0982:
0983: /**Maps <code>JFileChooser.getName(File)</code> through queue*/
0984: public String getName(final File file) {
0985: return ((String) runMapping(new MapAction("getName") {
0986: public Object map() {
0987: return (((JFileChooser) getSource()).getName(file));
0988: }
0989: }));
0990: }
0991:
0992: /**Maps <code>JFileChooser.getSelectedFile()</code> through queue*/
0993: public File getSelectedFile() {
0994: return ((File) runMapping(new MapAction("getSelectedFile") {
0995: public Object map() {
0996: return (((JFileChooser) getSource()).getSelectedFile());
0997: }
0998: }));
0999: }
1000:
1001: /**Maps <code>JFileChooser.getSelectedFiles()</code> through queue*/
1002: public File[] getSelectedFiles() {
1003: return ((File[]) runMapping(new MapAction("getSelectedFiles") {
1004: public Object map() {
1005: return (((JFileChooser) getSource()).getSelectedFiles());
1006: }
1007: }));
1008: }
1009:
1010: /**Maps <code>JFileChooser.getTypeDescription(File)</code> through queue*/
1011: public String getTypeDescription(final File file) {
1012: return ((String) runMapping(new MapAction("getTypeDescription") {
1013: public Object map() {
1014: return (((JFileChooser) getSource())
1015: .getTypeDescription(file));
1016: }
1017: }));
1018: }
1019:
1020: /**Maps <code>JFileChooser.getUI()</code> through queue*/
1021: public FileChooserUI getUI() {
1022: return ((FileChooserUI) runMapping(new MapAction("getUI") {
1023: public Object map() {
1024: return (((JFileChooser) getSource()).getUI());
1025: }
1026: }));
1027: }
1028:
1029: /**Maps <code>JFileChooser.isDirectorySelectionEnabled()</code> through queue*/
1030: public boolean isDirectorySelectionEnabled() {
1031: return (runMapping(new MapBooleanAction(
1032: "isDirectorySelectionEnabled") {
1033: public boolean map() {
1034: return (((JFileChooser) getSource())
1035: .isDirectorySelectionEnabled());
1036: }
1037: }));
1038: }
1039:
1040: /**Maps <code>JFileChooser.isFileHidingEnabled()</code> through queue*/
1041: public boolean isFileHidingEnabled() {
1042: return (runMapping(new MapBooleanAction("isFileHidingEnabled") {
1043: public boolean map() {
1044: return (((JFileChooser) getSource())
1045: .isFileHidingEnabled());
1046: }
1047: }));
1048: }
1049:
1050: /**Maps <code>JFileChooser.isFileSelectionEnabled()</code> through queue*/
1051: public boolean isFileSelectionEnabled() {
1052: return (runMapping(new MapBooleanAction(
1053: "isFileSelectionEnabled") {
1054: public boolean map() {
1055: return (((JFileChooser) getSource())
1056: .isFileSelectionEnabled());
1057: }
1058: }));
1059: }
1060:
1061: /**Maps <code>JFileChooser.isMultiSelectionEnabled()</code> through queue*/
1062: public boolean isMultiSelectionEnabled() {
1063: return (runMapping(new MapBooleanAction(
1064: "isMultiSelectionEnabled") {
1065: public boolean map() {
1066: return (((JFileChooser) getSource())
1067: .isMultiSelectionEnabled());
1068: }
1069: }));
1070: }
1071:
1072: /**Maps <code>JFileChooser.isTraversable(File)</code> through queue*/
1073: public boolean isTraversable(final File file) {
1074: return (runMapping(new MapBooleanAction("isTraversable") {
1075: public boolean map() {
1076: return (((JFileChooser) getSource())
1077: .isTraversable(file));
1078: }
1079: }));
1080: }
1081:
1082: /**Maps <code>JFileChooser.removeActionListener(ActionListener)</code> through queue*/
1083: public void removeActionListener(final ActionListener actionListener) {
1084: runMapping(new MapVoidAction("removeActionListener") {
1085: public void map() {
1086: ((JFileChooser) getSource())
1087: .removeActionListener(actionListener);
1088: }
1089: });
1090: }
1091:
1092: /**Maps <code>JFileChooser.removeChoosableFileFilter(FileFilter)</code> through queue*/
1093: public boolean removeChoosableFileFilter(final FileFilter fileFilter) {
1094: return (runMapping(new MapBooleanAction(
1095: "removeChoosableFileFilter") {
1096: public boolean map() {
1097: return (((JFileChooser) getSource())
1098: .removeChoosableFileFilter(fileFilter));
1099: }
1100: }));
1101: }
1102:
1103: /**Maps <code>JFileChooser.rescanCurrentDirectory()</code> through queue*/
1104: public void rescanCurrentDirectory() {
1105: runMapping(new MapVoidAction("rescanCurrentDirectory") {
1106: public void map() {
1107: ((JFileChooser) getSource()).rescanCurrentDirectory();
1108: }
1109: });
1110: }
1111:
1112: /**Maps <code>JFileChooser.resetChoosableFileFilters()</code> through queue*/
1113: public void resetChoosableFileFilters() {
1114: runMapping(new MapVoidAction("resetChoosableFileFilters") {
1115: public void map() {
1116: ((JFileChooser) getSource())
1117: .resetChoosableFileFilters();
1118: }
1119: });
1120: }
1121:
1122: /**Maps <code>JFileChooser.setAccessory(JComponent)</code> through queue*/
1123: public void setAccessory(final JComponent jComponent) {
1124: runMapping(new MapVoidAction("setAccessory") {
1125: public void map() {
1126: ((JFileChooser) getSource()).setAccessory(jComponent);
1127: }
1128: });
1129: }
1130:
1131: /**Maps <code>JFileChooser.setApproveButtonMnemonic(char)</code> through queue*/
1132: public void setApproveButtonMnemonic(final char c) {
1133: runMapping(new MapVoidAction("setApproveButtonMnemonic") {
1134: public void map() {
1135: ((JFileChooser) getSource())
1136: .setApproveButtonMnemonic(c);
1137: }
1138: });
1139: }
1140:
1141: /**Maps <code>JFileChooser.setApproveButtonMnemonic(int)</code> through queue*/
1142: public void setApproveButtonMnemonic(final int i) {
1143: runMapping(new MapVoidAction("setApproveButtonMnemonic") {
1144: public void map() {
1145: ((JFileChooser) getSource())
1146: .setApproveButtonMnemonic(i);
1147: }
1148: });
1149: }
1150:
1151: /**Maps <code>JFileChooser.setApproveButtonText(String)</code> through queue*/
1152: public void setApproveButtonText(final String string) {
1153: runMapping(new MapVoidAction("setApproveButtonText") {
1154: public void map() {
1155: ((JFileChooser) getSource())
1156: .setApproveButtonText(string);
1157: }
1158: });
1159: }
1160:
1161: /**Maps <code>JFileChooser.setApproveButtonToolTipText(String)</code> through queue*/
1162: public void setApproveButtonToolTipText(final String string) {
1163: runMapping(new MapVoidAction("setApproveButtonToolTipText") {
1164: public void map() {
1165: ((JFileChooser) getSource())
1166: .setApproveButtonToolTipText(string);
1167: }
1168: });
1169: }
1170:
1171: /**Maps <code>JFileChooser.setCurrentDirectory(File)</code> through queue*/
1172: public void setCurrentDirectory(final File file) {
1173: runMapping(new MapVoidAction("setCurrentDirectory") {
1174: public void map() {
1175: ((JFileChooser) getSource()).setCurrentDirectory(file);
1176: }
1177: });
1178: }
1179:
1180: /**Maps <code>JFileChooser.setDialogTitle(String)</code> through queue*/
1181: public void setDialogTitle(final String string) {
1182: runMapping(new MapVoidAction("setDialogTitle") {
1183: public void map() {
1184: ((JFileChooser) getSource()).setDialogTitle(string);
1185: }
1186: });
1187: }
1188:
1189: /**Maps <code>JFileChooser.setDialogType(int)</code> through queue*/
1190: public void setDialogType(final int i) {
1191: runMapping(new MapVoidAction("setDialogType") {
1192: public void map() {
1193: ((JFileChooser) getSource()).setDialogType(i);
1194: }
1195: });
1196: }
1197:
1198: /**Maps <code>JFileChooser.setFileFilter(FileFilter)</code> through queue*/
1199: public void setFileFilter(final FileFilter fileFilter) {
1200: runMapping(new MapVoidAction("setFileFilter") {
1201: public void map() {
1202: ((JFileChooser) getSource()).setFileFilter(fileFilter);
1203: }
1204: });
1205: }
1206:
1207: /**Maps <code>JFileChooser.setFileHidingEnabled(boolean)</code> through queue*/
1208: public void setFileHidingEnabled(final boolean b) {
1209: runMapping(new MapVoidAction("setFileHidingEnabled") {
1210: public void map() {
1211: ((JFileChooser) getSource()).setFileHidingEnabled(b);
1212: }
1213: });
1214: }
1215:
1216: /**Maps <code>JFileChooser.setFileSelectionMode(int)</code> through queue*/
1217: public void setFileSelectionMode(final int i) {
1218: runMapping(new MapVoidAction("setFileSelectionMode") {
1219: public void map() {
1220: ((JFileChooser) getSource()).setFileSelectionMode(i);
1221: }
1222: });
1223: }
1224:
1225: /**Maps <code>JFileChooser.setFileSystemView(FileSystemView)</code> through queue*/
1226: public void setFileSystemView(final FileSystemView fileSystemView) {
1227: runMapping(new MapVoidAction("setFileSystemView") {
1228: public void map() {
1229: ((JFileChooser) getSource())
1230: .setFileSystemView(fileSystemView);
1231: }
1232: });
1233: }
1234:
1235: /**Maps <code>JFileChooser.setFileView(FileView)</code> through queue*/
1236: public void setFileView(final FileView fileView) {
1237: runMapping(new MapVoidAction("setFileView") {
1238: public void map() {
1239: ((JFileChooser) getSource()).setFileView(fileView);
1240: }
1241: });
1242: }
1243:
1244: /**Maps <code>JFileChooser.setMultiSelectionEnabled(boolean)</code> through queue*/
1245: public void setMultiSelectionEnabled(final boolean b) {
1246: runMapping(new MapVoidAction("setMultiSelectionEnabled") {
1247: public void map() {
1248: ((JFileChooser) getSource())
1249: .setMultiSelectionEnabled(b);
1250: }
1251: });
1252: }
1253:
1254: /**Maps <code>JFileChooser.setSelectedFile(File)</code> through queue*/
1255: public void setSelectedFile(final File file) {
1256: runMapping(new MapVoidAction("setSelectedFile") {
1257: public void map() {
1258: ((JFileChooser) getSource()).setSelectedFile(file);
1259: }
1260: });
1261: }
1262:
1263: /**Maps <code>JFileChooser.setSelectedFiles(File[])</code> through queue*/
1264: public void setSelectedFiles(final File[] file) {
1265: runMapping(new MapVoidAction("setSelectedFiles") {
1266: public void map() {
1267: ((JFileChooser) getSource()).setSelectedFiles(file);
1268: }
1269: });
1270: }
1271:
1272: /**Maps <code>JFileChooser.showDialog(Component, String)</code> through queue*/
1273: public int showDialog(final Component component, final String string) {
1274: return (runMapping(new MapIntegerAction("showDialog") {
1275: public int map() {
1276: return (((JFileChooser) getSource()).showDialog(
1277: component, string));
1278: }
1279: }));
1280: }
1281:
1282: /**Maps <code>JFileChooser.showOpenDialog(Component)</code> through queue*/
1283: public int showOpenDialog(final Component component) {
1284: return (runMapping(new MapIntegerAction("showOpenDialog") {
1285: public int map() {
1286: return (((JFileChooser) getSource())
1287: .showOpenDialog(component));
1288: }
1289: }));
1290: }
1291:
1292: /**Maps <code>JFileChooser.showSaveDialog(Component)</code> through queue*/
1293: public int showSaveDialog(final Component component) {
1294: return (runMapping(new MapIntegerAction("showSaveDialog") {
1295: public int map() {
1296: return (((JFileChooser) getSource())
1297: .showSaveDialog(component));
1298: }
1299: }));
1300: }
1301:
1302: //End of mapping //
1303: ////////////////////////////////////////////////////////
1304:
1305: private void waitPainted(int index) {
1306: Waiter drawingWaiter = new Waiter(new Waitable() {
1307: public Object actionProduced(Object param) {
1308: JList list = getFileList();
1309: int last_one = list.getModel().getSize() - 1;
1310: if (last_one == -1) {
1311: return ("");
1312: }
1313: int current = (param != null) ? ((Integer) param)
1314: .intValue() : 0;
1315: try {
1316: if (list.getCellBounds(current, current) != null) {
1317: return (list.getCellBounds(last_one, last_one));
1318: } else {
1319: return (null);
1320: }
1321: } catch (NullPointerException e) {
1322: //sometimes thrown from list.getCellBounds when item exists but not painted
1323: return (null);
1324: }
1325: }
1326:
1327: public String getDescription() {
1328: return ("List drawed");
1329: }
1330: });
1331: drawingWaiter.setTimeouts(getTimeouts().cloneThis());
1332: drawingWaiter.getTimeouts().setTimeout(
1333: "Waiter.WaitingTime",
1334: getTimeouts().getTimeout(
1335: "JFileChooserOperator.WaitListPaintedTimeout"));
1336: drawingWaiter.setOutput(getOutput().createErrorOutput());
1337: try {
1338: drawingWaiter.waitAction((index != -1) ? new Integer(index)
1339: : null);
1340: } catch (InterruptedException e) {
1341: output.printStackTrace(e);
1342: }
1343: }
1344:
1345: private JComboBox getCombo(int index) {
1346: return ((JComboBox) innerSearcher.findComponent(
1347: new ComponentChooser() {
1348: public boolean checkComponent(Component comp) {
1349: return (comp != null && comp instanceof JComboBox);
1350: }
1351:
1352: public String getDescription() {
1353: return ("JComboBox");
1354: }
1355: }, index));
1356: }
1357:
1358: private JButton getNoTextButton(int index) {
1359: return ((JButton) innerSearcher.findComponent(
1360: new ComponentChooser() {
1361: public boolean checkComponent(Component comp) {
1362: return (comp != null
1363: && comp instanceof JButton
1364: && !(comp.getParent() instanceof JComboBox) && (((JButton) comp)
1365: .getText() == null || ((JButton) comp)
1366: .getText().length() == 0));
1367: }
1368:
1369: public String getDescription() {
1370: return ("JButton");
1371: }
1372: }, index));
1373: }
1374:
1375: private JToggleButton getToggleButton(int index) {
1376: return ((JToggleButton) innerSearcher.findComponent(
1377: new ComponentChooser() {
1378: public boolean checkComponent(Component comp) {
1379: return (comp != null && comp instanceof JToggleButton);
1380: }
1381:
1382: public String getDescription() {
1383: return ("JToggleButton");
1384: }
1385: }, index));
1386: }
1387:
1388: private int findFileIndex(final String file,
1389: final StringComparator comparator) {
1390: Waiter fileWaiter = new Waiter(new Waitable() {
1391: public Object actionProduced(Object obj) {
1392: File[] files = getFiles();
1393: for (int i = 0; i < files.length; i++) {
1394: if (comparator.equals(files[i].getName(), file)) {
1395: return (new Integer(i));
1396: }
1397: }
1398: return (null);
1399: }
1400:
1401: public String getDescription() {
1402: return ("\"" + file + "\" file to be displayed");
1403: }
1404: });
1405: fileWaiter.setOutput(getOutput().createErrorOutput());
1406: fileWaiter.setTimeouts(getTimeouts().cloneThis());
1407: fileWaiter.getTimeouts().setTimeout(
1408: "Waiter.WaitingTime",
1409: getTimeouts().getTimeout(
1410: "JFileChooserOperator.WaitListPaintedTimeout"));
1411: try {
1412: return (((Integer) fileWaiter.waitAction(null)).intValue());
1413: } catch (InterruptedException e) {
1414: throw (new JemmyException("Waiting has been interrupted!"));
1415: }
1416: }
1417:
1418: private int findDirIndex(String dir, StringComparator comparator) {
1419: ComboBoxModel cbModel = getPathCombo().getModel();
1420: for (int i = cbModel.getSize() - 1; i >= 0; i--) {
1421: if (comparator.equals(((File) cbModel.getElementAt(i))
1422: .getName(), dir)) {
1423: return (i);
1424: }
1425: }
1426: return (-1);
1427: }
1428:
1429: private int findFileTypeIndex(String fileType,
1430: StringComparator comparator) {
1431: ComboBoxModel cbModel = getFileTypesCombo().getModel();
1432: for (int i = 0; i < cbModel.getSize(); i++) {
1433: if (comparator.equals(
1434: ((FileFilter) cbModel.getElementAt(i))
1435: .getDescription(), fileType)) {
1436: return (i);
1437: }
1438: }
1439: return (-1);
1440: }
1441:
1442: /**
1443: * Allows to find a dialog containing JFileChooser.
1444: */
1445: public static class JFileChooserJDialogFinder implements
1446: ComponentChooser {
1447: TestOut output;
1448: ComponentChooser subChooser;
1449:
1450: /**
1451: * Constructs JFileChooserJDialogFinder.
1452: * @param output an output to put searching message into.
1453: */
1454: public JFileChooserJDialogFinder(TestOut output) {
1455: this .output = output;
1456: subChooser = new JFileChooserFinder();
1457: }
1458:
1459: public boolean checkComponent(Component comp) {
1460: if (comp != null && comp instanceof Window
1461: && ((Window) comp).isVisible()) {
1462: ComponentSearcher searcher = new ComponentSearcher(
1463: (Container) comp);
1464: searcher.setOutput(output);
1465: return (searcher.findComponent(subChooser) != null);
1466: } else {
1467: return (false);
1468: }
1469: }
1470:
1471: public String getDescription() {
1472: return ("JFileChooser's window");
1473: }
1474: }
1475:
1476: /**
1477: * Checks component type.
1478: */
1479: public static class JFileChooserFinder extends Finder {
1480: /**
1481: * Constructs JFileChooserFinder.
1482: * @param sf other searching criteria.
1483: */
1484: public JFileChooserFinder(ComponentChooser sf) {
1485: super (JFileChooser.class, sf);
1486: }
1487:
1488: /**
1489: * Constructs JFileChooserFinder.
1490: */
1491: public JFileChooserFinder() {
1492: super (JFileChooser.class);
1493: }
1494: }
1495:
1496: private class ButtonFinder implements ComponentChooser {
1497: String text;
1498:
1499: public ButtonFinder(String text) {
1500: this .text = text;
1501: }
1502:
1503: public boolean checkComponent(Component comp) {
1504: return (comp != null && comp instanceof JButton
1505: && ((JButton) comp).getText() != null && ((JButton) comp)
1506: .getText().equals(text));
1507: }
1508:
1509: public String getDescription() {
1510: return ("\"" + text + "\" button");
1511: }
1512: }
1513:
1514: }
|