Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Component/CompEventOnHiddenComponent/CompEventOnHiddenComponent.java
41155 views
1
/*
2
* Copyright (c) 2006, 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. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
/*
27
@test
28
@key headful
29
@bug 6383903 8144166
30
@summary REGRESSION: componentMoved is now getting called for some hidden components
31
@author andrei.dmitriev: area=awt.component
32
@run main CompEventOnHiddenComponent
33
*/
34
35
import java.awt.*;
36
import java.awt.event.*;
37
import javax.swing.*;
38
39
public class CompEventOnHiddenComponent
40
{
41
transient static boolean moved = false;
42
transient static boolean resized = false;
43
44
transient static boolean ancestor_moved = false;
45
transient static boolean ancestor_resized = false;
46
static String passed = "";
47
48
private static void init()
49
{
50
Robot robot;
51
try {
52
robot = new Robot();
53
}catch(Exception ex) {
54
ex.printStackTrace();
55
throw new RuntimeException("Unexpected failure");
56
}
57
58
EventQueue.invokeLater(new Runnable(){
59
public void run(){
60
JFrame f = new JFrame("JFrame");
61
JButton b = new JButton("JButton");
62
f.add(b);
63
new JOptionPane().
64
createInternalFrame(b, "Test").
65
addComponentListener(new ComponentAdapter() {
66
public void componentMoved(ComponentEvent e) {
67
moved = true;
68
System.out.println(e);
69
}
70
public void componentResized(ComponentEvent e) {
71
resized = true;
72
System.out.println(e);
73
}
74
});
75
}
76
});
77
78
robot.waitForIdle();
79
80
if (moved || resized){
81
passed = "Hidden component got COMPONENT_MOVED or COMPONENT_RESIZED event";
82
} else {
83
System.out.println("Stage 1 passed.");
84
}
85
86
EventQueue.invokeLater(new Runnable() {
87
public void run() {
88
JFrame parentWindow = new JFrame("JFrame 1");
89
JButton component = new JButton("JButton 1");;
90
JButton smallButton = new JButton("Small Button");
91
92
93
smallButton.addHierarchyBoundsListener(new HierarchyBoundsAdapter() {
94
public void ancestorMoved(HierarchyEvent e) {
95
ancestor_moved = true;
96
System.out.println("SMALL COMPONENT >>>>>"+e);
97
}
98
public void ancestorResized(HierarchyEvent e) {
99
ancestor_resized = true;
100
System.out.println("SMALL COMPONENT >>>>>"+e);
101
}
102
});
103
104
105
parentWindow.add(component);
106
component.add(smallButton);
107
108
component.setSize(100, 100);
109
component.setLocation(100, 100);
110
111
}
112
});
113
114
robot.waitForIdle();
115
116
if (!ancestor_resized || !ancestor_moved){
117
passed = "Hidden component didn't get ANCESTOR event";
118
} else {
119
System.out.println("Stage 2 passed.");
120
}
121
122
robot.waitForIdle();
123
124
if (passed.equals("")){
125
CompEventOnHiddenComponent.pass();
126
} else {
127
CompEventOnHiddenComponent.fail(passed);
128
}
129
130
}//End init()
131
132
133
134
/*****************************************************
135
* Standard Test Machinery Section
136
* DO NOT modify anything in this section -- it's a
137
* standard chunk of code which has all of the
138
* synchronisation necessary for the test harness.
139
* By keeping it the same in all tests, it is easier
140
* to read and understand someone else's test, as
141
* well as insuring that all tests behave correctly
142
* with the test harness.
143
* There is a section following this for test-
144
* classes
145
******************************************************/
146
private static boolean theTestPassed = false;
147
private static boolean testGeneratedInterrupt = false;
148
private static String failureMessage = "";
149
150
private static Thread mainThread = null;
151
152
private static int sleepTime = 300000;
153
154
// Not sure about what happens if multiple of this test are
155
// instantiated in the same VM. Being static (and using
156
// static vars), it aint gonna work. Not worrying about
157
// it for now.
158
public static void main( String args[] ) throws InterruptedException
159
{
160
mainThread = Thread.currentThread();
161
try
162
{
163
init();
164
}
165
catch( TestPassedException e )
166
{
167
//The test passed, so just return from main and harness will
168
// interepret this return as a pass
169
return;
170
}
171
//At this point, neither test pass nor test fail has been
172
// called -- either would have thrown an exception and ended the
173
// test, so we know we have multiple threads.
174
175
//Test involves other threads, so sleep and wait for them to
176
// called pass() or fail()
177
try
178
{
179
Thread.sleep( sleepTime );
180
//Timed out, so fail the test
181
throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
182
}
183
catch (InterruptedException e)
184
{
185
//The test harness may have interrupted the test. If so, rethrow the exception
186
// so that the harness gets it and deals with it.
187
if( ! testGeneratedInterrupt ) throw e;
188
189
//reset flag in case hit this code more than once for some reason (just safety)
190
testGeneratedInterrupt = false;
191
192
if ( theTestPassed == false )
193
{
194
throw new RuntimeException( failureMessage );
195
}
196
}
197
198
}//main
199
200
public static synchronized void setTimeoutTo( int seconds )
201
{
202
sleepTime = seconds * 1000;
203
}
204
205
public static synchronized void pass()
206
{
207
System.out.println( "The test passed." );
208
System.out.println( "The test is over, hit Ctl-C to stop Java VM" );
209
//first check if this is executing in main thread
210
if ( mainThread == Thread.currentThread() )
211
{
212
//Still in the main thread, so set the flag just for kicks,
213
// and throw a test passed exception which will be caught
214
// and end the test.
215
theTestPassed = true;
216
throw new TestPassedException();
217
}
218
theTestPassed = true;
219
testGeneratedInterrupt = true;
220
mainThread.interrupt();
221
}//pass()
222
223
public static synchronized void fail()
224
{
225
//test writer didn't specify why test failed, so give generic
226
fail( "it just plain failed! :-)" );
227
}
228
229
public static synchronized void fail( String whyFailed )
230
{
231
System.out.println( "The test failed: " + whyFailed );
232
System.out.println( "The test is over, hit Ctl-C to stop Java VM" );
233
//check if this called from main thread
234
if ( mainThread == Thread.currentThread() )
235
{
236
//If main thread, fail now 'cause not sleeping
237
throw new RuntimeException( whyFailed );
238
}
239
theTestPassed = false;
240
testGeneratedInterrupt = true;
241
failureMessage = whyFailed;
242
mainThread.interrupt();
243
}//fail()
244
245
}// class CompEventOnHiddenComponent
246
247
//This exception is used to exit from any level of call nesting
248
// when it's determined that the test has passed, and immediately
249
// end the test.
250
class TestPassedException extends RuntimeException
251
{
252
}
253
254
//*********** End Standard Test Machinery Section **********
255
256