1 /*
2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation. Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 package org.netbeans.jemmy.operators;
26 
27 import java.awt.Component;
28 import java.awt.Container;
29 import java.awt.Insets;
30 import java.awt.event.KeyEvent;
31 import java.awt.event.MouseEvent;
32 import java.util.Hashtable;
33 
34 import javax.swing.JDialog;
35 import javax.swing.JFrame;
36 import javax.swing.JMenu;
37 import javax.swing.JMenuBar;
38 import javax.swing.JMenuItem;
39 import javax.swing.MenuElement;
40 import javax.swing.MenuSelectionManager;
41 import javax.swing.SingleSelectionModel;
42 import javax.swing.plaf.MenuBarUI;
43 
44 import org.netbeans.jemmy.Action;
45 import org.netbeans.jemmy.ComponentChooser;
46 import org.netbeans.jemmy.ComponentSearcher;
47 import org.netbeans.jemmy.Outputable;
48 import org.netbeans.jemmy.TestOut;
49 import org.netbeans.jemmy.TimeoutExpiredException;
50 import org.netbeans.jemmy.Timeoutable;
51 import org.netbeans.jemmy.Timeouts;
52 import org.netbeans.jemmy.drivers.DriverManager;
53 import org.netbeans.jemmy.drivers.MenuDriver;
54 import org.netbeans.jemmy.util.Platform;
55 
56 /**
57  * <BR><BR>Timeouts used: <BR>
58  * JMenuOperator.WaitBeforePopupTimeout - time to sleep before popup expanding
59  * <BR>
60  * JMenuOperator.WaitPopupTimeout - time to wait popup displayed <BR>
61  * ComponentOperator.WaitComponentTimeout - time to wait button displayed <BR>.
62  *
63  * @see org.netbeans.jemmy.Timeouts
64  * @author Alexandre Iline (alexandre.iline@oracle.com)
65  *
66  */
67 public class JMenuBarOperator extends JComponentOperator
68         implements Outputable, Timeoutable {
69 
70     /**
71      * Identifier for a "submenu" properties.
72      *
73      * @see #getDump
74      */
75     public static final String SUBMENU_PREFIX_DPROP = "Submenu";
76 
77     private TestOut output;
78     private Timeouts timeouts;
79     private MenuDriver driver;
80 
81     /**
82      * Constructor.
83      *
84      * @param b a component
85      */
JMenuBarOperator(JMenuBar b)86     public JMenuBarOperator(JMenuBar b) {
87         super(b);
88         driver = DriverManager.getMenuDriver(getClass());
89     }
90 
91     /**
92      * Constructs a JMenuBarOperator object.
93      *
94      * @param cont a container
95      * @param chooser a component chooser specifying searching criteria.
96      * @param index an index between appropriate ones.
97      */
JMenuBarOperator(ContainerOperator<?> cont, ComponentChooser chooser, int index)98     public JMenuBarOperator(ContainerOperator<?> cont, ComponentChooser chooser, int index) {
99         this((JMenuBar) cont.
100                 waitSubComponent(new JMenuBarFinder(chooser),
101                         index));
102         copyEnvironment(cont);
103     }
104 
105     /**
106      * Constructs a JMenuBarOperator object.
107      *
108      * @param cont a container
109      * @param chooser a component chooser specifying searching criteria.
110      */
JMenuBarOperator(ContainerOperator<?> cont, ComponentChooser chooser)111     public JMenuBarOperator(ContainerOperator<?> cont, ComponentChooser chooser) {
112         this(cont, chooser, 0);
113     }
114 
115     /**
116      * Constructor. Waits component in container first. Uses cont's timeout and
117      * output for waiting and to init operator.
118      *
119      * @param cont Operator pointing a container to search component in.
120      * @throws TimeoutExpiredException
121      */
JMenuBarOperator(ContainerOperator<?> cont)122     public JMenuBarOperator(ContainerOperator<?> cont) {
123         this((JMenuBar) waitComponent(cont,
124                 new JMenuBarFinder(),
125                 0));
126         copyEnvironment(cont);
127     }
128 
129     /**
130      * Searches JMenuBar in frame.
131      *
132      * @param frame a container
133      * @return found JMenuBar
134      */
findJMenuBar(JFrame frame)135     public static JMenuBar findJMenuBar(JFrame frame) {
136         return findJMenuBar((Container) frame);
137     }
138 
139     /**
140      * Searches JMenuBar in dialog.
141      *
142      * @param dialog a container
143      * @return found JMenuBar
144      */
findJMenuBar(JDialog dialog)145     public static JMenuBar findJMenuBar(JDialog dialog) {
146         return findJMenuBar((Container) dialog);
147     }
148 
149     /**
150      * Searches JMenuBar in container.
151      *
152      * @param cont a container
153      * @return found JMenuBar
154      * @throws TimeoutExpiredException
155      */
waitJMenuBar(Container cont)156     public static JMenuBar waitJMenuBar(Container cont) {
157         return (JMenuBar) waitComponent(cont, new JMenuBarFinder());
158     }
159 
160     /**
161      * Waits JMenuBar in frame.
162      *
163      * @param frame a container
164      * @return found JMenuBar
165      * @throws TimeoutExpiredException
166      */
waitJMenuBar(JFrame frame)167     public static JMenuBar waitJMenuBar(JFrame frame) {
168         return waitJMenuBar((Container) frame);
169     }
170 
171     /**
172      * Waits JMenuBar in dialog.
173      *
174      * @param dialog a container
175      * @return found JMenuBar
176      * @throws TimeoutExpiredException
177      */
waitJMenuBar(JDialog dialog)178     public static JMenuBar waitJMenuBar(JDialog dialog) {
179         return waitJMenuBar((Container) dialog);
180     }
181 
182     /**
183      * Waits JMenuBar in container.
184      *
185      * @param cont a container
186      * @return found JMenuBar
187      */
findJMenuBar(Container cont)188     public static JMenuBar findJMenuBar(Container cont) {
189         return (JMenuBar) findComponent(cont, new JMenuBarFinder());
190     }
191 
192     static {
193         //necessary to init timeouts
JMenuOperator.performInit()194         JMenuOperator.performInit();
195     }
196 
197     @Override
setOutput(TestOut out)198     public void setOutput(TestOut out) {
199         super.setOutput(out);
200         output = out;
201     }
202 
203     @Override
getOutput()204     public TestOut getOutput() {
205         return output;
206     }
207 
208     @Override
setTimeouts(Timeouts times)209     public void setTimeouts(Timeouts times) {
210         super.setTimeouts(times);
211         timeouts = times;
212     }
213 
214     @Override
getTimeouts()215     public Timeouts getTimeouts() {
216         return timeouts;
217     }
218 
219     @Override
copyEnvironment(Operator anotherOperator)220     public void copyEnvironment(Operator anotherOperator) {
221         super.copyEnvironment(anotherOperator);
222         driver = DriverManager.getMenuDriver(this);
223     }
224 
225     /**
226      * Pushes menu.
227      *
228      * @param choosers Array of choosers to find menuItems to push.
229      * @return Last pushed JMenuItem.
230      * @throws TimeoutExpiredException
231      */
pushMenu(final ComponentChooser[] choosers)232     public JMenuItem pushMenu(final ComponentChooser[] choosers) {
233         makeComponentVisible();
234         return ((JMenuItem) produceTimeRestricted(new Action<Object, Void>() {
235             @Override
236             public Object launch(Void obj) {
237                 //TDB 1.5 menu workaround
238                 getQueueTool().waitEmpty();
239                 Object result = driver.pushMenu(JMenuBarOperator.this,
240                         JMenuOperator.converChoosers(choosers));
241                 getQueueTool().waitEmpty();
242                 return result;
243             }
244 
245             @Override
246             public String getDescription() {
247                 return JMenuOperator.createDescription(choosers);
248             }
249 
250             @Override
251             public String toString() {
252                 return "JMenuBarOperator.pushMenu.Action{description = " + getDescription() + '}';
253             }
254         }, "JMenuOperator.PushMenuTimeout"));
255     }
256 
257     /**
258      * Executes {@code pushMenu(choosers)} in a separate thread.
259      *
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<Object, Void>("Menu pushing") {
266             @Override
267             public Object doAction(Void param) {
268                 //TDB 1.5 menu workaround
269                 getQueueTool().waitEmpty();
270                 Object result = driver.pushMenu(JMenuBarOperator.this,
271                         JMenuOperator.converChoosers(choosers));
272                 getQueueTool().waitEmpty();
273                 return result;
274             }
275         });
276     }
277 
278     /**
279      * Pushes menu.
280      *
281      * @param names an array of menu texts.
282      * @param comparator a string comparision algorithm
283      * @return Last pushed JMenuItem.
284      * @throws TimeoutExpiredException
285      */
286     public JMenuItem pushMenu(String[] names, StringComparator comparator) {
287         return pushMenu(JMenuItemOperator.createChoosers(names, comparator));
288     }
289 
290     /**
291      * Pushes menu.
292      *
293      * @param names Menu items texts.
294      * @param ce Compare text exactly.
295      * @param ccs Compare text case sensitively.
296      * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
297      * @return Last pushed JMenuItem.
298      * @throws TimeoutExpiredException
299      * @deprecated Use pushMenu(String[]) or pushMenu(String[],
300      * StringComparator)
301      */
302     @Deprecated
303     public JMenuItem pushMenu(String[] names, boolean ce, boolean ccs) {
304         return pushMenu(names, new DefaultStringComparator(ce, ccs));
305     }
306 
307     /**
308      * Executes {@code pushMenu(names, ce, ccs)} in a separate thread.
309      *
310      * @param names an array of menu texts.
311      * @param comparator a string comparision algorithm
312      */
313     public void pushMenuNoBlock(String[] names, StringComparator comparator) {
314         pushMenuNoBlock(JMenuItemOperator.createChoosers(names, comparator));
315     }
316 
317     /**
318      * Executes {@code pushMenu(names, ce, ccs)} in a separate thread.
319      *
320      * @param names Menu items texts.
321      * @param ce Compare text exactly.
322      * @param ccs Compare text case sensitively.
323      * @see #pushMenu(String[], boolean,boolean)
324      * @deprecated Use pushMenuNoBlock(String[]) or pushMenuNoBlock(String[],
325      * StringComparator)
326      */
327     @Deprecated
328     public void pushMenuNoBlock(String[] names, boolean ce, boolean ccs) {
329         pushMenuNoBlock(names, new DefaultStringComparator(ce, ccs));
330     }
331 
332     /**
333      * Pushes menu.
334      *
335      * @param names Menu items texts.
336      * @return Last pushed JMenuItem.
337      * @throws TimeoutExpiredException
338      */
339     public JMenuItem pushMenu(String[] names) {
340         return pushMenu(names, getComparator());
341     }
342 
343     /**
344      * Executes {@code pushMenu(names)} in a separate thread.
345      *
346      * @param names Menu items texts.
347      * @see #pushMenu(String[])
348      */
349     public void pushMenuNoBlock(String[] names) {
350         pushMenuNoBlock(names, getComparator());
351     }
352 
353     /**
354      * Pushes menu.
355      *
356      * @param path a menu path.
357      * @param delim a path delimiter.
358      * @param comparator a string comparision algorithm
359      * @return Last pushed JMenuItem.
360      * @throws TimeoutExpiredException
361      */
362     public JMenuItem pushMenu(String path, String delim, StringComparator comparator) {
363         return pushMenu(parseString(path, delim), comparator);
364     }
365 
366     /**
367      * Pushes menu. Uses PathParser assigned to this operator.
368      *
369      * @param path a menu path.
370      * @param comparator a string comparision algorithm
371      * @return Last pushed JMenuItem.
372      * @throws TimeoutExpiredException
373      */
374     public JMenuItem pushMenu(String path, StringComparator comparator) {
375         return pushMenu(parseString(path), comparator);
376     }
377 
378     /**
379      * Pushes menu.
380      *
381      * @param path String menupath representation ("File/New", for example).
382      * @param delim String menupath divider ("/").
383      * @param ce Compare text exactly.
384      * @param ccs Compare text case sensitively.
385      * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
386      * @return Last pushed JMenuItem.
387      * @throws TimeoutExpiredException
388      * @deprecated Use pushMenu(String, String) or pushMenu(String, String,
389      * StringComparator)
390      */
391     @Deprecated
392     public JMenuItem pushMenu(String path, String delim, boolean ce, boolean ccs) {
393         return pushMenu(parseString(path, delim), ce, ccs);
394     }
395 
396     /**
397      * Executes {@code pushMenu(names, delim, comparator)} in a separate
398      * thread.
399      *
400      * @param path a menu path.
401      * @param delim a path delimiter.
402      * @param comparator a string comparision algorithm
403      */
404     public void pushMenuNoBlock(String path, String delim, StringComparator comparator) {
405         pushMenuNoBlock(parseString(path, delim), comparator);
406     }
407 
408     /**
409      * Executes {@code pushMenu(names, comparator)} in a separate thread.
410      * Uses PathParser assigned to this operator.
411      *
412      * @param path a menu path.
413      * @param comparator a string comparision algorithm
414      */
415     public void pushMenuNoBlock(String path, StringComparator comparator) {
416         pushMenuNoBlock(parseString(path), comparator);
417     }
418 
419     /**
420      * Executes {@code pushMenu(path, delim, ce, ccs)} in a separate
421      * thread.
422      *
423      * @param path String menupath representation ("File/New", for example).
424      * @param delim String menupath divider ("/").
425      * @param ce Compare text exactly.
426      * @param ccs Compare text case sensitively.
427      * @see #pushMenu
428      * @deprecated Use pushMenuNoBlock(String, String) or
429      * pushMenuNoBlock(String, String, StringComparator)
430      */
431     @Deprecated
432     public void pushMenuNoBlock(String path, String delim, boolean ce, boolean ccs) {
433         pushMenuNoBlock(parseString(path, delim), ce, ccs);
434     }
435 
436     /**
437      * Pushes menu.
438      *
439      * @param path String menupath representation ("File/New", for example).
440      * @param delim String menupath divider ("/").
441      * @return Last pushed JMenuItem.
442      * @throws TimeoutExpiredException
443      */
444     public JMenuItem pushMenu(String path, String delim) {
445         return pushMenu(parseString(path, delim));
446     }
447 
448     /**
449      * Pushes menu. Uses PathParser assigned to this operator.
450      *
451      * @param path String menupath representation ("File/New", for example).
452      * @return Last pushed JMenuItem.
453      * @throws TimeoutExpiredException
454      */
455     public JMenuItem pushMenu(String path) {
456         return pushMenu(parseString(path));
457     }
458 
459     /**
460      * Executes {@code pushMenu(path, delim)} in a separate thread.
461      *
462      * @param path String menupath representation ("File/New", for example).
463      * @param delim String menupath divider ("/").
464      */
465     public void pushMenuNoBlock(String path, String delim) {
466         pushMenuNoBlock(parseString(path, delim));
467     }
468 
469     /**
470      * Executes {@code pushMenu(path)} in a separate thread.
471      *
472      * @param path String menupath representation ("File/New", for example).
473      */
474     public void pushMenuNoBlock(String path) {
475         pushMenuNoBlock(parseString(path));
476     }
477 
478     public JMenuItemOperator[] showMenuItems(ComponentChooser[] choosers) {
479         if (choosers == null || choosers.length == 0) {
480             return JMenuItemOperator.getMenuItems((MenuElement) getSource(), this);
481         } else {
482             return JMenuItemOperator.getMenuItems((JMenu) pushMenu(choosers), this);
483         }
484     }
485 
486     /**
487      * Shows submenu of menu specified by a {@code path} parameter.
488      *
489      * @param path an array of menu texts.
490      * @param comparator a string comparision algorithm
491      * @return an array of operators created tor items from the submenu.
492      * @throws TimeoutExpiredException
493      */
494     public JMenuItemOperator[] showMenuItems(String[] path, StringComparator comparator) {
495         if (path == null || path.length == 0) {
496             return JMenuItemOperator.getMenuItems((MenuElement) getSource(), this);
497         } else {
498             return JMenuItemOperator.getMenuItems((JMenu) pushMenu(path, comparator), this);
499         }
500     }
501 
502     /**
503      * Shows submenu of menu specified by a {@code path} parameter. Uses
504      * StringComparator assigned to the operator.
505      *
506      * @param path an array of menu texts.
507      * @return an array of operators created tor items from the submenu.
508      * @throws TimeoutExpiredException
509      */
510     public JMenuItemOperator[] showMenuItems(String[] path) {
511         return showMenuItems(path, getComparator());
512     }
513 
514     /**
515      * Shows submenu of menu specified by a {@code path} parameter.
516      *
517      * @param path a string identifying the menu path.
518      * @param delim a path delimiter.
519      * @param comparator a string comparision algorithm
520      * @return an array of operators created tor items from the submenu.
521      * @throws TimeoutExpiredException
522      */
523     public JMenuItemOperator[] showMenuItems(String path, String delim, StringComparator comparator) {
524         return showMenuItems(parseString(path, delim), comparator);
525     }
526 
527     /**
528      * Shows submenu of menu specified by a {@code path} parameter. Uses
529      * PathParser assigned to this operator.
530      *
531      * @param path a string identifying the menu path.
532      * @param comparator a string comparision algorithm
533      * @return an array of operators created tor items from the submenu.
534      * @throws TimeoutExpiredException
535      */
536     public JMenuItemOperator[] showMenuItems(String path, StringComparator comparator) {
537         return showMenuItems(parseString(path), comparator);
538     }
539 
540     /**
541      * Shows submenu of menu specified by a {@code path} parameter. Uses
542      * StringComparator assigned to the operator.
543      *
544      * @param path a string identifying the menu path.
545      * @param delim a path delimiter.
546      * @return an array of operators created tor items from the submenu.
547      * @throws TimeoutExpiredException
548      */
549     public JMenuItemOperator[] showMenuItems(String path, String delim) {
550         return showMenuItems(path, delim, getComparator());
551     }
552 
553     /**
554      * Shows submenu of menu specified by a {@code path} parameter. Uses
555      * PathParser assigned to this operator. Uses StringComparator assigned to
556      * the operator.
557      *
558      * @param path a string identifying the menu path.
559      * @return an array of operators created tor items from the submenu.
560      * @throws TimeoutExpiredException
561      */
562     public JMenuItemOperator[] showMenuItems(String path) {
563         return showMenuItems(path, getComparator());
564     }
565 
566     public JMenuItemOperator showMenuItem(ComponentChooser[] choosers) {
567         ComponentChooser[] parentPath = getParentPath(choosers);
568         JMenu menu;
569         ContainerOperator<?> menuCont;
570         if (parentPath.length > 0) {
571             menu = (JMenu) pushMenu(getParentPath(choosers));
572             menuCont = new ContainerOperator<>(menu.getPopupMenu());
573             menuCont.copyEnvironment(this);
574         } else {
575             menuCont = this;
576         }
577         JMenuItemOperator result = new JMenuItemOperator(menuCont, choosers[choosers.length - 1]);
578         result.copyEnvironment(this);
579         return result;
580     }
581 
582     /**
583      * Expends all menus to show menu item specified by a {@code path}
584      * parameter.
585      *
586      * @param path an array of menu texts.
587      * @param comparator a string comparision algorithm
588      * @return an operator for the last menu item in path.
589      * @throws TimeoutExpiredException
590      */
591     public JMenuItemOperator showMenuItem(String[] path, StringComparator comparator) {
592         String[] parentPath = getParentPath(path);
593         JMenu menu;
594         ContainerOperator<?> menuCont;
595         if (parentPath.length > 0) {
596             menu = (JMenu) pushMenu(getParentPath(path), comparator);
597             menuCont = new ContainerOperator<>(menu.getPopupMenu());
598             menuCont.copyEnvironment(this);
599         } else {
600             menuCont = this;
601         }
602         JMenuItemOperator result;
603         // isVisible() on items returns false on mac, so we need a special searcher.
604         if (Platform.isOSX()) {
605             ComponentSearcher searcher = new ComponentSearcher((Container) menuCont.getSource());
606             searcher.setOutput(output);
607             Component c = searcher.findComponent(new JMenuItemOperator.JMenuItemByLabelFinder(path[path.length - 1], getComparator()));
608             result = new JMenuItemOperator((JMenuItem) c);
609         } else {
610             result = new JMenuItemOperator(menuCont, path[path.length - 1]);
611         }
612         result.copyEnvironment(this);
613         return result;
614     }
615 
616     /**
617      * Expands all menus to show menu item specified by a {@code path}
618      * parameter.
619      *
620      * @param path an array of menu texts.
621      * @return an operator for the last menu item in path.
622      * @throws TimeoutExpiredException
623      */
624     public JMenuItemOperator showMenuItem(String[] path) {
625         return showMenuItem(path, getComparator());
626     }
627 
628     /**
629      * Expands all menus to show menu item specified by a {@code path}
630      * parameter.
631      *
632      * @param path a string identifying the menu path.
633      * @param delim a path delimiter.
634      * @param comparator a string comparision algorithm
635      * @return an operator for the last menu item in path.
636      * @throws TimeoutExpiredException
637      */
638     public JMenuItemOperator showMenuItem(String path, String delim, StringComparator comparator) {
639         return showMenuItem(parseString(path, delim), comparator);
640     }
641 
642     /**
643      * Expands all menus to show menu item specified by a {@code path}
644      * parameter. Uses PathParser assigned to this operator.
645      *
646      * @param path a string identifying the menu path.
647      * @param comparator a string comparision algorithm
648      * @return an operator for the last menu item in path.
649      * @throws TimeoutExpiredException
650      */
651     public JMenuItemOperator showMenuItem(String path, StringComparator comparator) {
652         return showMenuItem(parseString(path), comparator);
653     }
654 
655     /**
656      * Expands all menus to show menu item specified by a {@code path}
657      * parameter. Uses StringComparator assigned to the operator.
658      *
659      * @param path a string identifying the menu path.
660      * @param delim a path delimiter.
661      * @return an operator for the last menu item in path.
662      * @throws TimeoutExpiredException
663      */
664     public JMenuItemOperator showMenuItem(String path, String delim) {
665         return showMenuItem(path, delim, getComparator());
666     }
667 
668     /**
669      * Expands all menus to show menu item specified by a {@code path}
670      * parameter. Uses PathParser assigned to this operator. Uses
671      * StringComparator assigned to the operator.
672      *
673      * @param path a string identifying the menu path.
674      * @return an array of operators created tor items from the submenu.
675      * @throws TimeoutExpiredException
676      */
677     public JMenuItemOperator showMenuItem(String path) {
678         return showMenuItem(path, getComparator());
679     }
680 
681     /**
682      * Closes all expanded submenus.
683      */
684     public void closeSubmenus() {
685         JMenu menu = (JMenu) findSubComponent(new ComponentChooser() {
686             @Override
687             public boolean checkComponent(Component comp) {
688                 return (comp instanceof JMenu
689                         && ((JMenu) comp).isPopupMenuVisible());
690             }
691 
692             @Override
693             public String getDescription() {
694                 return "Expanded JMenu";
695             }
696 
697             @Override
698             public String toString() {
699                 return "JMenuBarOperator.closeSubmenus.ComponentChooser{description = " + getDescription() + '}';
700             }
701         });
702         if (menu != null) {
703             JMenuOperator oper = new JMenuOperator(menu);
704             oper.copyEnvironment(this);
705             oper.push();
706         }
707     }
708 
709     @Override
710     public Hashtable<String, Object> getDump() {
711         Hashtable<String, Object> result = super.getDump();
712         String[] items = new String[((JMenuBar) getSource()).getMenuCount()];
713         for (int i = 0; i < ((JMenuBar) getSource()).getMenuCount(); i++) {
714             if (((JMenuBar) getSource()).getMenu(i) != null) {
715                 items[i] = ((JMenuBar) getSource()).getMenu(i).getText();
716             } else {
717                 items[i] = "null";
718             }
719         }
720         addToDump(result, SUBMENU_PREFIX_DPROP, items);
721         return result;
722     }
723 
724     ////////////////////////////////////////////////////////
725     //Mapping                                             //
726     /**
727      * Maps {@code JMenuBar.add(JMenu)} through queue
728      */
729     public JMenu add(final JMenu jMenu) {
730         return (runMapping(new MapAction<JMenu>("add") {
731             @Override
732             public JMenu map() {
733                 return ((JMenuBar) getSource()).add(jMenu);
734             }
735         }));
736     }
737 
738     /**
739      * Maps {@code JMenuBar.getComponentIndex(Component)} through queue
740      */
741     public int getComponentIndex(final Component component) {
742         return (runMapping(new MapIntegerAction("getComponentIndex") {
743             @Override
744             public int map() {
745                 return ((JMenuBar) getSource()).getComponentIndex(component);
746             }
747         }));
748     }
749 
750     /**
751      * Maps {@code JMenuBar.getHelpMenu()} through queue
752      */
753     public JMenu getHelpMenu() {
754         return (runMapping(new MapAction<JMenu>("getHelpMenu") {
755             @Override
756             public JMenu map() {
757                 return ((JMenuBar) getSource()).getHelpMenu();
758             }
759         }));
760     }
761 
762     /**
763      * Maps {@code JMenuBar.getMargin()} through queue
764      */
765     public Insets getMargin() {
766         return (runMapping(new MapAction<Insets>("getMargin") {
767             @Override
768             public Insets map() {
769                 return ((JMenuBar) getSource()).getMargin();
770             }
771         }));
772     }
773 
774     /**
775      * Maps {@code JMenuBar.getMenu(int)} through queue
776      */
777     public JMenu getMenu(final int i) {
778         return (runMapping(new MapAction<JMenu>("getMenu") {
779             @Override
780             public JMenu map() {
781                 return ((JMenuBar) getSource()).getMenu(i);
782             }
783         }));
784     }
785 
786     /**
787      * Maps {@code JMenuBar.getMenuCount()} through queue
788      */
789     public int getMenuCount() {
790         return (runMapping(new MapIntegerAction("getMenuCount") {
791             @Override
792             public int map() {
793                 return ((JMenuBar) getSource()).getMenuCount();
794             }
795         }));
796     }
797 
798     /**
799      * Maps {@code JMenuBar.getSelectionModel()} through queue
800      */
801     public SingleSelectionModel getSelectionModel() {
802         return (runMapping(new MapAction<SingleSelectionModel>("getSelectionModel") {
803             @Override
804             public SingleSelectionModel map() {
805                 return ((JMenuBar) getSource()).getSelectionModel();
806             }
807         }));
808     }
809 
810     /**
811      * Maps {@code JMenuBar.getSubElements()} through queue
812      */
813     public MenuElement[] getSubElements() {
814         return ((MenuElement[]) runMapping(new MapAction<Object>("getSubElements") {
815             @Override
816             public Object map() {
817                 return ((JMenuBar) getSource()).getSubElements();
818             }
819         }));
820     }
821 
822     /**
823      * Maps {@code JMenuBar.getUI()} through queue
824      */
825     public MenuBarUI getUI() {
826         return (runMapping(new MapAction<MenuBarUI>("getUI") {
827             @Override
828             public MenuBarUI map() {
829                 return ((JMenuBar) getSource()).getUI();
830             }
831         }));
832     }
833 
834     /**
835      * Maps {@code JMenuBar.isBorderPainted()} through queue
836      */
837     public boolean isBorderPainted() {
838         return (runMapping(new MapBooleanAction("isBorderPainted") {
839             @Override
840             public boolean map() {
841                 return ((JMenuBar) getSource()).isBorderPainted();
842             }
843         }));
844     }
845 
846     /**
847      * Maps {@code JMenuBar.isSelected()} through queue
848      */
849     public boolean isSelected() {
850         return (runMapping(new MapBooleanAction("isSelected") {
851             @Override
852             public boolean map() {
853                 return ((JMenuBar) getSource()).isSelected();
854             }
855         }));
856     }
857 
858     /**
859      * Maps {@code JMenuBar.menuSelectionChanged(boolean)} through queue
860      */
861     public void menuSelectionChanged(final boolean b) {
862         runMapping(new MapVoidAction("menuSelectionChanged") {
863             @Override
864             public void map() {
865                 ((JMenuBar) getSource()).menuSelectionChanged(b);
866             }
867         });
868     }
869 
870     /**
871      * Maps
872      * {@code JMenuBar.processKeyEvent(KeyEvent, MenuElement[], MenuSelectionManager)}
873      * through queue
874      */
875     public void processKeyEvent(final KeyEvent keyEvent, final MenuElement[] menuElement, final MenuSelectionManager menuSelectionManager) {
876         runMapping(new MapVoidAction("processKeyEvent") {
877             @Override
878             public void map() {
879                 ((JMenuBar) getSource()).processKeyEvent(keyEvent, menuElement, menuSelectionManager);
880             }
881         });
882     }
883 
884     /**
885      * Maps
886      * {@code JMenuBar.processMouseEvent(MouseEvent, MenuElement[], MenuSelectionManager)}
887      * through queue
888      */
889     public void processMouseEvent(final MouseEvent mouseEvent, final MenuElement[] menuElement, final MenuSelectionManager menuSelectionManager) {
890         runMapping(new MapVoidAction("processMouseEvent") {
891             @Override
892             public void map() {
893                 ((JMenuBar) getSource()).processMouseEvent(mouseEvent, menuElement, menuSelectionManager);
894             }
895         });
896     }
897 
898     /**
899      * Maps {@code JMenuBar.setBorderPainted(boolean)} through queue
900      */
901     public void setBorderPainted(final boolean b) {
902         runMapping(new MapVoidAction("setBorderPainted") {
903             @Override
904             public void map() {
905                 ((JMenuBar) getSource()).setBorderPainted(b);
906             }
907         });
908     }
909 
910     /**
911      * Maps {@code JMenuBar.setHelpMenu(JMenu)} through queue
912      */
913     public void setHelpMenu(final JMenu jMenu) {
914         runMapping(new MapVoidAction("setHelpMenu") {
915             @Override
916             public void map() {
917                 ((JMenuBar) getSource()).setHelpMenu(jMenu);
918             }
919         });
920     }
921 
922     /**
923      * Maps {@code JMenuBar.setMargin(Insets)} through queue
924      */
925     public void setMargin(final Insets insets) {
926         runMapping(new MapVoidAction("setMargin") {
927             @Override
928             public void map() {
929                 ((JMenuBar) getSource()).setMargin(insets);
930             }
931         });
932     }
933 
934     /**
935      * Maps {@code JMenuBar.setSelected(Component)} through queue
936      */
937     public void setSelected(final Component component) {
938         runMapping(new MapVoidAction("setSelected") {
939             @Override
940             public void map() {
941                 ((JMenuBar) getSource()).setSelected(component);
942             }
943         });
944     }
945 
946     /**
947      * Maps {@code JMenuBar.setSelectionModel(SingleSelectionModel)}
948      * through queue
949      */
950     public void setSelectionModel(final SingleSelectionModel singleSelectionModel) {
951         runMapping(new MapVoidAction("setSelectionModel") {
952             @Override
953             public void map() {
954                 ((JMenuBar) getSource()).setSelectionModel(singleSelectionModel);
955             }
956         });
957     }
958 
959     /**
960      * Maps {@code JMenuBar.setUI(MenuBarUI)} through queue
961      */
962     public void setUI(final MenuBarUI menuBarUI) {
963         runMapping(new MapVoidAction("setUI") {
964             @Override
965             public void map() {
966                 ((JMenuBar) getSource()).setUI(menuBarUI);
967             }
968         });
969     }
970 
971     //End of mapping                                      //
972     ////////////////////////////////////////////////////////
973     /**
974      * Checks component type.
975      */
976     public static class JMenuBarFinder extends Finder {
977 
978         /**
979          * Constructs JMenuBarFinder.
980          *
981          * @param sf other searching criteria.
982          */
983         public JMenuBarFinder(ComponentChooser sf) {
984             super(JMenuBar.class, sf);
985         }
986 
987         /**
988          * Constructs JMenuBarFinder.
989          */
990         public JMenuBarFinder() {
991             super(JMenuBar.class);
992         }
993     }
994 
995 }
996