Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/InputMethods/InputMethodKeyEventsTest/InputMethodKeyEventsTest.java
41153 views
1
/*
2
* Copyright (c) 2017, 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
/* @test
25
* @bug 8177414
26
* @summary KEY_PRESSED and KEY_TYPED events are not generated if a key's held
27
* @library ../../regtesthelpers
28
* @build Util
29
* @run main/manual InputMethodKeyEventsTest
30
*/
31
32
import java.awt.*;
33
import java.awt.event.ActionEvent;
34
import java.awt.event.ActionListener;
35
import java.awt.event.KeyEvent;
36
import java.awt.event.KeyListener;
37
import java.util.concurrent.atomic.AtomicBoolean;
38
39
import test.java.awt.regtesthelpers.Util;
40
41
public class InputMethodKeyEventsTest {
42
private static final AtomicBoolean testCompleted = new AtomicBoolean(false);
43
private static volatile boolean testResult = false;
44
45
private static Dialog controlDialog;
46
private static Frame testFrame;
47
48
private static final String instructions =
49
"Verify that KEY_PRESSED and KEY_TYPED events are generated after a key's " +
50
"\npressed and held.\n" +
51
"\nThis test is for OS X only. For other platforms please simply press \"Pass\".\n" +
52
"\n1. Go to \"System Preferences -> Keyboard -> Input Sources\" and add \"British\" IM." +
53
"\n2. Set current IM to \"British\"." +
54
"\n3. Set focus to the frame located at north-west corner." +
55
"\n4. Pres and hold the \"i\" key for 3 seconds." +
56
"\n5. Press and release the \"i\" key again. Use log area to ensure that " +
57
"\n KEY_TYPED and KEY_PRESSED events are still generated." +
58
"\nIf KEY_PRESSED, KEY_TYPED and KEY_RELEASED are generated for every key press then " +
59
"\npress \"Pass\", otherwise press \"Fail\".";
60
61
public static void main(String[] args) {
62
try {
63
Robot robot = Util.createRobot();
64
65
createAndShowGUI();
66
Util.waitForIdle(robot);
67
68
Util.waitForCondition(testCompleted);
69
if (!testResult) {
70
throw new RuntimeException("Test FAILED!");
71
}
72
} finally {
73
if (controlDialog != null) {
74
controlDialog.dispose();
75
}
76
if (testFrame != null) {
77
testFrame.dispose();
78
}
79
}
80
}
81
82
private static void createAndShowGUI() {
83
controlDialog = new Dialog((Frame)null, "InputMethodKeyEventsTest");
84
85
TextArea messageArea = new TextArea(instructions, 15, 80, TextArea.SCROLLBARS_BOTH);
86
controlDialog.add("North", messageArea);
87
88
TextArea logArea = new TextArea("Test's logs are displayed here\n", 15, 80, TextArea.SCROLLBARS_BOTH);
89
controlDialog.add("Center", logArea);
90
91
Button passedButton = new Button("Pass");
92
passedButton.addActionListener(new ActionListener() {
93
@Override
94
public void actionPerformed(ActionEvent e) {
95
testResult = true;
96
completeTest();
97
}
98
});
99
100
Button failedButton = new Button("Fail");
101
failedButton.addActionListener(new ActionListener() {
102
@Override
103
public void actionPerformed(ActionEvent e) {
104
testResult = false;
105
completeTest();
106
}
107
});
108
109
Panel buttonPanel = new Panel();
110
buttonPanel.add("West",passedButton);
111
buttonPanel.add("East", failedButton);
112
controlDialog.add("South", buttonPanel);
113
114
controlDialog.setBounds(250, 0, 500, 500);
115
controlDialog.setVisible(true);
116
117
testFrame = new Frame("InputMethodKeyEventsTest");
118
testFrame.setSize(200, 200);
119
testFrame.addKeyListener(new KeyListener() {
120
@Override
121
public void keyTyped(KeyEvent e) {
122
logArea.append("KEY_TYPED keyCode = " + e.getKeyCode() + "\n");
123
}
124
125
@Override
126
public void keyPressed(KeyEvent e) {
127
logArea.append("KEY_PRESSED keyCode = " + e.getKeyCode() + "\n");
128
}
129
130
@Override
131
public void keyReleased(KeyEvent e) {
132
logArea.append("KEY_RELEASED keyCode = " + e.getKeyCode() + "\n");
133
}
134
});
135
testFrame.setVisible(true);
136
}
137
138
private static void completeTest() {
139
testCompleted.set(true);
140
synchronized (testCompleted) {
141
testCompleted.notifyAll();
142
}
143
}
144
}
145
146