Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Dialog/MakeWindowAlwaysOnTop/MakeWindowAlwaysOnTop.java
38828 views
1
/*
2
* Copyright (c) 2010, 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 6829546
27
@summary tests that an always-on-top modal dialog doesn't make any windows always-on-top
28
@author artem.ananiev: area=awt.modal
29
@library ../../regtesthelpers
30
@build Util
31
@run main MakeWindowAlwaysOnTop
32
*/
33
34
import java.awt.*;
35
import java.awt.event.*;
36
37
import test.java.awt.regtesthelpers.Util;
38
39
public class MakeWindowAlwaysOnTop
40
{
41
private static Frame f;
42
private static Dialog d;
43
44
public static void main(String[] args) throws Exception
45
{
46
Robot r = Util.createRobot();
47
Util.waitForIdle(r);
48
49
// Frame
50
f = new Frame("Test frame");
51
f.setBounds(100, 100, 400, 300);
52
f.setBackground(Color.RED);
53
f.setVisible(true);
54
r.delay(100);
55
Util.waitForIdle(r);
56
57
// Dialog
58
d = new Dialog(null, "Modal dialog", Dialog.ModalityType.APPLICATION_MODAL);
59
d.setBounds(500, 500, 160, 160);
60
d.setAlwaysOnTop(true);
61
EventQueue.invokeLater(new Runnable()
62
{
63
public void run()
64
{
65
d.setVisible(true);
66
}
67
});
68
// Wait until the dialog is shown
69
EventQueue.invokeAndWait(new Runnable()
70
{
71
public void run()
72
{
73
// Empty
74
}
75
});
76
r.delay(100);
77
Util.waitForIdle(r);
78
79
// Click on the frame to trigger modality
80
Point p = f.getLocationOnScreen();
81
r.mouseMove(p.x + f.getWidth() / 2, p.y + f.getHeight() / 2);
82
Util.waitForIdle(r);
83
r.mousePress(InputEvent.BUTTON1_MASK);
84
Util.waitForIdle(r);
85
r.mouseRelease(InputEvent.BUTTON1_MASK);
86
Util.waitForIdle(r);
87
88
r.delay(100);
89
Util.waitForIdle(r);
90
91
// Dispose dialog
92
d.dispose();
93
r.delay(100);
94
Util.waitForIdle(r);
95
96
// Show another frame at the same location
97
Frame t = new Frame("Check");
98
t.setBounds(100, 100, 400, 300);
99
t.setBackground(Color.BLUE);
100
t.setVisible(true);
101
r.delay(100);
102
Util.waitForIdle(r);
103
104
// Bring it above the first frame
105
t.toFront();
106
r.delay(100);
107
Util.waitForIdle(r);
108
109
Color c = r.getPixelColor(p.x + f.getWidth() / 2, p.y + f.getHeight() / 2);
110
System.out.println("Color = " + c);
111
System.out.flush();
112
// If the color is RED, then the first frame is now always-on-top
113
if (Color.RED.equals(c))
114
{
115
throw new RuntimeException("Test FAILED: the frame is always-on-top");
116
}
117
else if (!Color.BLUE.equals(c))
118
{
119
throw new RuntimeException("Test FAILED: unknown window is on top of the frame");
120
}
121
else
122
{
123
System.out.println("Test PASSED");
124
System.out.flush();
125
}
126
127
// Dispose all the windows
128
t.dispose();
129
f.dispose();
130
}
131
}
132
133