Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Mixing/MixingInHwPanel.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
26
@key headful
27
@bug 6829858
28
@summary Mixing should work inside heavyweight containers
29
@author [email protected]: area=awt.mixing
30
@library ../regtesthelpers
31
@build Util
32
@run main MixingInHwPanel
33
*/
34
35
36
/**
37
* MixingInHwPanel.java
38
*
39
* summary: Mixing should work inside heavyweight containers
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 MixingInHwPanel
50
{
51
static volatile boolean failed = true;
52
53
private static void init()
54
{
55
// Create the components: frame -> hwPanel -> JDesktopPane ->
56
// -> JInternalFrame -> hwButton
57
Frame frame = new Frame("Mixing in a heavyweight Panel");
58
frame.setBounds(100, 100, 640, 480);
59
60
Panel hwPanel = new Panel(new BorderLayout());
61
frame.add(hwPanel);
62
63
JDesktopPane desktop = new JDesktopPane();
64
hwPanel.add(desktop);
65
66
JInternalFrame iFrame = new JInternalFrame("one",
67
true, true, true, true);
68
iFrame.setPreferredSize(new Dimension(150, 55));
69
iFrame.setBounds(600, 100, 150, 55);
70
iFrame.setVisible(true);
71
desktop.add(iFrame);
72
73
Button button = new Button("HW Button");
74
button.addActionListener(new ActionListener() {
75
public void actionPerformed(ActionEvent e) {
76
failed = false;
77
}
78
});
79
iFrame.add(button);
80
81
// Show the frame with the hwButton slightly hidden initially
82
frame.setVisible(true);
83
84
Robot robot = Util.createRobot();
85
robot.setAutoDelay(20);
86
87
Util.waitForIdle(robot);
88
89
// Now resize the frame so that the button is fully visible
90
frame.setBounds(100, 100, 800, 480);
91
frame.validate();
92
93
Util.waitForIdle(robot);
94
95
// And click the part of the button that has been previously hidden
96
Point bLoc = button.getLocationOnScreen();
97
robot.mouseMove(bLoc.x + button.getWidth() - 15, bLoc.y + button.getHeight() / 2);
98
99
Util.waitForIdle(robot);
100
101
robot.mousePress(InputEvent.BUTTON1_MASK);
102
robot.mouseRelease(InputEvent.BUTTON1_MASK);
103
104
Util.waitForIdle(robot);
105
106
// If the click happens (the shape is reapplied), the button's action
107
// listener will make failed == false.
108
if (failed) {
109
MixingInHwPanel.fail("The HW button did not receive the click.");
110
} else {
111
MixingInHwPanel.pass();
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 MixingInHwPanel
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