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 7160951 8152492 8178448
28 * @summary [macosx] ActionListener called twice for JMenuItem using ScreenMenuBar
29 * @author vera.akulova@oracle.com
30 * @modules java.desktop/java.awt:open
31 * @library ../../../../lib/testlibrary
32 * @build jdk.testlibrary.OSInfo
33 * @run main ActionListenerCalledTwiceTest
34 */
35
36 import jdk.testlibrary.OSInfo;
37 import java.awt.*;
38 import java.awt.event.*;
39 import javax.swing.*;
40
41 public class ActionListenerCalledTwiceTest {
42
43 static String menuItems[] = {"Item1", "Item2", "Item3",
44 "Item4", "Item5", "Item6"};
45 static KeyStroke keyStrokes[] = {
46 KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.META_MASK),
47 KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0),
48 KeyStroke.getKeyStroke(KeyEvent.VK_UP, InputEvent.SHIFT_MASK),
49 KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.META_MASK),
50 KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.CTRL_MASK),
51 KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, InputEvent.META_MASK)
52 };
53
54 static JMenuBar bar;
55 static JFrame frame;
56 static volatile int listenerCallCounter = 0;
57
58 public static void main(String[] args) throws Exception {
59 if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
60 System.out.println("This test is for MacOS only." +
61 " Automatically passed on other platforms.");
62 return;
63 }
64
65 try {
66
67 System.setProperty("apple.laf.useScreenMenuBar", "true");
68 SwingUtilities.invokeAndWait(
69 ActionListenerCalledTwiceTest::createAndShowGUI);
70
71 Robot robot = new Robot();
72 robot.setAutoDelay(100);
73
74 testForTwice(robot, "");
75
76 SwingUtilities.invokeAndWait(
77 ActionListenerCalledTwiceTest::testDefaultMenuBar);
78 robot.waitForIdle();
79
|
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 7160951 8152492 8178448
28 * @summary [macosx] ActionListener called twice for JMenuItem using ScreenMenuBar
29 * @author vera.akulova@oracle.com
30 * @modules java.desktop/java.awt:open
31 * @library /test/lib
32 * @build jdk.test.lib.Platform
33 * @run main ActionListenerCalledTwiceTest
34 */
35
36 import jdk.test.lib.Platform;
37 import java.awt.*;
38 import java.awt.event.*;
39 import javax.swing.*;
40
41 public class ActionListenerCalledTwiceTest {
42
43 static String menuItems[] = {"Item1", "Item2", "Item3",
44 "Item4", "Item5", "Item6"};
45 static KeyStroke keyStrokes[] = {
46 KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.META_MASK),
47 KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0),
48 KeyStroke.getKeyStroke(KeyEvent.VK_UP, InputEvent.SHIFT_MASK),
49 KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.META_MASK),
50 KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.CTRL_MASK),
51 KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, InputEvent.META_MASK)
52 };
53
54 static JMenuBar bar;
55 static JFrame frame;
56 static volatile int listenerCallCounter = 0;
57
58 public static void main(String[] args) throws Exception {
59 if (!Platform.isOSX()) {
60 System.out.println("This test is for MacOS only." +
61 " Automatically passed on other platforms.");
62 return;
63 }
64
65 try {
66
67 System.setProperty("apple.laf.useScreenMenuBar", "true");
68 SwingUtilities.invokeAndWait(
69 ActionListenerCalledTwiceTest::createAndShowGUI);
70
71 Robot robot = new Robot();
72 robot.setAutoDelay(100);
73
74 testForTwice(robot, "");
75
76 SwingUtilities.invokeAndWait(
77 ActionListenerCalledTwiceTest::testDefaultMenuBar);
78 robot.waitForIdle();
79
|