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