Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Modal/WsDisabledStyle/OverBlocker/OverBlocker.java
41159 views
1
/*
2
* Copyright (c) 2007, 2008, 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 %I% %E%
26
@bug 4080029
27
@summary Modal Dialog block input to all frame windows not just its parent.
28
@author dmitry.cherepanov: area=awt.modal
29
@run main/manual OverBlocker
30
*/
31
32
/**
33
* OverBlocker.java
34
*
35
* summary: The test verifies that if user tries to activate the blocked dialog
36
* then the blocker dialog appears over the other windows
37
*/
38
39
import java.awt.*;
40
import java.awt.event.*;
41
42
public class OverBlocker
43
{
44
45
private static void init()
46
{
47
//*** Create instructions for the user here ***
48
49
String[] instructions =
50
{
51
" the test will be run 4 times, to start next test just close all ",
52
" windows of previous; the instructions are the same for all tests: ",
53
" 1) there is a frame with 'show modal' button, ",
54
" 2) press the button to show a dialog, ",
55
" 3) activate any non-Java application, move the app over the dialog, ",
56
" 4) click on the frame by mouse, ",
57
" 5) make sure that the dialog comes up from the application and ",
58
" now the dialog overlaps the app as well as the frame, ",
59
" if it's true, then the test passed, otherwise, it failed. ",
60
" Press 'pass' button only after all of the 4 tests are completed, ",
61
" the number of the currently executed test is displayed on the ",
62
" output window. "
63
};
64
Sysout.createDialog( );
65
Sysout.printInstructions( instructions );
66
67
test(false, true);
68
test(true, true);
69
test(true, false);
70
test(false, false);
71
72
}//End init()
73
74
private static final Object obj = new Object();
75
private static int counter = 0;
76
77
/*
78
* The ownerless parameter indicates whether the blocker dialog
79
* has owner. The usual parameter indicates whether the blocker
80
* dialog is a Java dialog (non-native dialog like file dialog).
81
*/
82
private static void test(final boolean ownerless, final boolean usual) {
83
84
Sysout.print(" * test #" + (++counter) + " is running ... ");
85
86
final Frame frame = new Frame();
87
Button button = new Button("show modal");
88
button.addActionListener(new ActionListener() {
89
public void actionPerformed(ActionEvent ae) {
90
Dialog dialog = null;
91
Frame parent = ownerless ? null : frame;
92
if (usual) {
93
dialog = new Dialog(parent, "Sample", true);
94
} else {
95
dialog = new FileDialog(parent, "Sample", FileDialog.LOAD);
96
}
97
dialog.addWindowListener(new WindowAdapter(){
98
public void windowClosing(WindowEvent e){
99
e.getWindow().dispose();
100
}
101
});
102
dialog.setBounds(200, 200, 200, 200);
103
dialog.setVisible(true);
104
}
105
});
106
frame.add(button);
107
frame.setBounds(400, 400, 200, 200);
108
frame.addWindowListener(new WindowAdapter(){
109
public void windowClosing(WindowEvent e){
110
e.getWindow().dispose();
111
synchronized(obj) {
112
obj.notify();
113
}
114
}
115
});
116
frame.setVisible(true);
117
118
synchronized(obj) {
119
try{
120
obj.wait();
121
} catch(Exception e) {
122
throw new RuntimeException(e);
123
}
124
}
125
126
Sysout.println(" completed. ");
127
128
}
129
130
/*****************************************************
131
* Standard Test Machinery Section
132
* DO NOT modify anything in this section -- it's a
133
* standard chunk of code which has all of the
134
* synchronisation necessary for the test harness.
135
* By keeping it the same in all tests, it is easier
136
* to read and understand someone else's test, as
137
* well as insuring that all tests behave correctly
138
* with the test harness.
139
* There is a section following this for test-defined
140
* classes
141
******************************************************/
142
private static boolean theTestPassed = false;
143
private static boolean testGeneratedInterrupt = false;
144
private static String failureMessage = "";
145
146
private static Thread mainThread = null;
147
148
private static int sleepTime = 300000;
149
150
public static void main( String args[] ) throws InterruptedException
151
{
152
mainThread = Thread.currentThread();
153
try
154
{
155
init();
156
}
157
catch( TestPassedException e )
158
{
159
//The test passed, so just return from main and harness will
160
// interepret this return as a pass
161
return;
162
}
163
//At this point, neither test passed nor test failed has been
164
// called -- either would have thrown an exception and ended the
165
// test, so we know we have multiple threads.
166
167
//Test involves other threads, so sleep and wait for them to
168
// called pass() or fail()
169
try
170
{
171
Thread.sleep( sleepTime );
172
//Timed out, so fail the test
173
throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
174
}
175
catch (InterruptedException e)
176
{
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
if ( theTestPassed == false )
182
{
183
throw new RuntimeException( failureMessage );
184
}
185
}
186
187
}//main
188
189
public static synchronized void setTimeoutTo( int seconds )
190
{
191
sleepTime = seconds * 1000;
192
}
193
194
public static synchronized void pass()
195
{
196
Sysout.println( "The test passed." );
197
Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
198
//first check if this is executing in main thread
199
if ( mainThread == Thread.currentThread() )
200
{
201
//Still in the main thread, so set the flag just for kicks,
202
// and throw a test passed exception which will be caught
203
// and end the test.
204
theTestPassed = true;
205
throw new TestPassedException();
206
}
207
//pass was called from a different thread, so set the flag and interrupt
208
// the main thead.
209
theTestPassed = true;
210
testGeneratedInterrupt = true;
211
mainThread.interrupt();
212
}//pass()
213
214
public static synchronized void fail()
215
{
216
//test writer didn't specify why test failed, so give generic
217
fail( "it just plain failed! :-)" );
218
}
219
220
public static synchronized void fail( String whyFailed )
221
{
222
Sysout.println( "The test failed: " + whyFailed );
223
Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
224
//check if this called from main thread
225
if ( mainThread == Thread.currentThread() )
226
{
227
//If main thread, fail now 'cause not sleeping
228
throw new RuntimeException( whyFailed );
229
}
230
theTestPassed = false;
231
testGeneratedInterrupt = true;
232
failureMessage = whyFailed;
233
mainThread.interrupt();
234
}//fail()
235
236
}// class ManualMainTest
237
238
//This exception is used to exit from any level of call nesting
239
// when it's determined that the test has passed, and immediately
240
// end the test.
241
class TestPassedException extends RuntimeException
242
{
243
}
244
245
//*********** End Standard Test Machinery Section **********
246
247
248
//************ Begin classes defined for the test ****************
249
250
// make listeners in a class defined here, and instantiate them in init()
251
252
/* Example of a class which may be written as part of a test
253
class NewClass implements anInterface
254
{
255
static int newVar = 0;
256
257
public void eventDispatched(AWTEvent e)
258
{
259
//Counting events to see if we get enough
260
eventCount++;
261
262
if( eventCount == 20 )
263
{
264
//got enough events, so pass
265
266
ManualMainTest.pass();
267
}
268
else if( tries == 20 )
269
{
270
//tried too many times without getting enough events so fail
271
272
ManualMainTest.fail();
273
}
274
275
}// eventDispatched()
276
277
}// NewClass class
278
279
*/
280
281
282
//************** End classes defined for the test *******************
283
284
285
286
287
/****************************************************
288
Standard Test Machinery
289
DO NOT modify anything below -- it's a standard
290
chunk of code whose purpose is to make user
291
interaction uniform, and thereby make it simpler
292
to read and understand someone else's test.
293
****************************************************/
294
295
/**
296
This is part of the standard test machinery.
297
It creates a dialog (with the instructions), and is the interface
298
for sending text messages to the user.
299
To print the instructions, send an array of strings to Sysout.createDialog
300
WithInstructions method. Put one line of instructions per array entry.
301
To display a message for the tester to see, simply call Sysout.println
302
with the string to be displayed.
303
This mimics System.out.println but works within the test harness as well
304
as standalone.
305
*/
306
307
class Sysout
308
{
309
private static TestDialog dialog;
310
311
public static void createDialogWithInstructions( String[] instructions )
312
{
313
dialog = new TestDialog( new Frame(), "Instructions" );
314
dialog.printInstructions( instructions );
315
dialog.setVisible(true);
316
println( "Any messages for the tester will display here." );
317
}
318
319
public static void createDialog( )
320
{
321
dialog = new TestDialog( new Frame(), "Instructions" );
322
String[] defInstr = { "Instructions will appear here. ", "" } ;
323
dialog.printInstructions( defInstr );
324
dialog.setVisible(true);
325
println( "Any messages for the tester will display here." );
326
}
327
328
329
public static void printInstructions( String[] instructions )
330
{
331
dialog.printInstructions( instructions );
332
}
333
334
335
public static void println( String messageIn )
336
{
337
dialog.displayMessage( messageIn, true );
338
}
339
340
public static void print( String messageIn )
341
{
342
dialog.displayMessage( messageIn, false );
343
}
344
345
}// Sysout class
346
347
/**
348
This is part of the standard test machinery. It provides a place for the
349
test instructions to be displayed, and a place for interactive messages
350
to the user to be displayed.
351
To have the test instructions displayed, see Sysout.
352
To have a message to the user be displayed, see Sysout.
353
Do not call anything in this dialog directly.
354
*/
355
class TestDialog extends Dialog implements ActionListener
356
{
357
358
TextArea instructionsText;
359
TextArea messageText;
360
int maxStringLength = 80;
361
Panel buttonP = new Panel();
362
Button passB = new Button( "pass" );
363
Button failB = new Button( "fail" );
364
365
//DO NOT call this directly, go through Sysout
366
public TestDialog( Frame frame, String name )
367
{
368
super( frame, name );
369
int scrollBoth = TextArea.SCROLLBARS_BOTH;
370
instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
371
add( "North", instructionsText );
372
373
messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
374
add("Center", messageText);
375
376
passB = new Button( "pass" );
377
passB.setActionCommand( "pass" );
378
passB.addActionListener( this );
379
buttonP.add( "East", passB );
380
381
failB = new Button( "fail" );
382
failB.setActionCommand( "fail" );
383
failB.addActionListener( this );
384
buttonP.add( "West", failB );
385
386
add( "South", buttonP );
387
pack();
388
389
setVisible(true);
390
}// TestDialog()
391
392
//DO NOT call this directly, go through Sysout
393
public void printInstructions( String[] instructions )
394
{
395
//Clear out any current instructions
396
instructionsText.setText( "" );
397
398
//Go down array of instruction strings
399
400
String printStr, remainingStr;
401
for( int i=0; i < instructions.length; i++ )
402
{
403
//chop up each into pieces maxSringLength long
404
remainingStr = instructions[ i ];
405
while( remainingStr.length() > 0 )
406
{
407
//if longer than max then chop off first max chars to print
408
if( remainingStr.length() >= maxStringLength )
409
{
410
//Try to chop on a word boundary
411
int posOfSpace = remainingStr.
412
lastIndexOf( ' ', maxStringLength - 1 );
413
414
if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
415
416
printStr = remainingStr.substring( 0, posOfSpace + 1 );
417
remainingStr = remainingStr.substring( posOfSpace + 1 );
418
}
419
//else just print
420
else
421
{
422
printStr = remainingStr;
423
remainingStr = "";
424
}
425
426
instructionsText.append( printStr + "\n" );
427
428
}// while
429
430
}// for
431
432
}//printInstructions()
433
434
//DO NOT call this directly, go through Sysout
435
public void displayMessage( String messageIn, boolean nextLine )
436
{
437
messageText.append( messageIn + (nextLine? "\n" : "") );
438
System.out.println(messageIn);
439
}
440
441
//catch presses of the passed and failed buttons.
442
//simply call the standard pass() or fail() static methods of
443
//ManualMainTest
444
public void actionPerformed( ActionEvent e )
445
{
446
if( e.getActionCommand() == "pass" )
447
{
448
OverBlocker.pass();
449
}
450
else
451
{
452
OverBlocker.fail();
453
}
454
}
455
456
}// TestDialog class
457
458