Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Choice/SelectCurrentItemTest/SelectCurrentItemTest.java
41153 views
1
/*
2
* Copyright (c) 2002, 2018, 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 4902933 8197810
26
@summary Test that selecting the current item doesnot send an ItemEvent
27
@key headful
28
@run main SelectCurrentItemTest
29
*/
30
31
import java.awt.Choice;
32
import java.awt.Robot;
33
import java.awt.Frame;
34
import java.awt.BorderLayout;
35
import java.awt.AWTException;
36
import java.awt.Point;
37
import java.awt.Dimension;
38
import java.awt.event.InputEvent;
39
import java.awt.event.ItemListener;
40
import java.awt.event.WindowListener;
41
import java.awt.event.ItemEvent;
42
import java.awt.event.WindowEvent;
43
import java.util.concurrent.CountDownLatch;
44
import java.util.concurrent.TimeUnit;
45
46
public class SelectCurrentItemTest implements ItemListener, WindowListener {
47
//Declare things used in the test, like buttons and labels here
48
private Frame frame;
49
private Choice theChoice;
50
private Robot robot;
51
52
private CountDownLatch latch = new CountDownLatch(1);
53
private volatile boolean passed = true;
54
55
private void init()
56
{
57
try {
58
robot = new Robot();
59
robot.setAutoDelay(500);
60
} catch (AWTException e) {
61
throw new RuntimeException("Unable to create Robot. Test fails.");
62
}
63
64
frame = new Frame("SelectCurrentItemTest");
65
frame.setLayout(new BorderLayout());
66
theChoice = new Choice();
67
for (int i = 0; i < 10; i++) {
68
theChoice.add(new String("Choice Item " + i));
69
}
70
theChoice.addItemListener(this);
71
frame.add(theChoice);
72
frame.addWindowListener(this);
73
74
frame.setLocation(1,20);
75
robot.mouseMove(10, 30);
76
frame.pack();
77
frame.setVisible(true);
78
}
79
80
public static void main(String... args) {
81
SelectCurrentItemTest test = new SelectCurrentItemTest();
82
test.init();
83
try {
84
test.latch.await(12000, TimeUnit.MILLISECONDS);
85
} catch (InterruptedException e) {}
86
test.robot.waitForIdle();
87
88
try {
89
if (!test.passed) {
90
throw new RuntimeException("TEST FAILED.");
91
}
92
} finally {
93
test.frame.dispose();
94
}
95
}
96
97
private void run() {
98
try {Thread.sleep(1000);} catch (InterruptedException e){}
99
// get loc of Choice on screen
100
Point loc = theChoice.getLocationOnScreen();
101
// get bounds of Choice
102
Dimension size = theChoice.getSize();
103
robot.mouseMove(loc.x + size.width - 10, loc.y + size.height / 2);
104
105
robot.setAutoDelay(250);
106
robot.mousePress(InputEvent.BUTTON1_MASK);
107
robot.mouseRelease(InputEvent.BUTTON1_MASK);
108
109
robot.delay(1000);
110
111
robot.mouseMove(loc.x + size.width / 2, loc.y + size.height);
112
robot.mousePress(InputEvent.BUTTON1_MASK);
113
robot.mouseRelease(InputEvent.BUTTON1_MASK);
114
robot.waitForIdle();
115
latch.countDown();
116
}
117
118
@Override public void itemStateChanged(ItemEvent e) {
119
System.out.println("ItemEvent received. Test fails");
120
passed = false;
121
}
122
123
@Override public void windowOpened(WindowEvent e) {
124
System.out.println("windowActivated()");
125
(new Thread(this::run)).start();
126
}
127
128
@Override public void windowActivated(WindowEvent e) {}
129
@Override public void windowDeactivated(WindowEvent e) {}
130
@Override public void windowClosed(WindowEvent e) {}
131
@Override public void windowClosing(WindowEvent e) {}
132
@Override public void windowIconified(WindowEvent e) {}
133
@Override public void windowDeiconified(WindowEvent e) {}
134
}
135
136