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