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