1/* 2 * Copyright (c) 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 */ 23 24/* 25 * @test 26 * @bug 6191390 27 * @summary Verify that ActionEvent is received with correct modifiers set. 28 * @run main/manual ActionEventTest 29 */ 30 31import java.awt.Frame; 32import java.awt.Menu; 33import java.awt.MenuBar; 34import java.awt.MenuItem; 35import java.awt.TextArea; 36import java.awt.event.ActionEvent; 37import java.awt.event.ActionListener; 38 39public final class ActionEventTest extends Frame { 40 41 MenuBar menuBar; 42 TextArea instructions; 43 public static boolean isProgInterruption = false; 44 static Thread mainThread = null; 45 static int sleepTime = 300000; 46 47 public ActionEventTest() { 48 menuBar = new MenuBar(); 49 Menu menu = new Menu("Menu1"); 50 MenuItem menuItem = new MenuItem("MenuItem"); 51 52 menuItem.addActionListener(new ActionListener() { 53 @Override 54 public void actionPerformed(ActionEvent ae) { 55 System.out.println("actionPerformed"); 56 int md = ae.getModifiers(); 57 int expectedMask = ActionEvent.ALT_MASK | ActionEvent.CTRL_MASK 58 | ActionEvent.SHIFT_MASK; 59 60 isProgInterruption = true; 61 mainThread.interrupt(); 62 if ((md & expectedMask) != expectedMask) { 63 throw new RuntimeException("Action Event modifiers are not" 64 + " set correctly."); 65 } 66 } 67 }); 68 menu.add(menuItem); 69 menuBar.add(menu); 70 setMenuBar(menuBar); 71 72 instructions = new TextArea(10, 50); 73 instructions.setText( 74 " This is a manual test\n" + 75 " Keep the Alt, Shift & Ctrl Keys pressed while doing next steps\n" + 76 " Click 'Menu1' Menu from the Menu Bar\n" + 77 " It will show 'MenuItem'\n" + 78 " Left mouse Click the 'MenuItem'\n" + 79 " Test exits automatically after mouse click."); 80 add(instructions); 81 82 setSize(400, 400); 83 setVisible(true); 84 validate(); 85 } 86 87 88 public static void main(final String[] args) throws Exception { 89 mainThread = Thread.currentThread(); 90 ActionEventTest test = new ActionEventTest(); 91 try { 92 mainThread.sleep(sleepTime); 93 } catch (InterruptedException e) { 94 if (!isProgInterruption) { 95 throw e; 96 } 97 } 98 test.dispose(); 99 if (!isProgInterruption) { 100 throw new RuntimeException("Timed out after " + sleepTime / 1000 101 + " seconds"); 102 } 103 } 104} 105