Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Mixing/LWComboBox.java
41149 views
1
/*
2
* Copyright (c) 2009, 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
/*
25
@test %W% %E%
26
@key headful
27
@bug 6637655
28
@summary Tests whether a LW combobox correctly overlaps a HW button
29
@author anthony.petrov@...: area=awt.mixing
30
@library ../regtesthelpers
31
@build Util
32
@run main LWComboBox
33
*/
34
35
36
/**
37
* LWComboBox.java
38
*
39
* summary: Tests whether a LW combobox correctly overlaps a HW button
40
*/
41
42
import java.awt.*;
43
import java.awt.event.*;
44
import javax.swing.*;
45
import java.util.Vector;
46
import test.java.awt.regtesthelpers.Util;
47
48
49
50
public class LWComboBox
51
{
52
static volatile boolean failed = false;
53
54
private static void init()
55
{
56
JFrame f = new JFrame("LW menu test");
57
58
JComboBox ch;
59
Button b;
60
61
Vector v = new Vector();
62
for(int i = 1 ; i <=20;i++){
63
v.add("Item # "+i);
64
}
65
ch = new JComboBox(v);
66
67
68
b = new Button("AWT Button");
69
b.addActionListener(new ActionListener() {
70
public void actionPerformed(ActionEvent e) {
71
failed = true;
72
}
73
});
74
75
f.add(ch,BorderLayout.NORTH);
76
f.add(b,BorderLayout.CENTER);
77
f.setSize(300,300);
78
f.setVisible(true);
79
80
Robot robot = Util.createRobot();
81
robot.setAutoDelay(20);
82
83
Util.waitForIdle(robot);
84
85
// Pop up the combobox
86
Point lLoc = ch.getLocationOnScreen();
87
System.err.println("lLoc: " + lLoc);
88
robot.mouseMove(lLoc.x + 5, lLoc.y + 5);
89
90
robot.mousePress(InputEvent.BUTTON1_MASK);
91
robot.mouseRelease(InputEvent.BUTTON1_MASK);
92
Util.waitForIdle(robot);
93
94
// Click on the combo popup.
95
// It's assumed that the popup item is located
96
// above the heavyweight button.
97
Point bLoc = b.getLocationOnScreen();
98
System.err.println("bLoc: " + bLoc);
99
robot.mouseMove(bLoc.x + 10, bLoc.y + 10);
100
101
robot.mousePress(InputEvent.BUTTON1_MASK);
102
robot.mouseRelease(InputEvent.BUTTON1_MASK);
103
Util.waitForIdle(robot);
104
105
if (failed) {
106
fail("The LW popup did not received the click.");
107
} else {
108
pass();
109
}
110
}//End init()
111
112
113
114
/*****************************************************
115
* Standard Test Machinery Section
116
* DO NOT modify anything in this section -- it's a
117
* standard chunk of code which has all of the
118
* synchronisation necessary for the test harness.
119
* By keeping it the same in all tests, it is easier
120
* to read and understand someone else's test, as
121
* well as insuring that all tests behave correctly
122
* with the test harness.
123
* There is a section following this for test-
124
* classes
125
******************************************************/
126
private static boolean theTestPassed = false;
127
private static boolean testGeneratedInterrupt = false;
128
private static String failureMessage = "";
129
130
private static Thread mainThread = null;
131
132
private static int sleepTime = 300000;
133
134
// Not sure about what happens if multiple of this test are
135
// instantiated in the same VM. Being static (and using
136
// static vars), it aint gonna work. Not worrying about
137
// it for now.
138
public static void main( String args[] ) throws InterruptedException
139
{
140
mainThread = Thread.currentThread();
141
try
142
{
143
init();
144
}
145
catch( TestPassedException e )
146
{
147
//The test passed, so just return from main and harness will
148
// interepret this return as a pass
149
return;
150
}
151
//At this point, neither test pass nor test fail has been
152
// called -- either would have thrown an exception and ended the
153
// test, so we know we have multiple threads.
154
155
//Test involves other threads, so sleep and wait for them to
156
// called pass() or fail()
157
try
158
{
159
Thread.sleep( sleepTime );
160
//Timed out, so fail the test
161
throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
162
}
163
catch (InterruptedException e)
164
{
165
//The test harness may have interrupted the test. If so, rethrow the exception
166
// so that the harness gets it and deals with it.
167
if( ! testGeneratedInterrupt ) throw e;
168
169
//reset flag in case hit this code more than once for some reason (just safety)
170
testGeneratedInterrupt = false;
171
172
if ( theTestPassed == false )
173
{
174
throw new RuntimeException( failureMessage );
175
}
176
}
177
178
}//main
179
180
public static synchronized void setTimeoutTo( int seconds )
181
{
182
sleepTime = seconds * 1000;
183
}
184
185
public static synchronized void pass()
186
{
187
System.out.println( "The test passed." );
188
System.out.println( "The test is over, hit Ctl-C to stop Java VM" );
189
//first check if this is executing in main thread
190
if ( mainThread == Thread.currentThread() )
191
{
192
//Still in the main thread, so set the flag just for kicks,
193
// and throw a test passed exception which will be caught
194
// and end the test.
195
theTestPassed = true;
196
throw new TestPassedException();
197
}
198
theTestPassed = true;
199
testGeneratedInterrupt = true;
200
mainThread.interrupt();
201
}//pass()
202
203
public static synchronized void fail()
204
{
205
//test writer didn't specify why test failed, so give generic
206
fail( "it just plain failed! :-)" );
207
}
208
209
public static synchronized void fail( String whyFailed )
210
{
211
System.out.println( "The test failed: " + whyFailed );
212
System.out.println( "The test is over, hit Ctl-C to stop Java VM" );
213
//check if this called from main thread
214
if ( mainThread == Thread.currentThread() )
215
{
216
//If main thread, fail now 'cause not sleeping
217
throw new RuntimeException( whyFailed );
218
}
219
theTestPassed = false;
220
testGeneratedInterrupt = true;
221
failureMessage = whyFailed;
222
mainThread.interrupt();
223
}//fail()
224
225
}// class LWComboBox
226
227
//This exception is used to exit from any level of call nesting
228
// when it's determined that the test has passed, and immediately
229
// end the test.
230
class TestPassedException extends RuntimeException
231
{
232
}
233
234