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