Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Focus/DisposedWindow/DisposeDialogNotActivateOwnerTest/DisposeDialogNotActivateOwnerTest.java
41154 views
1
/*
2
* Copyright (c) 2006, 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.
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
@key headful
27
@bug 6386592 8160766
28
@summary Tests that disposing a dialog doesn't activate its invisible owner.
29
*/
30
31
import java.awt.AWTException;
32
import java.awt.Button;
33
import java.awt.Component;
34
import java.awt.Dialog;
35
import java.awt.Dimension;
36
import java.awt.Frame;
37
import java.awt.Point;
38
import java.awt.Robot;
39
import java.awt.event.FocusAdapter;
40
import java.awt.event.FocusEvent;
41
import java.awt.event.InputEvent;
42
43
public class DisposeDialogNotActivateOwnerTest {
44
Robot robot;
45
Frame frame;
46
Frame dialogInvisibleOwner;
47
Dialog dialog;
48
Button frameButton;
49
static volatile boolean buttonReceivedFocus = false;
50
51
public static void main(String[] args) {
52
DisposeDialogNotActivateOwnerTest test =
53
new DisposeDialogNotActivateOwnerTest();
54
test.performTest();
55
test.dispose();
56
}
57
58
public DisposeDialogNotActivateOwnerTest() {
59
try {
60
robot = new Robot();
61
} catch (AWTException e) {
62
throw new RuntimeException("Error: unable to create robot");
63
}
64
65
robot.setAutoDelay(200);
66
dialogInvisibleOwner = new Frame("Dialog Invisible Owner Frame");
67
dialog = new Dialog(dialogInvisibleOwner, "Owned Dialog");
68
69
frame = new Frame("A Frame");
70
frameButton = new Button("button");
71
frameButton.addFocusListener(new FocusAdapter() {
72
public void focusGained(FocusEvent e) {
73
buttonReceivedFocus = true;
74
}
75
});
76
frame.setBounds(0, 0, 400, 200);
77
frame.add(frameButton);
78
dialog.setBounds(100, 50, 200, 100);
79
}
80
81
public void performTest() {
82
frame.setVisible(true);
83
robot.delay(200);
84
robot.waitForIdle();
85
clickOnTitle(frame);
86
robot.delay(200);
87
robot.waitForIdle();
88
robot.delay(200);
89
if (!frame.isFocused()) {
90
dispose();
91
throw new RuntimeException("Error: frame didn't get initial focus");
92
}
93
94
dialog.setVisible(true);
95
robot.delay(200);
96
robot.waitForIdle();
97
robot.delay(200);
98
if (!dialog.isFocused()) {
99
dispose();
100
throw new RuntimeException("Error: dialog didn't get initial focus");
101
}
102
103
dialog.dispose();
104
robot.waitForIdle();
105
robot.delay(200);
106
if (!buttonReceivedFocus) {
107
dispose();
108
throw new RuntimeException(
109
"Test failed: Dialog activates invisible owner when disposed!");
110
}
111
}
112
113
public void dispose() {
114
frame.dispose();
115
dialog.dispose();
116
dialogInvisibleOwner.dispose();
117
}
118
119
void clickOnTitle(Component c) {
120
Point p = c.getLocationOnScreen();
121
Dimension d = c.getSize();
122
robot.mouseMove(p.x + (int)(d.getWidth() / 2),
123
p.y + ((Frame)c).getInsets().top / 2);
124
robot.mousePress(InputEvent.BUTTON1_MASK);
125
robot.mouseRelease(InputEvent.BUTTON1_MASK);
126
}
127
}
128
129