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