Source Code Cross Referenced for JMenuBarOperator.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) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s): Alexandre Iline.
025:         *
026:         * The Original Software is the Jemmy library.
027:         * The Initial Developer of the Original Software is Alexandre Iline.
028:         * All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         *
041:         *
042:         *
043:         * $Id: JMenuBarOperator.java,v 1.16 2007/10/05 11:35:27 jskrivanek Exp $ $Revision: 1.16 $ $Date: 2007/10/05 11:35:27 $
044:         *
045:         */
046:
047:        package org.netbeans.jemmy.operators;
048:
049:        import org.netbeans.jemmy.Action;
050:        import org.netbeans.jemmy.ComponentSearcher;
051:        import org.netbeans.jemmy.ComponentChooser;
052:        import org.netbeans.jemmy.Outputable;
053:        import org.netbeans.jemmy.TestOut;
054:        import org.netbeans.jemmy.Timeoutable;
055:        import org.netbeans.jemmy.TimeoutExpiredException;
056:        import org.netbeans.jemmy.Timeouts;
057:
058:        import org.netbeans.jemmy.drivers.MenuDriver;
059:        import org.netbeans.jemmy.drivers.DriverManager;
060:
061:        import java.awt.Component;
062:        import java.awt.Container;
063:        import java.awt.Insets;
064:
065:        import java.awt.event.KeyEvent;
066:        import java.awt.event.MouseEvent;
067:
068:        import java.util.Hashtable;
069:
070:        import javax.swing.JDialog;
071:        import javax.swing.JFrame;
072:        import javax.swing.JMenu;
073:        import javax.swing.JMenuBar;
074:        import javax.swing.JMenuItem;
075:        import javax.swing.MenuElement;
076:        import javax.swing.MenuSelectionManager;
077:        import javax.swing.SingleSelectionModel;
078:
079:        import javax.swing.plaf.MenuBarUI;
080:
081:        /**
082:         * <BR><BR>Timeouts used: <BR>
083:         * JMenuOperator.WaitBeforePopupTimeout - time to sleep before popup expanding <BR>
084:         * JMenuOperator.WaitPopupTimeout - time to wait popup displayed <BR>
085:         * ComponentOperator.WaitComponentTimeout - time to wait button displayed <BR>.
086:         *
087:         * @see org.netbeans.jemmy.Timeouts
088:         * @author Alexandre Iline (alexandre.iline@sun.com)
089:         *	
090:         */
091:
092:        public class JMenuBarOperator extends JComponentOperator implements 
093:                Outputable, Timeoutable {
094:
095:            /**
096:             * Identifier for a "submenu" properties.
097:             * @see #getDump
098:             */
099:            public static final String SUBMENU_PREFIX_DPROP = "Submenu";
100:
101:            private TestOut output;
102:            private Timeouts timeouts;
103:            private MenuDriver driver;
104:
105:            /**
106:             * Constructor.
107:             * @param b a component
108:             */
109:            public JMenuBarOperator(JMenuBar b) {
110:                super (b);
111:                driver = DriverManager.getMenuDriver(getClass());
112:            }
113:
114:            /**
115:             * Constructs a JMenuBarOperator object.
116:             * @param cont a container
117:             * @param chooser a component chooser specifying searching criteria.
118:             * @param index an index between appropriate ones.
119:             */
120:            public JMenuBarOperator(ContainerOperator cont,
121:                    ComponentChooser chooser, int index) {
122:                this ((JMenuBar) cont.waitSubComponent(new JMenuBarFinder(
123:                        chooser), index));
124:                copyEnvironment(cont);
125:            }
126:
127:            /**
128:             * Constructs a JMenuBarOperator object.
129:             * @param cont a container
130:             * @param chooser a component chooser specifying searching criteria.
131:             */
132:            public JMenuBarOperator(ContainerOperator cont,
133:                    ComponentChooser chooser) {
134:                this (cont, chooser, 0);
135:            }
136:
137:            /**
138:             * Constructor.
139:             * Waits component in container first.
140:             * Uses cont's timeout and output for waiting and to init operator.
141:             * @param cont Operator pointing a container to search component in.
142:             * @throws TimeoutExpiredException
143:             */
144:            public JMenuBarOperator(ContainerOperator cont) {
145:                this ((JMenuBar) waitComponent(cont, new JMenuBarFinder(), 0));
146:                copyEnvironment(cont);
147:            }
148:
149:            /**
150:             * Searches JMenuBar in frame.
151:             * @param frame a container
152:             * @return found JMenuBar
153:             */
154:            public static JMenuBar findJMenuBar(JFrame frame) {
155:                return (findJMenuBar((Container) frame));
156:            }
157:
158:            /**
159:             * Searches JMenuBar in dialog.
160:             * @param dialog a container
161:             * @return found JMenuBar
162:             */
163:            public static JMenuBar findJMenuBar(JDialog dialog) {
164:                return (findJMenuBar((Container) dialog));
165:            }
166:
167:            /**
168:             * Searches JMenuBar in container.
169:             * @param cont a container
170:             * @return found JMenuBar
171:             * @throws TimeoutExpiredException
172:             */
173:            public static JMenuBar waitJMenuBar(Container cont) {
174:                return ((JMenuBar) waitComponent(cont, new JMenuBarFinder()));
175:            }
176:
177:            /**
178:             * Waits JMenuBar in frame.
179:             * @param frame a container
180:             * @return found JMenuBar
181:             * @throws TimeoutExpiredException
182:             */
183:            public static JMenuBar waitJMenuBar(JFrame frame) {
184:                return (waitJMenuBar((Container) frame));
185:            }
186:
187:            /**
188:             * Waits JMenuBar in dialog.
189:             * @param dialog a container
190:             * @return found JMenuBar
191:             * @throws TimeoutExpiredException
192:             */
193:            public static JMenuBar waitJMenuBar(JDialog dialog) {
194:                return (waitJMenuBar((Container) dialog));
195:            }
196:
197:            /**
198:             * Waits JMenuBar in container.
199:             * @param cont a container
200:             * @return found JMenuBar
201:             */
202:            public static JMenuBar findJMenuBar(Container cont) {
203:                return ((JMenuBar) findComponent(cont, new JMenuBarFinder()));
204:            }
205:
206:            static {
207:                //necessary to init timeouts
208:                JMenuOperator.class.getName();
209:            }
210:
211:            public void setOutput(TestOut out) {
212:                super .setOutput(out);
213:                output = out;
214:            }
215:
216:            public TestOut getOutput() {
217:                return (output);
218:            }
219:
220:            public void setTimeouts(Timeouts times) {
221:                super .setTimeouts(times);
222:                timeouts = times;
223:            }
224:
225:            public Timeouts getTimeouts() {
226:                return (timeouts);
227:            }
228:
229:            public void copyEnvironment(Operator anotherOperator) {
230:                super .copyEnvironment(anotherOperator);
231:                driver = DriverManager.getMenuDriver(this );
232:            }
233:
234:            /**
235:             * Pushes menu.
236:             * @param choosers Array of choosers to find menuItems to push.
237:             * @return Last pushed JMenuItem.
238:             * @throws TimeoutExpiredException
239:             */
240:            public JMenuItem pushMenu(final ComponentChooser[] choosers) {
241:                makeComponentVisible();
242:                return ((JMenuItem) produceTimeRestricted(new Action() {
243:                    public Object launch(Object obj) {
244:                        //TDB 1.5 menu workaround
245:                        getQueueTool().waitEmpty();
246:                        Object result = driver.pushMenu(JMenuBarOperator.this ,
247:                                JMenuOperator.converChoosers(choosers));
248:                        getQueueTool().waitEmpty();
249:                        return (result);
250:                    }
251:
252:                    public String getDescription() {
253:                        return (JMenuOperator.createDescription(choosers));
254:                    }
255:                }, getTimeouts().getTimeout("JMenuOperator.PushMenuTimeout")));
256:            }
257:
258:            /**
259:             * Executes <code>pushMenu(choosers)</code> in a separate thread.
260:             * @param choosers Array of choosers to find menuItems to push.
261:             * @see #pushMenu(ComponentChooser[])
262:             */
263:            public void pushMenuNoBlock(final ComponentChooser[] choosers) {
264:                makeComponentVisible();
265:                produceNoBlocking(new NoBlockingAction("Menu pushing") {
266:                    public Object doAction(Object param) {
267:                        //TDB 1.5 menu workaround
268:                        getQueueTool().waitEmpty();
269:                        Object result = driver.pushMenu(JMenuBarOperator.this ,
270:                                JMenuOperator.converChoosers(choosers));
271:                        getQueueTool().waitEmpty();
272:                        return (result);
273:                    }
274:                });
275:            }
276:
277:            /**
278:             * Pushes menu.
279:             * @param names an array of menu texts.
280:             * @param comparator a string comparision algorithm
281:             * @return Last pushed JMenuItem.
282:             * @throws TimeoutExpiredException
283:             */
284:            public JMenuItem pushMenu(String[] names,
285:                    StringComparator comparator) {
286:                return (pushMenu(JMenuItemOperator.createChoosers(names,
287:                        comparator)));
288:            }
289:
290:            /**
291:             * Pushes menu.
292:             * @param names Menu items texts.
293:             * @param ce Compare text exactly.
294:             * @param ccs Compare text case sensitively.
295:             * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
296:             * @return Last pushed JMenuItem.
297:             * @throws TimeoutExpiredException
298:             * @deprecated Use pushMenu(String[]) or pushMenu(String[], StringComparator)
299:             */
300:            public JMenuItem pushMenu(String[] names, boolean ce, boolean ccs) {
301:                return (pushMenu(names, new DefaultStringComparator(ce, ccs)));
302:            }
303:
304:            /**
305:             * Executes <code>pushMenu(names, ce, ccs)</code> in a separate thread.
306:             * @param names an array of menu texts.
307:             * @param comparator a string comparision algorithm
308:             */
309:            public void pushMenuNoBlock(String[] names,
310:                    StringComparator comparator) {
311:                pushMenuNoBlock(JMenuItemOperator.createChoosers(names,
312:                        comparator));
313:            }
314:
315:            /**
316:             * Executes <code>pushMenu(names, ce, ccs)</code> in a separate thread.
317:             * @param names Menu items texts.
318:             * @param ce Compare text exactly.
319:             * @param ccs Compare text case sensitively.
320:             * @see #pushMenu(String[], boolean,boolean)
321:             * @deprecated Use pushMenuNoBlock(String[]) or pushMenuNoBlock(String[], StringComparator)
322:             */
323:            public void pushMenuNoBlock(String[] names, boolean ce, boolean ccs) {
324:                pushMenuNoBlock(names, new DefaultStringComparator(ce, ccs));
325:            }
326:
327:            /**
328:             * Pushes menu.
329:             * @param names Menu items texts.
330:             * @return Last pushed JMenuItem.
331:             * @throws TimeoutExpiredException
332:             */
333:            public JMenuItem pushMenu(String[] names) {
334:                return (pushMenu(names, getComparator()));
335:            }
336:
337:            /**
338:             * Executes <code>pushMenu(names)</code> in a separate thread.
339:             * @param names Menu items texts.
340:             * @see #pushMenu(String[])
341:             */
342:            public void pushMenuNoBlock(String[] names) {
343:                pushMenuNoBlock(names, getComparator());
344:            }
345:
346:            /**
347:             * Pushes menu.
348:             * @param path a menu path.
349:             * @param delim a path delimiter.
350:             * @param comparator a string comparision algorithm
351:             * @return Last pushed JMenuItem.
352:             * @throws TimeoutExpiredException
353:             */
354:            public JMenuItem pushMenu(String path, String delim,
355:                    StringComparator comparator) {
356:                return (pushMenu(parseString(path, delim), comparator));
357:            }
358:
359:            /**
360:             * Pushes menu. Uses PathParser assigned to this operator.
361:             * @param path a menu path.
362:             * @param comparator a string comparision algorithm
363:             * @return Last pushed JMenuItem.
364:             * @throws TimeoutExpiredException
365:             */
366:            public JMenuItem pushMenu(String path, StringComparator comparator) {
367:                return (pushMenu(parseString(path), comparator));
368:            }
369:
370:            /**
371:             * Pushes menu.
372:             * @param path String menupath representation ("File/New", for example).
373:             * @param delim String menupath divider ("/").
374:             * @param ce Compare text exactly.
375:             * @param ccs Compare text case sensitively.
376:             * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
377:             * @return Last pushed JMenuItem.
378:             * @throws TimeoutExpiredException
379:             * @deprecated Use pushMenu(String, String) or pushMenu(String, String, StringComparator)
380:             */
381:            public JMenuItem pushMenu(String path, String delim, boolean ce,
382:                    boolean ccs) {
383:                return (pushMenu(parseString(path, delim), ce, ccs));
384:            }
385:
386:            /**
387:             * Executes <code>pushMenu(names, delim, comparator)</code> in a separate thread.
388:             * @param path a menu path.
389:             * @param delim a path delimiter.
390:             * @param comparator a string comparision algorithm
391:             */
392:            public void pushMenuNoBlock(String path, String delim,
393:                    StringComparator comparator) {
394:                pushMenuNoBlock(parseString(path, delim), comparator);
395:            }
396:
397:            /**
398:             * Executes <code>pushMenu(names, comparator)</code> in a separate thread.
399:             * Uses PathParser assigned to this operator.
400:             * @param path a menu path.
401:             * @param comparator a string comparision algorithm
402:             */
403:            public void pushMenuNoBlock(String path, StringComparator comparator) {
404:                pushMenuNoBlock(parseString(path), comparator);
405:            }
406:
407:            /**
408:             * Executes <code>pushMenu(path, delim, ce, ccs)</code> in a separate thread.
409:             * @param path String menupath representation ("File/New", for example).
410:             * @param delim String menupath divider ("/").
411:             * @param ce Compare text exactly.
412:             * @param ccs Compare text case sensitively.
413:             * @see #pushMenu
414:             * @deprecated Use pushMenuNoBlock(String, String) or pushMenuNoBlock(String, String, StringComparator)
415:             */
416:            public void pushMenuNoBlock(String path, String delim, boolean ce,
417:                    boolean ccs) {
418:                pushMenuNoBlock(parseString(path, delim), ce, ccs);
419:            }
420:
421:            /**
422:             * Pushes menu.
423:             * @param path String menupath representation ("File/New", for example).
424:             * @param delim String menupath divider ("/").
425:             * @return Last pushed JMenuItem.
426:             * @throws TimeoutExpiredException
427:             */
428:            public JMenuItem pushMenu(String path, String delim) {
429:                return (pushMenu(parseString(path, delim)));
430:            }
431:
432:            /**
433:             * Pushes menu. Uses PathParser assigned to this operator.
434:             * @param path String menupath representation ("File/New", for example).
435:             * @return Last pushed JMenuItem.
436:             * @throws TimeoutExpiredException
437:             */
438:            public JMenuItem pushMenu(String path) {
439:                return (pushMenu(parseString(path)));
440:            }
441:
442:            /**
443:             * Executes <code>pushMenu(path, delim)</code> in a separate thread.
444:             * @param path String menupath representation ("File/New", for example).
445:             * @param delim String menupath divider ("/").
446:             */
447:            public void pushMenuNoBlock(String path, String delim) {
448:                pushMenuNoBlock(parseString(path, delim));
449:            }
450:
451:            /**
452:             * Executes <code>pushMenu(path)</code> in a separate thread.
453:             * @param path String menupath representation ("File/New", for example).
454:             */
455:            public void pushMenuNoBlock(String path) {
456:                pushMenuNoBlock(parseString(path));
457:            }
458:
459:            public JMenuItemOperator[] showMenuItems(ComponentChooser[] choosers) {
460:                if (choosers == null || choosers.length == 0) {
461:                    return (JMenuItemOperator.getMenuItems(
462:                            (MenuElement) getSource(), this ));
463:                } else {
464:                    return (JMenuItemOperator.getMenuItems(
465:                            (JMenu) pushMenu(choosers), this ));
466:                }
467:            }
468:
469:            /**
470:             * Shows submenu of menu specified by a <code>path</code> parameter.
471:             * @param path an array of menu texts.
472:             * @param comparator a string comparision algorithm
473:             * @return an array of operators created tor items from the submenu.
474:             * @throws TimeoutExpiredException
475:             */
476:            public JMenuItemOperator[] showMenuItems(String[] path,
477:                    StringComparator comparator) {
478:                if (path == null || path.length == 0) {
479:                    return (JMenuItemOperator.getMenuItems(
480:                            (MenuElement) getSource(), this ));
481:                } else {
482:                    return (JMenuItemOperator.getMenuItems((JMenu) pushMenu(
483:                            path, comparator), this ));
484:                }
485:            }
486:
487:            /**
488:             * Shows submenu of menu specified by a <code>path</code> parameter.
489:             * Uses StringComparator assigned to the operator.
490:             * @param path an array of menu texts.
491:             * @return an array of operators created tor items from the submenu.
492:             * @throws TimeoutExpiredException
493:             */
494:            public JMenuItemOperator[] showMenuItems(String[] path) {
495:                return (showMenuItems(path, getComparator()));
496:            }
497:
498:            /**
499:             * Shows submenu of menu specified by a <code>path</code> parameter.
500:             * @param path a string identifying the menu path.
501:             * @param delim a path delimiter.
502:             * @param comparator a string comparision algorithm
503:             * @return an array of operators created tor items from the submenu.
504:             * @throws TimeoutExpiredException
505:             */
506:            public JMenuItemOperator[] showMenuItems(String path, String delim,
507:                    StringComparator comparator) {
508:                return (showMenuItems(parseString(path, delim), comparator));
509:            }
510:
511:            /**
512:             * Shows submenu of menu specified by a <code>path</code> parameter.
513:             * Uses PathParser assigned to this operator.
514:             * @param path a string identifying the menu path.
515:             * @param comparator a string comparision algorithm
516:             * @return an array of operators created tor items from the submenu.
517:             * @throws TimeoutExpiredException
518:             */
519:            public JMenuItemOperator[] showMenuItems(String path,
520:                    StringComparator comparator) {
521:                return (showMenuItems(parseString(path), comparator));
522:            }
523:
524:            /**
525:             * Shows submenu of menu specified by a <code>path</code> parameter.
526:             * Uses StringComparator assigned to the operator.
527:             * @param path a string identifying the menu path.
528:             * @param delim a path delimiter.
529:             * @return an array of operators created tor items from the submenu.
530:             * @throws TimeoutExpiredException
531:             */
532:            public JMenuItemOperator[] showMenuItems(String path, String delim) {
533:                return (showMenuItems(path, delim, getComparator()));
534:            }
535:
536:            /**
537:             * Shows submenu of menu specified by a <code>path</code> parameter.
538:             * Uses PathParser assigned to this operator.
539:             * Uses StringComparator assigned to the operator.
540:             * @param path a string identifying the menu path.
541:             * @return an array of operators created tor items from the submenu.
542:             * @throws TimeoutExpiredException
543:             */
544:            public JMenuItemOperator[] showMenuItems(String path) {
545:                return (showMenuItems(path, getComparator()));
546:            }
547:
548:            public JMenuItemOperator showMenuItem(ComponentChooser[] choosers) {
549:                ComponentChooser[] parentPath = getParentPath(choosers);
550:                JMenu menu;
551:                ContainerOperator menuCont;
552:                if (parentPath.length > 0) {
553:                    menu = (JMenu) pushMenu(getParentPath(choosers));
554:                    menuCont = new ContainerOperator(menu.getPopupMenu());
555:                    menuCont.copyEnvironment(this );
556:                } else {
557:                    menuCont = this ;
558:                }
559:                JMenuItemOperator result = new JMenuItemOperator(menuCont,
560:                        choosers[choosers.length - 1]);
561:                result.copyEnvironment(this );
562:                return (result);
563:            }
564:
565:            /**
566:             * Expends all menus to show menu item specified by a <code>path</code> parameter.
567:             * @param path an array of menu texts.
568:             * @param comparator a string comparision algorithm
569:             * @return an operator for the last menu item in path.
570:             * @throws TimeoutExpiredException
571:             */
572:            public JMenuItemOperator showMenuItem(String[] path,
573:                    StringComparator comparator) {
574:                String[] parentPath = getParentPath(path);
575:                JMenu menu;
576:                ContainerOperator menuCont;
577:                if (parentPath.length > 0) {
578:                    menu = (JMenu) pushMenu(getParentPath(path), comparator);
579:                    menuCont = new ContainerOperator(menu.getPopupMenu());
580:                    menuCont.copyEnvironment(this );
581:                } else {
582:                    menuCont = this ;
583:                }
584:                JMenuItemOperator result;
585:                // isVisible() on items returns false on mac, so we need a special searcher. 
586:                if (System.getProperty("os.name").toLowerCase().indexOf("mac") > -1) { // NOI18N
587:                    ComponentSearcher searcher = new ComponentSearcher(
588:                            (Container) menuCont.getSource());
589:                    searcher.setOutput(output);
590:                    Component c = searcher
591:                            .findComponent(new JMenuItemOperator.JMenuItemByLabelFinder(
592:                                    path[path.length - 1], getComparator()));
593:                    result = new JMenuItemOperator((JMenuItem) c);
594:                } else {
595:                    result = new JMenuItemOperator(menuCont,
596:                            path[path.length - 1]);
597:                }
598:                result.copyEnvironment(this );
599:                return (result);
600:            }
601:
602:            /**
603:             * Expands all menus to show menu item specified by a <code>path</code> parameter.
604:             * @param path an array of menu texts.
605:             * @return an operator for the last menu item in path.
606:             * @throws TimeoutExpiredException
607:             */
608:            public JMenuItemOperator showMenuItem(String[] path) {
609:                return (showMenuItem(path, getComparator()));
610:            }
611:
612:            /**
613:             * Expands all menus to show menu item specified by a <code>path</code> parameter.
614:             * @param path a string identifying the menu path.
615:             * @param delim a path delimiter.
616:             * @param comparator a string comparision algorithm
617:             * @return an operator for the last menu item in path.
618:             * @throws TimeoutExpiredException
619:             */
620:            public JMenuItemOperator showMenuItem(String path, String delim,
621:                    StringComparator comparator) {
622:                return (showMenuItem(parseString(path, delim), comparator));
623:            }
624:
625:            /**
626:             * Expands all menus to show menu item specified by a <code>path</code> parameter.
627:             * Uses PathParser assigned to this operator.
628:             * @param path a string identifying the menu path.
629:             * @param comparator a string comparision algorithm
630:             * @return an operator for the last menu item in path.
631:             * @throws TimeoutExpiredException
632:             */
633:            public JMenuItemOperator showMenuItem(String path,
634:                    StringComparator comparator) {
635:                return (showMenuItem(parseString(path), comparator));
636:            }
637:
638:            /**
639:             * Expands all menus to show menu item specified by a <code>path</code> parameter.
640:             * Uses StringComparator assigned to the operator.
641:             * @param path a string identifying the menu path.
642:             * @param delim a path delimiter.
643:             * @return an operator for the last menu item in path.
644:             * @throws TimeoutExpiredException
645:             */
646:            public JMenuItemOperator showMenuItem(String path, String delim) {
647:                return (showMenuItem(path, delim, getComparator()));
648:            }
649:
650:            /**
651:             * Expands all menus to show menu item specified by a <code>path</code> parameter.
652:             * Uses PathParser assigned to this operator.
653:             * Uses StringComparator assigned to the operator.
654:             * @param path a string identifying the menu path.
655:             * @return an array of operators created tor items from the submenu.
656:             * @throws TimeoutExpiredException
657:             */
658:            public JMenuItemOperator showMenuItem(String path) {
659:                return (showMenuItem(path, getComparator()));
660:            }
661:
662:            /**
663:             * Closes all expanded submenus.
664:             */
665:            public void closeSubmenus() {
666:                JMenu menu = (JMenu) findSubComponent(new ComponentChooser() {
667:                    public boolean checkComponent(Component comp) {
668:                        return (comp instanceof  JMenu && ((JMenu) comp)
669:                                .isPopupMenuVisible());
670:                    }
671:
672:                    public String getDescription() {
673:                        return ("Expanded JMenu");
674:                    }
675:                });
676:                if (menu != null) {
677:                    JMenuOperator oper = new JMenuOperator(menu);
678:                    oper.copyEnvironment(this );
679:                    oper.push();
680:                }
681:            }
682:
683:            public Hashtable getDump() {
684:                Hashtable result = super .getDump();
685:                String[] items = new String[((JMenuBar) getSource())
686:                        .getMenuCount()];
687:                for (int i = 0; i < ((JMenuBar) getSource()).getMenuCount(); i++) {
688:                    if (((JMenuBar) getSource()).getMenu(i) != null) {
689:                        items[i] = ((JMenuBar) getSource()).getMenu(i)
690:                                .getText();
691:                    } else {
692:                        items[i] = "null";
693:                    }
694:                }
695:                addToDump(result, SUBMENU_PREFIX_DPROP, items);
696:                return (result);
697:            }
698:
699:            ////////////////////////////////////////////////////////
700:            //Mapping                                             //
701:
702:            /**Maps <code>JMenuBar.add(JMenu)</code> through queue*/
703:            public JMenu add(final JMenu jMenu) {
704:                return ((JMenu) runMapping(new MapAction("add") {
705:                    public Object map() {
706:                        return (((JMenuBar) getSource()).add(jMenu));
707:                    }
708:                }));
709:            }
710:
711:            /**Maps <code>JMenuBar.getComponentIndex(Component)</code> through queue*/
712:            public int getComponentIndex(final Component component) {
713:                return (runMapping(new MapIntegerAction("getComponentIndex") {
714:                    public int map() {
715:                        return (((JMenuBar) getSource())
716:                                .getComponentIndex(component));
717:                    }
718:                }));
719:            }
720:
721:            /**Maps <code>JMenuBar.getHelpMenu()</code> through queue*/
722:            public JMenu getHelpMenu() {
723:                return ((JMenu) runMapping(new MapAction("getHelpMenu") {
724:                    public Object map() {
725:                        return (((JMenuBar) getSource()).getHelpMenu());
726:                    }
727:                }));
728:            }
729:
730:            /**Maps <code>JMenuBar.getMargin()</code> through queue*/
731:            public Insets getMargin() {
732:                return ((Insets) runMapping(new MapAction("getMargin") {
733:                    public Object map() {
734:                        return (((JMenuBar) getSource()).getMargin());
735:                    }
736:                }));
737:            }
738:
739:            /**Maps <code>JMenuBar.getMenu(int)</code> through queue*/
740:            public JMenu getMenu(final int i) {
741:                return ((JMenu) runMapping(new MapAction("getMenu") {
742:                    public Object map() {
743:                        return (((JMenuBar) getSource()).getMenu(i));
744:                    }
745:                }));
746:            }
747:
748:            /**Maps <code>JMenuBar.getMenuCount()</code> through queue*/
749:            public int getMenuCount() {
750:                return (runMapping(new MapIntegerAction("getMenuCount") {
751:                    public int map() {
752:                        return (((JMenuBar) getSource()).getMenuCount());
753:                    }
754:                }));
755:            }
756:
757:            /**Maps <code>JMenuBar.getSelectionModel()</code> through queue*/
758:            public SingleSelectionModel getSelectionModel() {
759:                return ((SingleSelectionModel) runMapping(new MapAction(
760:                        "getSelectionModel") {
761:                    public Object map() {
762:                        return (((JMenuBar) getSource()).getSelectionModel());
763:                    }
764:                }));
765:            }
766:
767:            /**Maps <code>JMenuBar.getSubElements()</code> through queue*/
768:            public MenuElement[] getSubElements() {
769:                return ((MenuElement[]) runMapping(new MapAction(
770:                        "getSubElements") {
771:                    public Object map() {
772:                        return (((JMenuBar) getSource()).getSubElements());
773:                    }
774:                }));
775:            }
776:
777:            /**Maps <code>JMenuBar.getUI()</code> through queue*/
778:            public MenuBarUI getUI() {
779:                return ((MenuBarUI) runMapping(new MapAction("getUI") {
780:                    public Object map() {
781:                        return (((JMenuBar) getSource()).getUI());
782:                    }
783:                }));
784:            }
785:
786:            /**Maps <code>JMenuBar.isBorderPainted()</code> through queue*/
787:            public boolean isBorderPainted() {
788:                return (runMapping(new MapBooleanAction("isBorderPainted") {
789:                    public boolean map() {
790:                        return (((JMenuBar) getSource()).isBorderPainted());
791:                    }
792:                }));
793:            }
794:
795:            /**Maps <code>JMenuBar.isSelected()</code> through queue*/
796:            public boolean isSelected() {
797:                return (runMapping(new MapBooleanAction("isSelected") {
798:                    public boolean map() {
799:                        return (((JMenuBar) getSource()).isSelected());
800:                    }
801:                }));
802:            }
803:
804:            /**Maps <code>JMenuBar.menuSelectionChanged(boolean)</code> through queue*/
805:            public void menuSelectionChanged(final boolean b) {
806:                runMapping(new MapVoidAction("menuSelectionChanged") {
807:                    public void map() {
808:                        ((JMenuBar) getSource()).menuSelectionChanged(b);
809:                    }
810:                });
811:            }
812:
813:            /**Maps <code>JMenuBar.processKeyEvent(KeyEvent, MenuElement[], MenuSelectionManager)</code> through queue*/
814:            public void processKeyEvent(final KeyEvent keyEvent,
815:                    final MenuElement[] menuElement,
816:                    final MenuSelectionManager menuSelectionManager) {
817:                runMapping(new MapVoidAction("processKeyEvent") {
818:                    public void map() {
819:                        ((JMenuBar) getSource()).processKeyEvent(keyEvent,
820:                                menuElement, menuSelectionManager);
821:                    }
822:                });
823:            }
824:
825:            /**Maps <code>JMenuBar.processMouseEvent(MouseEvent, MenuElement[], MenuSelectionManager)</code> through queue*/
826:            public void processMouseEvent(final MouseEvent mouseEvent,
827:                    final MenuElement[] menuElement,
828:                    final MenuSelectionManager menuSelectionManager) {
829:                runMapping(new MapVoidAction("processMouseEvent") {
830:                    public void map() {
831:                        ((JMenuBar) getSource()).processMouseEvent(mouseEvent,
832:                                menuElement, menuSelectionManager);
833:                    }
834:                });
835:            }
836:
837:            /**Maps <code>JMenuBar.setBorderPainted(boolean)</code> through queue*/
838:            public void setBorderPainted(final boolean b) {
839:                runMapping(new MapVoidAction("setBorderPainted") {
840:                    public void map() {
841:                        ((JMenuBar) getSource()).setBorderPainted(b);
842:                    }
843:                });
844:            }
845:
846:            /**Maps <code>JMenuBar.setHelpMenu(JMenu)</code> through queue*/
847:            public void setHelpMenu(final JMenu jMenu) {
848:                runMapping(new MapVoidAction("setHelpMenu") {
849:                    public void map() {
850:                        ((JMenuBar) getSource()).setHelpMenu(jMenu);
851:                    }
852:                });
853:            }
854:
855:            /**Maps <code>JMenuBar.setMargin(Insets)</code> through queue*/
856:            public void setMargin(final Insets insets) {
857:                runMapping(new MapVoidAction("setMargin") {
858:                    public void map() {
859:                        ((JMenuBar) getSource()).setMargin(insets);
860:                    }
861:                });
862:            }
863:
864:            /**Maps <code>JMenuBar.setSelected(Component)</code> through queue*/
865:            public void setSelected(final Component component) {
866:                runMapping(new MapVoidAction("setSelected") {
867:                    public void map() {
868:                        ((JMenuBar) getSource()).setSelected(component);
869:                    }
870:                });
871:            }
872:
873:            /**Maps <code>JMenuBar.setSelectionModel(SingleSelectionModel)</code> through queue*/
874:            public void setSelectionModel(
875:                    final SingleSelectionModel singleSelectionModel) {
876:                runMapping(new MapVoidAction("setSelectionModel") {
877:                    public void map() {
878:                        ((JMenuBar) getSource())
879:                                .setSelectionModel(singleSelectionModel);
880:                    }
881:                });
882:            }
883:
884:            /**Maps <code>JMenuBar.setUI(MenuBarUI)</code> through queue*/
885:            public void setUI(final MenuBarUI menuBarUI) {
886:                runMapping(new MapVoidAction("setUI") {
887:                    public void map() {
888:                        ((JMenuBar) getSource()).setUI(menuBarUI);
889:                    }
890:                });
891:            }
892:
893:            //End of mapping                                      //
894:            ////////////////////////////////////////////////////////
895:
896:            /**
897:             * Checks component type.
898:             */
899:            public static class JMenuBarFinder extends Finder {
900:                /**
901:                 * Constructs JMenuBarFinder.
902:                 * @param sf other searching criteria.
903:                 */
904:                public JMenuBarFinder(ComponentChooser sf) {
905:                    super (JMenuBar.class, sf);
906:                }
907:
908:                /**
909:                 * Constructs JMenuBarFinder.
910:                 */
911:                public JMenuBarFinder() {
912:                    super (JMenuBar.class);
913:                }
914:            }
915:
916:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.