1/*
2 * Copyright (c) 2013, 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 */
23
24/*
25 * @test
26 * @key headful
27 * @bug 4171437
28 * @library ../../regtesthelpers
29 * @build Util
30 * @author Georges Saab
31 * @run main bug4171437
32 */
33
34import java.awt.*;
35import java.awt.event.*;
36import java.util.ArrayList;
37import javax.swing.*;
38import javax.swing.event.*;
39
40public class bug4171437 {
41    static volatile boolean closeActivated = false;
42    static volatile boolean customActivated = false;
43
44    public static void main(String[] args) throws Exception {
45        SwingUtilities.invokeAndWait(new Runnable() {
46            public void run() {
47                createAndShowGUI();
48            }
49        });
50
51        Robot robot = new Robot();
52        robot.setAutoDelay(50);
53        robot.waitForIdle();
54
55        Util.hitMnemonics(robot, KeyEvent.VK_F);
56        Util.hitKeys(robot, KeyEvent.VK_C);
57
58        robot.waitForIdle();
59        Thread.sleep(1000);
60
61        if (!closeActivated || customActivated) {
62            throw new RuntimeException("Didn't pass the muster");
63        }
64    }
65    public static void createAndShowGUI() {
66        JMenuBar menubar = new JMenuBar();
67
68        JMenu fileMenu = new JMenu("File");
69        fileMenu.setMnemonic('f');
70
71        JMenuItem fmi1 = new JMenuItem();
72        fmi1 = new JMenuItem("Open");
73        JMenuItem fmi2 = new JMenuItem();
74        fmi2 = new JMenuItem("Close");
75        fmi2.setMnemonic('c');
76        fmi2.addActionListener(new ActionListener() {
77            public void actionPerformed(ActionEvent e) {
78                closeActivated = true;
79            }
80        });
81
82        fileMenu.add( fmi1);
83        fileMenu.add( fmi2);
84
85        menubar.add( fileMenu);
86
87        JMenu custom = new JMenu("Custom");
88        custom.setMnemonic('c');
89        JMenuItem cmi = new JMenuItem();
90        cmi = new JMenuItem("Properties");
91        cmi.setMnemonic('p');
92        custom.add( cmi);
93        custom.addMenuListener(new MenuListener() {
94            public void menuSelected(MenuEvent e) {
95                customActivated = true;
96            }
97            public void menuDeselected(MenuEvent e) {}
98            public void menuCanceled(MenuEvent e) {}
99        });
100        menubar.add( custom);
101
102        JFrame frame = new JFrame();
103        frame.setJMenuBar( menubar);
104        frame.setSize(300, 300);
105        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
106        frame.pack();
107        frame.setVisible(true);
108    }
109}
110