Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Focus/ModalDialogActivationTest/ModalDialogActivationTest.java
41152 views
1
/*
2
* Copyright (c) 2016, 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
import java.awt.EventQueue;
27
import java.awt.Frame;
28
import java.awt.event.WindowAdapter;
29
import java.awt.event.WindowEvent;
30
import javax.swing.JDialog;
31
import javax.swing.JFrame;
32
33
/*
34
@test
35
@key headful
36
@bug 8160570 8166015
37
@summary Tests that a modal dialog receives WINDOW_ACTIVATED
38
& WINDOW_GAINED_FOCUS on first show.
39
*/
40
41
public class ModalDialogActivationTest {
42
static final Object lock = new Object();
43
static volatile boolean activated;
44
static volatile boolean focused;
45
46
public static void main(String[] args) throws InterruptedException {
47
EventQueue.invokeLater(() -> runGUI());
48
49
long time = System.currentTimeMillis();
50
synchronized (lock) {
51
while (!activated || !focused) {
52
lock.wait(5000);
53
if (System.currentTimeMillis() - time >= 5000) break;
54
}
55
}
56
if (!activated || !focused) {
57
throw new RuntimeException("Test FAILED: activated: " + activated
58
+ ", focused: " + focused);
59
}
60
System.out.println("Test PASSED");
61
}
62
63
static void runGUI() {
64
JFrame f = new JFrame("frame");
65
final JDialog d = new MyModalDialog(f, "dialog");
66
d.addWindowListener(new WindowAdapter() {
67
@Override
68
public void windowActivated(WindowEvent e) {
69
synchronized (lock) {
70
activated = true;
71
lock.notifyAll();
72
}
73
}
74
});
75
d.addWindowFocusListener(new WindowAdapter() {
76
@Override
77
public void windowGainedFocus(WindowEvent e) {
78
synchronized (lock) {
79
focused = true;
80
lock.notifyAll();
81
}
82
}
83
});
84
f.setVisible(true);
85
d.setVisible(true);
86
}
87
88
static class MyModalDialog extends JDialog {
89
public MyModalDialog(Frame owner, String title) {
90
super(owner, title, true);
91
}
92
93
@Override
94
public boolean getFocusableWindowState() {
95
try {
96
// let Toolkit thread go ahead
97
Thread.sleep(100);
98
} catch (InterruptedException ignore) {
99
}
100
return super.getFocusableWindowState();
101
}
102
}
103
}
104
105