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