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 */ 29 30 import java.awt.AWTException; 31 import java.awt.FlowLayout; 32 import java.awt.Frame; 33 import java.awt.List; 34 import java.awt.Robot; 35 import java.awt.event.ActionEvent; 36 import java.awt.event.ActionListener; 37 import java.awt.event.KeyEvent; 38 39 public class ActionEventTest extends Frame { 40 List list; 41 Robot robot; 42 43 public ActionEventTest() { 44 try { 45 robot = new Robot(); 46 } catch(AWTException e) { 47 throw new RuntimeException(e.getMessage()); 48 } 49 50 list = new List(1, false); 51 list.add("0"); 52 add(list); 53 setSize(400,400); 54 setLayout(new FlowLayout()); 55 pack(); 56 setVisible(true); 57 robot.waitForIdle(); 58 } 59 60 void performTest() { 61 list.addActionListener(new ActionListener() { 62 @Override 63 public void actionPerformed(ActionEvent ae) { 64 int md = ae.getModifiers(); 65 int expectedMask = ActionEvent.ALT_MASK | ActionEvent.CTRL_MASK 66 | ActionEvent.SHIFT_MASK; 67 68 if ((md & expectedMask) != expectedMask) { 69 70 robot.keyRelease(KeyEvent.VK_ALT); 71 robot.keyRelease(KeyEvent.VK_SHIFT); 72 robot.keyRelease(KeyEvent.VK_CONTROL); 73 dispose(); 74 throw new RuntimeException("Action Event modifiers are not" 75 + " set correctly."); 76 } 77 } 78 }); 79 80 list.select(0); 81 robot.keyPress(KeyEvent.VK_ALT); 82 robot.keyPress(KeyEvent.VK_SHIFT); 83 robot.keyPress(KeyEvent.VK_CONTROL); 84 // Press Enter on list item, to generate action event. 85 robot.keyPress(KeyEvent.VK_ENTER); 86 robot.keyRelease(KeyEvent.VK_ENTER); 87 robot.waitForIdle(); 88 robot.keyRelease(KeyEvent.VK_ALT); 89 robot.keyRelease(KeyEvent.VK_SHIFT); 90 robot.keyRelease(KeyEvent.VK_CONTROL); 91 robot.waitForIdle(); 92 } 93 94 public static void main(String args[]) { 95 ActionEventTest test = new ActionEventTest(); 96 test.performTest(); 97 test.dispose(); 98 } 99 }