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