Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JInternalFrame/6288609/TestJInternalFrameDispose.java
41153 views
1
/*
2
* Copyright (c) 2015, 2017, 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 6288609
28
* @summary JInternalFrame.setDefaultCloseOperation() interferes with "close"
29
behavior
30
* @library ../../regtesthelpers
31
* @build Util
32
* @run main TestJInternalFrameDispose
33
*/
34
35
import java.awt.Point;
36
import java.awt.Robot;
37
import java.awt.event.ActionEvent;
38
import java.awt.event.ActionListener;
39
import java.awt.event.InputEvent;
40
import javax.swing.JFrame;
41
import javax.swing.JDesktopPane;
42
import javax.swing.JMenu;
43
import javax.swing.JMenuBar;
44
import javax.swing.JMenuItem;
45
import javax.swing.JInternalFrame;
46
import javax.swing.SwingUtilities;
47
import javax.swing.event.InternalFrameAdapter;
48
import javax.swing.event.InternalFrameEvent;
49
50
public class TestJInternalFrameDispose {
51
52
private static JDesktopPane desktopPane;
53
private static JFrame frame = new JFrame("Test Frame");
54
private static int count = 0;
55
private static JMenu menu;
56
private static JMenuBar menuBar;
57
private static JMenuItem menuItem;
58
private static Robot robot;
59
private static JInternalFrame internalFrame;
60
61
public static void main(String[] args) throws Exception {
62
robot = new Robot();
63
SwingUtilities.invokeAndWait(new Runnable() {
64
@Override
65
public void run() {
66
createUI();
67
}
68
});
69
70
robot.waitForIdle();
71
executeTest();
72
robot.delay(1000);
73
dispose();
74
}
75
76
private static void createUI() {
77
78
desktopPane = new JDesktopPane();
79
frame.getContentPane().add(desktopPane);
80
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
81
82
menuBar = new JMenuBar();
83
frame.setJMenuBar(menuBar);
84
85
menu = new JMenu("File");
86
menuBar.add(menu);
87
88
menuItem = new JMenuItem("New Child");
89
menuItem.addActionListener(
90
new ActionListener() {
91
@Override
92
public void actionPerformed(ActionEvent e) {
93
JInternalFrame f = new JInternalFrame("Child "
94
+ (++count), true, true, true, true);
95
f.setDefaultCloseOperation(
96
JInternalFrame.DO_NOTHING_ON_CLOSE);
97
f.addInternalFrameListener(new InternalFrameAdapter() {
98
@Override
99
public void internalFrameClosing(
100
InternalFrameEvent e) {
101
e.getInternalFrame().dispose();
102
}
103
});
104
f.setSize(200, 300);
105
f.setLocation(count * 20, count * 20);
106
desktopPane.add(f);
107
f.setVisible(true);
108
}
109
});
110
menu.add(menuItem);
111
112
frame.setSize(400, 500);
113
frame.setLocationRelativeTo(null);
114
frame.setVisible(true);
115
}
116
117
private static void executeTest() throws Exception {
118
119
Point point = Util.getCenterPoint(menu);
120
performMouseOperations(point);
121
point = Util.getCenterPoint(menuItem);
122
performMouseOperations(point);
123
point = Util.getCenterPoint(menu);
124
performMouseOperations(point);
125
point = Util.getCenterPoint(menuItem);
126
performMouseOperations(point);
127
SwingUtilities.invokeAndWait(new Runnable() {
128
129
@Override
130
public void run() {
131
internalFrame = desktopPane.getSelectedFrame();
132
internalFrame.doDefaultCloseAction();
133
internalFrame = desktopPane.getSelectedFrame();
134
}
135
});
136
137
robot.delay(2000);
138
if (internalFrame == null) {
139
dispose();
140
throw new RuntimeException("Test Failed");
141
}
142
}
143
144
private static void dispose() throws Exception {
145
SwingUtilities.invokeAndWait(new Runnable() {
146
147
@Override
148
public void run() {
149
frame.dispose();
150
}
151
});
152
}
153
154
private static void performMouseOperations(Point point) {
155
robot.mouseMove(point.x, point.y);
156
robot.mousePress(InputEvent.BUTTON1_MASK);
157
robot.mouseRelease(InputEvent.BUTTON1_MASK);
158
robot.delay(1000);
159
robot.waitForIdle();
160
}
161
}
162
163