Source Code Cross Referenced for JMenuOperator.java in  » Testing » jemmy » org » netbeans » jemmy » operators » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » jemmy » org.netbeans.jemmy.operators 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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: JMenuOperator.java,v 1.16 2007/10/05 11:35:54 jskrivanek Exp $ $Revision: 1.16 $ $Date: 2007/10/05 11:35:54 $
0044:         *
0045:         */
0046:
0047:        package org.netbeans.jemmy.operators;
0048:
0049:        import org.netbeans.jemmy.Action;
0050:        import org.netbeans.jemmy.ComponentChooser;
0051:        import org.netbeans.jemmy.ComponentSearcher;
0052:        import org.netbeans.jemmy.Outputable;
0053:        import org.netbeans.jemmy.TestOut;
0054:        import org.netbeans.jemmy.Timeoutable;
0055:        import org.netbeans.jemmy.TimeoutExpiredException;
0056:        import org.netbeans.jemmy.Timeouts;
0057:        import org.netbeans.jemmy.Waitable;
0058:        import org.netbeans.jemmy.Waiter;
0059:
0060:        import org.netbeans.jemmy.drivers.MenuDriver;
0061:        import org.netbeans.jemmy.drivers.DescriptablePathChooser;
0062:        import org.netbeans.jemmy.drivers.DriverManager;
0063:        import org.netbeans.jemmy.drivers.PathChooser;
0064:
0065:        import java.awt.Component;
0066:        import java.awt.Container;
0067:
0068:        import java.util.Hashtable;
0069:
0070:        import javax.swing.JMenu;
0071:        import javax.swing.JMenuItem;
0072:        import javax.swing.JPopupMenu;
0073:
0074:        import javax.swing.event.MenuListener;
0075:
0076:        /**
0077:         * <BR><BR>Timeouts used: <BR>
0078:         * JMenuOperator.WaitBeforePopupTimeout - time to sleep before popup expanding <BR>
0079:         * JMenuOperator.WaitPopupTimeout - time to wait popup displayed <BR>
0080:         * JMenuOperator.PushMenuTimeout - time for the whole menu operation<BR>
0081:         * JMenuItemOperator.PushMenuTimeout - time between button pressing and releasing<BR>
0082:         * ComponentOperator.WaitComponentTimeout - time to wait button displayed <BR>
0083:         * ComponentOperator.WaitComponentEnabledTimeout - time to wait button enabled <BR>.
0084:         *
0085:         * @see org.netbeans.jemmy.Timeouts
0086:         *
0087:         * @author Alexandre Iline (alexandre.iline@sun.com)
0088:         *	
0089:         */
0090:
0091:        public class JMenuOperator extends JMenuItemOperator implements 
0092:                Outputable, Timeoutable {
0093:
0094:            /**
0095:             * Identifier for a "submenu" properties.
0096:             * @see #getDump
0097:             */
0098:            public static final String SUBMENU_PREFIX_DPROP = "Submenu";
0099:
0100:            private final static long WAIT_POPUP_TIMEOUT = 60000;
0101:            private final static long WAIT_BEFORE_POPUP_TIMEOUT = 0;
0102:            private final static long PUSH_MENU_TIMEOUT = 60000;
0103:
0104:            private Timeouts timeouts;
0105:            private TestOut output;
0106:            private MenuDriver driver;
0107:
0108:            /**
0109:             * Constructor.
0110:             * @param menu a component
0111:             */
0112:            public JMenuOperator(JMenu menu) {
0113:                super (menu);
0114:                driver = DriverManager.getMenuDriver(this );
0115:            }
0116:
0117:            /**
0118:             * Constructs a JMenuOperator object.
0119:             * @param cont a container
0120:             * @param chooser a component chooser specifying searching criteria.
0121:             * @param index an index between appropriate ones.
0122:             */
0123:            public JMenuOperator(ContainerOperator cont,
0124:                    ComponentChooser chooser, int index) {
0125:                this ((JMenu) cont.waitSubComponent(new JMenuFinder(chooser),
0126:                        index));
0127:                copyEnvironment(cont);
0128:            }
0129:
0130:            /**
0131:             * Constructs a JMenuOperator object.
0132:             * @param cont a container
0133:             * @param chooser a component chooser specifying searching criteria.
0134:             */
0135:            public JMenuOperator(ContainerOperator cont,
0136:                    ComponentChooser chooser) {
0137:                this (cont, chooser, 0);
0138:            }
0139:
0140:            /**
0141:             * Constructor.
0142:             * Waits component in container first.
0143:             * Uses cont's timeout and output for waiting and to init operator.
0144:             * @param cont a container
0145:             * @param text Button text. 
0146:             * @param index Ordinal component index.
0147:             * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0148:             * @throws TimeoutExpiredException
0149:             */
0150:            public JMenuOperator(ContainerOperator cont, String text, int index) {
0151:                this ((JMenu) waitComponent(cont, new JMenuByLabelFinder(text,
0152:                        cont.getComparator()), index));
0153:                copyEnvironment(cont);
0154:            }
0155:
0156:            /**
0157:             * Constructor.
0158:             * Waits component in container first.
0159:             * Uses cont's timeout and output for waiting and to init operator.
0160:             * @param cont a container
0161:             * @param text Button text. 
0162:             * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0163:             * @throws TimeoutExpiredException
0164:             */
0165:            public JMenuOperator(ContainerOperator cont, String text) {
0166:                this (cont, text, 0);
0167:            }
0168:
0169:            /**
0170:             * Constructor.
0171:             * Waits component in container first.
0172:             * Uses cont's timeout and output for waiting and to init operator.
0173:             * @param cont a container
0174:             * @param index Ordinal component index.
0175:             * @throws TimeoutExpiredException
0176:             */
0177:            public JMenuOperator(ContainerOperator cont, int index) {
0178:                this ((JMenu) waitComponent(cont, new JMenuFinder(), index));
0179:                copyEnvironment(cont);
0180:            }
0181:
0182:            /**
0183:             * Constructor.
0184:             * Waits component in container first.
0185:             * Uses cont's timeout and output for waiting and to init operator.
0186:             * @param cont a container
0187:             * @throws TimeoutExpiredException
0188:             */
0189:            public JMenuOperator(ContainerOperator cont) {
0190:                this (cont, 0);
0191:            }
0192:
0193:            /**
0194:             * Searches JMenu in container.
0195:             * @param cont Container to search component in.
0196:             * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
0197:             * @param index Ordinal component index.
0198:             * @return JMenu instance or null if component was not found.
0199:             */
0200:            public static JMenu findJMenu(Container cont,
0201:                    ComponentChooser chooser, int index) {
0202:                return ((JMenu) findComponent(cont, new JMenuFinder(chooser),
0203:                        index));
0204:            }
0205:
0206:            /**
0207:             * Searches 0'th JMenu in container.
0208:             * @param cont Container to search component in.
0209:             * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
0210:             * @return JMenu instance or null if component was not found.
0211:             */
0212:            public static JMenu findJMenu(Container cont,
0213:                    ComponentChooser chooser) {
0214:                return (findJMenu(cont, chooser, 0));
0215:            }
0216:
0217:            /**
0218:             * Searches JMenu by text.
0219:             * @param cont Container to search component in.
0220:             * @param text Button text. If null, contents is not checked.
0221:             * @param ce Compare text exactly.
0222:             * @param ccs Compare text case sensitively.
0223:             * @param index Ordinal component index.
0224:             * @return JMenu instance or null if component was not found.
0225:             * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0226:             */
0227:            public static JMenu findJMenu(Container cont, String text,
0228:                    boolean ce, boolean ccs, int index) {
0229:                return (findJMenu(cont, new JMenuByLabelFinder(text,
0230:                        new DefaultStringComparator(ce, ccs)), index));
0231:            }
0232:
0233:            /**
0234:             * Searches JMenu by text.
0235:             * @param cont Container to search component in.
0236:             * @param text Button text. If null, contents is not checked.
0237:             * @param ce Compare text exactly.
0238:             * @param ccs Compare text case sensitively.
0239:             * @return JMenu instance or null if component was not found.
0240:             * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0241:             */
0242:            public static JMenu findJMenu(Container cont, String text,
0243:                    boolean ce, boolean ccs) {
0244:                return (findJMenu(cont, text, ce, ccs, 0));
0245:            }
0246:
0247:            /**
0248:             * Waits JMenu in container.
0249:             * @param cont Container to search component in.
0250:             * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
0251:             * @param index Ordinal component index.
0252:             * @return JMenu instance.
0253:             * @throws TimeoutExpiredException
0254:             */
0255:            public static JMenu waitJMenu(final Container cont,
0256:                    final ComponentChooser chooser, final int index) {
0257:                return ((JMenu) waitComponent(cont, new JMenuFinder(chooser),
0258:                        index));
0259:            }
0260:
0261:            /**
0262:             * Waits 0'th JMenu in container.
0263:             * @param cont Container to search component in.
0264:             * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
0265:             * @return JMenu instance.
0266:             * @throws TimeoutExpiredException
0267:             */
0268:            public static JMenu waitJMenu(Container cont,
0269:                    ComponentChooser chooser) {
0270:                return (waitJMenu(cont, chooser, 0));
0271:            }
0272:
0273:            /**
0274:             * Waits JMenu by text.
0275:             * @param cont Container to search component in.
0276:             * @param text Button text. If null, contents is not checked.
0277:             * @param ce Compare text exactly.
0278:             * @param ccs Compare text case sensitively.
0279:             * @param index Ordinal component index.
0280:             * @return JMenu instance.
0281:             * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0282:             * @throws TimeoutExpiredException
0283:             */
0284:            public static JMenu waitJMenu(Container cont, String text,
0285:                    boolean ce, boolean ccs, int index) {
0286:                return (waitJMenu(cont, new JMenuByLabelFinder(text,
0287:                        new DefaultStringComparator(ce, ccs)), index));
0288:            }
0289:
0290:            /**
0291:             * Waits JMenu by text.
0292:             * @param cont Container to search component in.
0293:             * @param text Button text. If null, contents is not checked.
0294:             * @param ce Compare text exactly.
0295:             * @param ccs Compare text case sensitively.
0296:             * @return JMenu instance.
0297:             * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0298:             * @throws TimeoutExpiredException
0299:             */
0300:            public static JMenu waitJMenu(Container cont, String text,
0301:                    boolean ce, boolean ccs) {
0302:                return (waitJMenu(cont, text, ce, ccs, 0));
0303:            }
0304:
0305:            static {
0306:                Timeouts.initDefault("JMenuOperator.WaitBeforePopupTimeout",
0307:                        WAIT_BEFORE_POPUP_TIMEOUT);
0308:                Timeouts.initDefault("JMenuOperator.WaitPopupTimeout",
0309:                        WAIT_POPUP_TIMEOUT);
0310:                Timeouts.initDefault("JMenuOperator.PushMenuTimeout",
0311:                        PUSH_MENU_TIMEOUT);
0312:            }
0313:
0314:            public void setTimeouts(Timeouts timeouts) {
0315:                super .setTimeouts(timeouts);
0316:                this .timeouts = timeouts;
0317:            }
0318:
0319:            public Timeouts getTimeouts() {
0320:                return (timeouts);
0321:            }
0322:
0323:            public void setOutput(TestOut out) {
0324:                super .setOutput(out);
0325:                output = out;
0326:            }
0327:
0328:            public TestOut getOutput() {
0329:                return (output);
0330:            }
0331:
0332:            public void copyEnvironment(Operator anotherOperator) {
0333:                super .copyEnvironment(anotherOperator);
0334:                driver = DriverManager.getMenuDriver(this );
0335:            }
0336:
0337:            /**
0338:             * Pushes menu.
0339:             * @param choosers Array of choosers to find menuItems to push.
0340:             * @return Last pushed JMenuItem.
0341:             * @throws TimeoutExpiredException
0342:             */
0343:            public JMenuItem pushMenu(final ComponentChooser[] choosers) {
0344:                return ((JMenuItem) produceTimeRestricted(new Action() {
0345:                    public Object launch(Object obj) {
0346:                        //TDB 1.5 menu workaround
0347:                        getQueueTool().waitEmpty();
0348:                        Object result = driver.pushMenu(JMenuOperator.this ,
0349:                                converChoosers(choosers));
0350:                        getQueueTool().waitEmpty();
0351:                        return (result);
0352:                    }
0353:
0354:                    public String getDescription() {
0355:                        return (createDescription(choosers));
0356:                    }
0357:                }, getTimeouts().getTimeout("JMenuOperator.PushMenuTimeout")));
0358:            }
0359:
0360:            /**
0361:             * Executes <code>pushMenu(choosers)</code> in a separate thread.
0362:             * @param choosers Array of choosers to find menuItems to push.
0363:             * @see #pushMenu(ComponentChooser[])
0364:             */
0365:            public void pushMenuNoBlock(final ComponentChooser[] choosers) {
0366:                produceNoBlocking(new NoBlockingAction("Menu pushing") {
0367:                    public Object doAction(Object param) {
0368:                        //TDB 1.5 menu workaround
0369:                        getQueueTool().waitEmpty();
0370:                        Object result = driver.pushMenu(JMenuOperator.this ,
0371:                                converChoosers(choosers));
0372:                        getQueueTool().waitEmpty();
0373:                        return (result);
0374:                    }
0375:                });
0376:            }
0377:
0378:            /**
0379:             * Pushes menu.
0380:             * @param names an array of menu texts.
0381:             * @param comparator a string comparision algorithm
0382:             * @return Last pushed JMenuItem.
0383:             * @throws TimeoutExpiredException
0384:             */
0385:            public JMenuItem pushMenu(String[] names,
0386:                    StringComparator comparator) {
0387:                return (pushMenu(JMenuItemOperator.createChoosers(names,
0388:                        comparator)));
0389:            }
0390:
0391:            /**
0392:             * Pushes menu.
0393:             * @param names Menu items texts.
0394:             * @param ce Compare text exactly.
0395:             * @param ccs Compare text case sensitively.
0396:             * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0397:             * @throws TimeoutExpiredException
0398:             * @return Last pushed JMenuItem.
0399:             * @deprecated Use pushMenu(String[]) or pushMenu(String[], StringComparator)
0400:             */
0401:            public JMenuItem pushMenu(String[] names, boolean ce, boolean ccs) {
0402:                return (pushMenu(names, new DefaultStringComparator(ce, ccs)));
0403:            }
0404:
0405:            /**
0406:             * Executes <code>pushMenu(names, ce, ccs)</code> in a separate thread.
0407:             * @param names an array of menu texts.
0408:             * @param comparator a string comparision algorithm
0409:             */
0410:            public void pushMenuNoBlock(String[] names,
0411:                    StringComparator comparator) {
0412:                pushMenuNoBlock(JMenuItemOperator.createChoosers(names,
0413:                        comparator));
0414:            }
0415:
0416:            /**
0417:             * Executes <code>pushMenu(names, ce, ccs)</code> in a separate thread.
0418:             * @param names Menu items texts.
0419:             * @param ce Compare text exactly.
0420:             * @param ccs Compare text case sensitively.
0421:             * @see #pushMenu(String[], boolean,boolean)
0422:             * @deprecated Use pushMenuNoBlock(String[]) or pushMenuNoBlock(String[], StringComparator)
0423:             */
0424:            public void pushMenuNoBlock(String[] names, boolean ce, boolean ccs) {
0425:                pushMenuNoBlock(names, new DefaultStringComparator(ce, ccs));
0426:            }
0427:
0428:            /**
0429:             * Pushes menu.
0430:             * Uses StringComparator assigned to this object,
0431:             * @param names Menu items texts.
0432:             * @return Last pushed JMenuItem.
0433:             * @throws TimeoutExpiredException
0434:             */
0435:            public JMenuItem pushMenu(String[] names) {
0436:                return (pushMenu(names, getComparator()));
0437:            }
0438:
0439:            /**
0440:             * Executes <code>pushMenu(names)</code> in a separate thread.
0441:             * @param names Menu items texts.
0442:             * @see #pushMenu(String[])
0443:             */
0444:            public void pushMenuNoBlock(String[] names) {
0445:                pushMenuNoBlock(names, getComparator());
0446:            }
0447:
0448:            /**
0449:             * Pushes menu.
0450:             * @param path a menu path.
0451:             * @param delim a path delimiter.
0452:             * @param comparator a string comparision algorithm
0453:             * @return Last pushed JMenuItem.
0454:             * @throws TimeoutExpiredException
0455:             */
0456:            public JMenuItem pushMenu(String path, String delim,
0457:                    StringComparator comparator) {
0458:                output.printLine("Pushing " + path + " menu in \n    "
0459:                        + toStringSource());
0460:                output.printGolden("Pushing " + path + " menu in \n    "
0461:                        + toStringSource());
0462:                return (pushMenu(parseString(path, delim), comparator));
0463:            }
0464:
0465:            /**
0466:             * Pushes menu. Uses PathParser assigned to this operator.
0467:             * @param path a menu path.
0468:             * @param comparator a string comparision algorithm
0469:             * @return Last pushed JMenuItem.
0470:             * @throws TimeoutExpiredException
0471:             */
0472:            public JMenuItem pushMenu(String path, StringComparator comparator) {
0473:                output.printLine("Pushing " + path + " menu in \n    "
0474:                        + toStringSource());
0475:                output.printGolden("Pushing " + path + " menu in \n    "
0476:                        + toStringSource());
0477:                return (pushMenu(parseString(path), comparator));
0478:            }
0479:
0480:            /**
0481:             * Pushes menu.
0482:             * @param path String menupath representation ("File/New", for example).
0483:             * @param delim String menupath divider ("/").
0484:             * @param ce Compare text exactly.
0485:             * @param ccs Compare text case sensitively.
0486:             * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0487:             * @return Last pushed JMenuItem.
0488:             * @throws TimeoutExpiredException
0489:             * @deprecated Use pushMenuNoBlock(String) or pushMenuNoBlock(String, StringComparator)
0490:             */
0491:            public JMenuItem pushMenu(String path, String delim, boolean ce,
0492:                    boolean ccs) {
0493:                return (pushMenu(path, delim, new DefaultStringComparator(ce,
0494:                        ccs)));
0495:            }
0496:
0497:            /**
0498:             * Executes <code>pushMenu(names, delim, comparator)</code> in a separate thread.
0499:             * @param path a menu path.
0500:             * @param delim a path delimiter.
0501:             * @param comparator a string comparision algorithm
0502:             */
0503:            public void pushMenuNoBlock(String path, String delim,
0504:                    StringComparator comparator) {
0505:                output.printLine("Pushing " + path + " menu in \n    "
0506:                        + toStringSource());
0507:                output.printGolden("Pushing " + path + " menu in \n    "
0508:                        + toStringSource());
0509:                pushMenuNoBlock(parseString(path, delim), comparator);
0510:            }
0511:
0512:            /**
0513:             * Executes <code>pushMenu(names, comparator)</code> in a separate thread.
0514:             * Uses PathParser assigned to this operator.
0515:             * @param path a menu path.
0516:             * @param comparator a string comparision algorithm
0517:             */
0518:            public void pushMenuNoBlock(String path, StringComparator comparator) {
0519:                output.printLine("Pushing " + path + " menu in \n    "
0520:                        + toStringSource());
0521:                output.printGolden("Pushing " + path + " menu in \n    "
0522:                        + toStringSource());
0523:                pushMenuNoBlock(parseString(path), comparator);
0524:            }
0525:
0526:            /**
0527:             * Executes <code>pushMenu(path, delim, ce, ccs)</code> in a separate thread.
0528:             * @param path String menupath representation ("File/New", for example).
0529:             * @param delim String menupath divider ("/").
0530:             * @param ce Compare text exactly.
0531:             * @param ccs Compare text case sensitively.
0532:             * @see #pushMenu
0533:             * @deprecated Use pushMenuNoBlock(String, String) or pushMenuNoBlock(String, String, StringComparator)
0534:             */
0535:            public void pushMenuNoBlock(String path, String delim, boolean ce,
0536:                    boolean ccs) {
0537:                pushMenuNoBlock(parseString(path, delim),
0538:                        new DefaultStringComparator(ce, ccs));
0539:            }
0540:
0541:            /**
0542:             * Pushes menu.
0543:             * Uses StringComparator assigned to this object,
0544:             * @param path String menupath representation ("File/New", for example).
0545:             * @param delim String menupath divider ("/").
0546:             * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0547:             * @return Last pushed JMenuItem.
0548:             * @throws TimeoutExpiredException
0549:             */
0550:            public JMenuItem pushMenu(String path, String delim) {
0551:                output.printLine("Pushing " + path + " menu in \n    "
0552:                        + toStringSource());
0553:                output.printGolden("Pushing " + path + " menu in \n    "
0554:                        + toStringSource());
0555:                return (pushMenu(parseString(path, delim)));
0556:            }
0557:
0558:            /**
0559:             * Pushes menu. Uses PathParser assigned to this operator.
0560:             * @param path String menupath representation ("File/New", for example).
0561:             * @return Last pushed JMenuItem.
0562:             * @throws TimeoutExpiredException
0563:             */
0564:            public JMenuItem pushMenu(String path) {
0565:                output.printLine("Pushing " + path + " menu in \n    "
0566:                        + toStringSource());
0567:                output.printGolden("Pushing " + path + " menu in \n    "
0568:                        + toStringSource());
0569:                return (pushMenu(parseString(path)));
0570:            }
0571:
0572:            /**
0573:             * Executes <code>pushMenu(path, delim)</code> in a separate thread.
0574:             * @param path String menupath representation ("File/New", for example).
0575:             * @param delim String menupath divider ("/").
0576:             */
0577:            public void pushMenuNoBlock(String path, String delim) {
0578:                output.printLine("Pushing " + path + " menu in \n    "
0579:                        + toStringSource());
0580:                output.printGolden("Pushing " + path + " menu in \n    "
0581:                        + toStringSource());
0582:                pushMenuNoBlock(parseString(path, delim));
0583:            }
0584:
0585:            /**
0586:             * Executes <code>pushMenu(path)</code> in a separate thread.
0587:             * @param path String menupath representation ("File/New", for example).
0588:             */
0589:            public void pushMenuNoBlock(String path) {
0590:                output.printLine("Pushing " + path + " menu in \n    "
0591:                        + toStringSource());
0592:                output.printGolden("Pushing " + path + " menu in \n    "
0593:                        + toStringSource());
0594:                pushMenuNoBlock(parseString(path));
0595:            }
0596:
0597:            public JMenuItemOperator[] showMenuItems(ComponentChooser[] choosers) {
0598:                return (JMenuItemOperator.getMenuItems(
0599:                        (JMenu) pushMenu(choosers), this ));
0600:            }
0601:
0602:            /**
0603:             * Shows submenu of menu specified by a <code>path</code> parameter.
0604:             * @param path an array of menu texts.
0605:             * @param comparator a string comparision algorithm
0606:             * @return an array of operators created tor items from the submenu.
0607:             * @throws TimeoutExpiredException
0608:             */
0609:            public JMenuItemOperator[] showMenuItems(String[] path,
0610:                    StringComparator comparator) {
0611:                return (showMenuItems(JMenuItemOperator.createChoosers(path,
0612:                        comparator)));
0613:            }
0614:
0615:            /**
0616:             * Shows submenu of menu specified by a <code>path</code> parameter.
0617:             * Uses StringComparator assigned to the operator.
0618:             * @param path an array of menu texts.
0619:             * @return an array of operators created tor items from the submenu.
0620:             * @throws TimeoutExpiredException
0621:             */
0622:            public JMenuItemOperator[] showMenuItems(String[] path) {
0623:                return (showMenuItems(path, getComparator()));
0624:            }
0625:
0626:            /**
0627:             * Shows submenu of menu specified by a <code>path</code> parameter.
0628:             * @param path a string identifying the menu path.
0629:             * @param delim a path delimiter.
0630:             * @param comparator a string comparision algorithm
0631:             * @return an array of operators created tor items from the submenu.
0632:             * @throws TimeoutExpiredException
0633:             */
0634:            public JMenuItemOperator[] showMenuItems(String path, String delim,
0635:                    StringComparator comparator) {
0636:                return (showMenuItems(parseString(path, delim), comparator));
0637:            }
0638:
0639:            /**
0640:             * Shows submenu of menu specified by a <code>path</code> parameter.
0641:             * Uses StringComparator assigned to the operator.
0642:             * @param path a string identifying the menu path.
0643:             * @param delim a path delimiter.
0644:             * @return an array of operators created tor items from the submenu.
0645:             * @throws TimeoutExpiredException
0646:             */
0647:            public JMenuItemOperator[] showMenuItems(String path, String delim) {
0648:                return (showMenuItems(path, delim, getComparator()));
0649:            }
0650:
0651:            /**
0652:             * Shows submenu of menu specified by a <code>path</code> parameter.
0653:             * Uses PathParser assigned to this operator.
0654:             * @param path a string identifying the menu path.
0655:             * @param comparator a string comparision algorithm
0656:             * @return an array of operators created tor items from the submenu.
0657:             * @throws TimeoutExpiredException
0658:             */
0659:            public JMenuItemOperator[] showMenuItems(String path,
0660:                    StringComparator comparator) {
0661:                return (showMenuItems(parseString(path), comparator));
0662:            }
0663:
0664:            /**
0665:             * Shows submenu of menu specified by a <code>path</code> parameter.
0666:             * Uses PathParser assigned to this operator.
0667:             * Uses StringComparator assigned to the operator.
0668:             * @param path a string identifying the menu path.
0669:             * @return an array of operators created tor items from the submenu.
0670:             * @throws TimeoutExpiredException
0671:             */
0672:            public JMenuItemOperator[] showMenuItems(String path) {
0673:                return (showMenuItems(path, getComparator()));
0674:            }
0675:
0676:            public JMenuItemOperator showMenuItem(ComponentChooser[] choosers) {
0677:                ComponentChooser[] parentPath = getParentPath(choosers);
0678:                JMenu menu;
0679:                if (parentPath.length > 0) {
0680:                    menu = (JMenu) pushMenu(parentPath);
0681:                } else {
0682:                    push();
0683:                    menu = (JMenu) getSource();
0684:                }
0685:                JPopupMenuOperator popup = new JPopupMenuOperator(menu
0686:                        .getPopupMenu());
0687:                popup.copyEnvironment(this );
0688:                JMenuItemOperator result = new JMenuItemOperator(popup,
0689:                        choosers[choosers.length - 1]);
0690:                result.copyEnvironment(this );
0691:                return (result);
0692:            }
0693:
0694:            /**
0695:             * Expends all menus to show menu item specified by a <code>path</code> parameter.
0696:             * @param path an array of menu texts.
0697:             * @param comparator a string comparision algorithm
0698:             * @return an operator for the last menu item in path.
0699:             * @throws TimeoutExpiredException
0700:             */
0701:            public JMenuItemOperator showMenuItem(String[] path,
0702:                    StringComparator comparator) {
0703:                String[] parentPath = getParentPath(path);
0704:                JMenu menu;
0705:                if (parentPath.length > 0) {
0706:                    menu = (JMenu) pushMenu(parentPath, comparator);
0707:                } else {
0708:                    push();
0709:                    menu = (JMenu) getSource();
0710:                }
0711:                JPopupMenuOperator popup = new JPopupMenuOperator(menu
0712:                        .getPopupMenu());
0713:                popup.copyEnvironment(this );
0714:                JMenuItemOperator result = new JMenuItemOperator(popup,
0715:                        path[path.length - 1]);
0716:                result.copyEnvironment(this );
0717:                return (result);
0718:            }
0719:
0720:            /**
0721:             * Expands all menus to show menu item specified by a <code>path</code> parameter.
0722:             * @param path an array of menu texts.
0723:             * @return an operator for the last menu item in path.
0724:             * @throws TimeoutExpiredException
0725:             */
0726:            public JMenuItemOperator showMenuItem(String[] path) {
0727:                return (showMenuItem(path, getComparator()));
0728:            }
0729:
0730:            /**
0731:             * Expands all menus to show menu item specified by a <code>path</code> parameter.
0732:             * @param path a string identifying the menu path.
0733:             * @param delim a path delimiter.
0734:             * @param comparator a string comparision algorithm
0735:             * @return an operator for the last menu item in path.
0736:             * @throws TimeoutExpiredException
0737:             */
0738:            public JMenuItemOperator showMenuItem(String path, String delim,
0739:                    StringComparator comparator) {
0740:                return (showMenuItem(parseString(path, delim), comparator));
0741:            }
0742:
0743:            /**
0744:             * Expands all menus to show menu item specified by a <code>path</code> parameter.
0745:             * Uses StringComparator assigned to the operator.
0746:             * @param path a string identifying the menu path.
0747:             * @param delim a path delimiter.
0748:             * @return an operator for the last menu item in path.
0749:             * @throws TimeoutExpiredException
0750:             */
0751:            public JMenuItemOperator showMenuItem(String path, String delim) {
0752:                return (showMenuItem(path, delim, getComparator()));
0753:            }
0754:
0755:            /**
0756:             * Expands all menus to show menu item specified by a <code>path</code> parameter.
0757:             * Uses PathParser assigned to this operator.
0758:             * @param path a string identifying the menu path.
0759:             * @param comparator a string comparision algorithm
0760:             * @return an operator for the last menu item in path.
0761:             * @throws TimeoutExpiredException
0762:             */
0763:            public JMenuItemOperator showMenuItem(String path,
0764:                    StringComparator comparator) {
0765:                return (showMenuItem(parseString(path), comparator));
0766:            }
0767:
0768:            /**
0769:             * Expands all menus to show menu item specified by a <code>path</code> parameter.
0770:             * Uses PathParser assigned to this operator.
0771:             * Uses StringComparator assigned to the operator.
0772:             * @param path a string identifying the menu path.
0773:             * @return an array of operators created tor items from the submenu.
0774:             * @throws TimeoutExpiredException
0775:             */
0776:            public JMenuItemOperator showMenuItem(String path) {
0777:                return (showMenuItem(path, getComparator()));
0778:            }
0779:
0780:            public Hashtable getDump() {
0781:                Hashtable result = super .getDump();
0782:                String[] items = new String[((JMenu) getSource())
0783:                        .getItemCount()];
0784:                for (int i = 0; i < ((JMenu) getSource()).getItemCount(); i++) {
0785:                    if (((JMenu) getSource()).getItem(i) != null
0786:                            && ((JMenu) getSource()).getItem(i).getText() != null) {
0787:                        items[i] = ((JMenu) getSource()).getItem(i).getText();
0788:                    } else {
0789:                        items[i] = "null";
0790:                    }
0791:                }
0792:                addToDump(result, SUBMENU_PREFIX_DPROP, items);
0793:                return (result);
0794:            }
0795:
0796:            ////////////////////////////////////////////////////////
0797:            //Mapping                                             //
0798:
0799:            /**Maps <code>JMenu.add(String)</code> through queue*/
0800:            public JMenuItem add(final String string) {
0801:                return ((JMenuItem) runMapping(new MapAction("add") {
0802:                    public Object map() {
0803:                        return (((JMenu) getSource()).add(string));
0804:                    }
0805:                }));
0806:            }
0807:
0808:            /**Maps <code>JMenu.add(Action)</code> through queue*/
0809:            public JMenuItem add(final javax.swing.Action action) {
0810:                return ((JMenuItem) runMapping(new MapAction("add") {
0811:                    public Object map() {
0812:                        return (((JMenu) getSource()).add(action));
0813:                    }
0814:                }));
0815:            }
0816:
0817:            /**Maps <code>JMenu.add(JMenuItem)</code> through queue*/
0818:            public JMenuItem add(final JMenuItem jMenuItem) {
0819:                return ((JMenuItem) runMapping(new MapAction("add") {
0820:                    public Object map() {
0821:                        return (((JMenu) getSource()).add(jMenuItem));
0822:                    }
0823:                }));
0824:            }
0825:
0826:            /**Maps <code>JMenu.addMenuListener(MenuListener)</code> through queue*/
0827:            public void addMenuListener(final MenuListener menuListener) {
0828:                runMapping(new MapVoidAction("addMenuListener") {
0829:                    public void map() {
0830:                        ((JMenu) getSource()).addMenuListener(menuListener);
0831:                    }
0832:                });
0833:            }
0834:
0835:            /**Maps <code>JMenu.addSeparator()</code> through queue*/
0836:            public void addSeparator() {
0837:                runMapping(new MapVoidAction("addSeparator") {
0838:                    public void map() {
0839:                        ((JMenu) getSource()).addSeparator();
0840:                    }
0841:                });
0842:            }
0843:
0844:            /**Maps <code>JMenu.getDelay()</code> through queue*/
0845:            public int getDelay() {
0846:                return (runMapping(new MapIntegerAction("getDelay") {
0847:                    public int map() {
0848:                        return (((JMenu) getSource()).getDelay());
0849:                    }
0850:                }));
0851:            }
0852:
0853:            /**Maps <code>JMenu.getItem(int)</code> through queue*/
0854:            public JMenuItem getItem(final int i) {
0855:                return ((JMenuItem) runMapping(new MapAction("getItem") {
0856:                    public Object map() {
0857:                        return (((JMenu) getSource()).getItem(i));
0858:                    }
0859:                }));
0860:            }
0861:
0862:            /**Maps <code>JMenu.getItemCount()</code> through queue*/
0863:            public int getItemCount() {
0864:                return (runMapping(new MapIntegerAction("getItemCount") {
0865:                    public int map() {
0866:                        return (((JMenu) getSource()).getItemCount());
0867:                    }
0868:                }));
0869:            }
0870:
0871:            /**Maps <code>JMenu.getMenuComponent(int)</code> through queue*/
0872:            public Component getMenuComponent(final int i) {
0873:                return ((Component) runMapping(new MapAction("getMenuComponent") {
0874:                    public Object map() {
0875:                        return (((JMenu) getSource()).getMenuComponent(i));
0876:                    }
0877:                }));
0878:            }
0879:
0880:            /**Maps <code>JMenu.getMenuComponentCount()</code> through queue*/
0881:            public int getMenuComponentCount() {
0882:                return (runMapping(new MapIntegerAction("getMenuComponentCount") {
0883:                    public int map() {
0884:                        return (((JMenu) getSource()).getMenuComponentCount());
0885:                    }
0886:                }));
0887:            }
0888:
0889:            /**Maps <code>JMenu.getMenuComponents()</code> through queue*/
0890:            public Component[] getMenuComponents() {
0891:                return ((Component[]) runMapping(new MapAction(
0892:                        "getMenuComponents") {
0893:                    public Object map() {
0894:                        return (((JMenu) getSource()).getMenuComponents());
0895:                    }
0896:                }));
0897:            }
0898:
0899:            /**Maps <code>JMenu.getPopupMenu()</code> through queue*/
0900:            public JPopupMenu getPopupMenu() {
0901:                return ((JPopupMenu) runMapping(new MapAction("getPopupMenu") {
0902:                    public Object map() {
0903:                        return (((JMenu) getSource()).getPopupMenu());
0904:                    }
0905:                }));
0906:            }
0907:
0908:            /**Maps <code>JMenu.insert(String, int)</code> through queue*/
0909:            public void insert(final String string, final int i) {
0910:                runMapping(new MapVoidAction("insert") {
0911:                    public void map() {
0912:                        ((JMenu) getSource()).insert(string, i);
0913:                    }
0914:                });
0915:            }
0916:
0917:            /**Maps <code>JMenu.insert(Action, int)</code> through queue*/
0918:            public JMenuItem insert(final javax.swing.Action action, final int i) {
0919:                return ((JMenuItem) runMapping(new MapAction("insert") {
0920:                    public Object map() {
0921:                        return (((JMenu) getSource()).insert(action, i));
0922:                    }
0923:                }));
0924:            }
0925:
0926:            /**Maps <code>JMenu.insert(JMenuItem, int)</code> through queue*/
0927:            public JMenuItem insert(final JMenuItem jMenuItem, final int i) {
0928:                return ((JMenuItem) runMapping(new MapAction("insert") {
0929:                    public Object map() {
0930:                        return (((JMenu) getSource()).insert(jMenuItem, i));
0931:                    }
0932:                }));
0933:            }
0934:
0935:            /**Maps <code>JMenu.insertSeparator(int)</code> through queue*/
0936:            public void insertSeparator(final int i) {
0937:                runMapping(new MapVoidAction("insertSeparator") {
0938:                    public void map() {
0939:                        ((JMenu) getSource()).insertSeparator(i);
0940:                    }
0941:                });
0942:            }
0943:
0944:            /**Maps <code>JMenu.isMenuComponent(Component)</code> through queue*/
0945:            public boolean isMenuComponent(final Component component) {
0946:                return (runMapping(new MapBooleanAction("isMenuComponent") {
0947:                    public boolean map() {
0948:                        return (((JMenu) getSource())
0949:                                .isMenuComponent(component));
0950:                    }
0951:                }));
0952:            }
0953:
0954:            /**Maps <code>JMenu.isPopupMenuVisible()</code> through queue*/
0955:            public boolean isPopupMenuVisible() {
0956:                return (runMapping(new MapBooleanAction("isPopupMenuVisible") {
0957:                    public boolean map() {
0958:                        return (((JMenu) getSource()).isPopupMenuVisible());
0959:                    }
0960:                }));
0961:            }
0962:
0963:            /**Maps <code>JMenu.isTearOff()</code> through queue*/
0964:            public boolean isTearOff() {
0965:                return (runMapping(new MapBooleanAction("isTearOff") {
0966:                    public boolean map() {
0967:                        return (((JMenu) getSource()).isTearOff());
0968:                    }
0969:                }));
0970:            }
0971:
0972:            /**Maps <code>JMenu.isTopLevelMenu()</code> through queue*/
0973:            public boolean isTopLevelMenu() {
0974:                return (runMapping(new MapBooleanAction("isTopLevelMenu") {
0975:                    public boolean map() {
0976:                        return (((JMenu) getSource()).isTopLevelMenu());
0977:                    }
0978:                }));
0979:            }
0980:
0981:            /**Maps <code>JMenu.remove(JMenuItem)</code> through queue*/
0982:            public void remove(final JMenuItem jMenuItem) {
0983:                runMapping(new MapVoidAction("remove") {
0984:                    public void map() {
0985:                        ((JMenu) getSource()).remove(jMenuItem);
0986:                    }
0987:                });
0988:            }
0989:
0990:            /**Maps <code>JMenu.removeMenuListener(MenuListener)</code> through queue*/
0991:            public void removeMenuListener(final MenuListener menuListener) {
0992:                runMapping(new MapVoidAction("removeMenuListener") {
0993:                    public void map() {
0994:                        ((JMenu) getSource()).removeMenuListener(menuListener);
0995:                    }
0996:                });
0997:            }
0998:
0999:            /**Maps <code>JMenu.setDelay(int)</code> through queue*/
1000:            public void setDelay(final int i) {
1001:                runMapping(new MapVoidAction("setDelay") {
1002:                    public void map() {
1003:                        ((JMenu) getSource()).setDelay(i);
1004:                    }
1005:                });
1006:            }
1007:
1008:            /**Maps <code>JMenu.setMenuLocation(int, int)</code> through queue*/
1009:            public void setMenuLocation(final int i, final int i1) {
1010:                runMapping(new MapVoidAction("setMenuLocation") {
1011:                    public void map() {
1012:                        ((JMenu) getSource()).setMenuLocation(i, i1);
1013:                    }
1014:                });
1015:            }
1016:
1017:            /**Maps <code>JMenu.setPopupMenuVisible(boolean)</code> through queue*/
1018:            public void setPopupMenuVisible(final boolean b) {
1019:                runMapping(new MapVoidAction("setPopupMenuVisible") {
1020:                    public void map() {
1021:                        ((JMenu) getSource()).setPopupMenuVisible(b);
1022:                    }
1023:                });
1024:            }
1025:
1026:            //End of mapping                                      //
1027:            ////////////////////////////////////////////////////////
1028:
1029:            static String createDescription(ComponentChooser[] choosers) {
1030:                String description = "(";
1031:                for (int i = 0; i < choosers.length; i++) {
1032:                    if (i > 0)
1033:                        description = description + ", ";
1034:                    description = description + choosers[i].getDescription();
1035:                }
1036:                description = description + ")";
1037:                return ("Menu pushing: " + description);
1038:            }
1039:
1040:            static DescriptablePathChooser converChoosers(
1041:                    final ComponentChooser[] choosers) {
1042:                return (new DescriptablePathChooser() {
1043:                    public boolean checkPathComponent(int depth,
1044:                            Object component) {
1045:                        return (choosers[depth]
1046:                                .checkComponent((Component) component));
1047:                    }
1048:
1049:                    public int getDepth() {
1050:                        return (choosers.length);
1051:                    }
1052:
1053:                    public String getDescription() {
1054:                        return (createDescription(choosers));
1055:                    }
1056:                });
1057:            }
1058:
1059:            /**
1060:             * Allows to find component by text.
1061:             */
1062:            public static class JMenuByLabelFinder implements  ComponentChooser {
1063:                String label;
1064:                StringComparator comparator;
1065:
1066:                /**
1067:                 * Constructs JMenuByLabelFinder.
1068:                 * @param lb a text pattern
1069:                 * @param comparator specifies string comparision algorithm.
1070:                 */
1071:                public JMenuByLabelFinder(String lb, StringComparator comparator) {
1072:                    label = lb;
1073:                    this .comparator = comparator;
1074:                }
1075:
1076:                /**
1077:                 * Constructs JMenuByLabelFinder.
1078:                 * @param lb a text pattern
1079:                 */
1080:                public JMenuByLabelFinder(String lb) {
1081:                    this (lb, Operator.getDefaultStringComparator());
1082:                }
1083:
1084:                public boolean checkComponent(Component comp) {
1085:                    if (comp instanceof  JMenu) {
1086:                        if (((JMenu) comp).getText() != null) {
1087:                            return (comparator.equals(((JMenu) comp).getText(),
1088:                                    label));
1089:                        }
1090:                    }
1091:                    return (false);
1092:                }
1093:
1094:                public String getDescription() {
1095:                    return ("JMenu with text \"" + label + "\"");
1096:                }
1097:            }
1098:
1099:            /**
1100:             * Checks component type.
1101:             */
1102:            public static class JMenuFinder extends Finder {
1103:                /**
1104:                 * Constructs JMenuFinder.
1105:                 * @param sf other searching criteria.
1106:                 */
1107:                public JMenuFinder(ComponentChooser sf) {
1108:                    super (JMenu.class, sf);
1109:                }
1110:
1111:                /**
1112:                 * Constructs JMenuFinder.
1113:                 */
1114:                public JMenuFinder() {
1115:                    super (JMenu.class);
1116:                }
1117:            }
1118:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.