Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JInternalFrame/8145896/TestJInternalFrameMaximize.java
41154 views
1
/*
2
* Copyright (c) 2016, 2019, 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 8145896 8194944
28
* @summary JInternalFrame setMaximum before adding to desktop throws null pointer exception
29
* @library ../../regtesthelpers
30
* @build Util
31
* @run main TestJInternalFrameMaximize
32
*/
33
34
import java.awt.Point;
35
import java.awt.Robot;
36
import java.awt.event.ActionEvent;
37
import java.awt.event.InputEvent;
38
import java.beans.PropertyVetoException;
39
import javax.swing.JFrame;
40
import javax.swing.JDesktopPane;
41
import javax.swing.JMenu;
42
import javax.swing.JMenuBar;
43
import javax.swing.JMenuItem;
44
import javax.swing.JInternalFrame;
45
import javax.swing.SwingUtilities;
46
import javax.swing.UIManager;
47
import javax.swing.UnsupportedLookAndFeelException;
48
49
public class TestJInternalFrameMaximize {
50
51
private static JDesktopPane desktopPane;
52
private static JFrame frame;
53
private static int count = 0;
54
private static JMenu menu;
55
private static JMenuBar menuBar;
56
private static JMenuItem menuItem;
57
private static Robot robot;
58
private static volatile String errorMessage = "";
59
private static volatile boolean isFrameShowing;
60
61
public static void main(String[] args) throws Exception {
62
robot = new Robot();
63
robot.setAutoDelay(100);
64
UIManager.LookAndFeelInfo[] lookAndFeelArray
65
= UIManager.getInstalledLookAndFeels();
66
for (UIManager.LookAndFeelInfo lookAndFeelItem : lookAndFeelArray) {
67
try {
68
String lookAndFeelString = lookAndFeelItem.getClassName();
69
if (tryLookAndFeel(lookAndFeelString)) {
70
createUI();
71
robot.waitForIdle();
72
blockTillDisplayed(frame);
73
executeTest();
74
robot.delay(1000);
75
}
76
} finally {
77
frame.dispose();
78
isFrameShowing = false;
79
robot.waitForIdle();
80
}
81
}
82
if (!"".equals(errorMessage)) {
83
throw new RuntimeException(errorMessage);
84
}
85
}
86
87
private static boolean tryLookAndFeel(String lookAndFeelString) {
88
try {
89
UIManager.setLookAndFeel(lookAndFeelString);
90
return true;
91
} catch (UnsupportedLookAndFeelException | ClassNotFoundException |
92
InstantiationException | IllegalAccessException e) {
93
errorMessage += e.getMessage() + "\n";
94
System.err.println("Caught Exception: " + e.getMessage());
95
return false;
96
}
97
}
98
99
private static void createUI() throws Exception {
100
101
SwingUtilities.invokeAndWait(() -> {
102
frame = new JFrame("Test Frame");
103
desktopPane = new JDesktopPane();
104
frame.getContentPane().add(desktopPane);
105
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
106
107
menuBar = new JMenuBar();
108
frame.setJMenuBar(menuBar);
109
110
menu = new JMenu("File");
111
menuBar.add(menu);
112
113
menuItem = new JMenuItem("New Child");
114
menuItem.addActionListener((ActionEvent e) -> {
115
try {
116
JInternalFrame f = new JInternalFrame("Child "
117
+ (++count), true, true, true, true);
118
f.setSize(200, 300);
119
f.setLocation(count * 20, count * 20);
120
f.setMaximum(true);
121
desktopPane.add(f);
122
f.setVisible(true);
123
} catch (PropertyVetoException ex) {
124
} catch (RuntimeException ex) {
125
errorMessage = "Test Failed";
126
}
127
});
128
menu.add(menuItem);
129
frame.setSize(500, 500);
130
frame.setLocationRelativeTo(null);
131
frame.setVisible(true);
132
});
133
}
134
135
private static void blockTillDisplayed(JFrame frame) throws Exception {
136
while (!isFrameShowing) {
137
try {
138
SwingUtilities.invokeAndWait(()-> isFrameShowing = frame.isShowing());
139
if (!isFrameShowing) {
140
Thread.sleep(1000);
141
}
142
} catch (InterruptedException ex) {
143
} catch (Exception ex) {
144
throw new RuntimeException(ex);
145
}
146
}
147
}
148
149
private static void executeTest() throws Exception {
150
Point point = Util.getCenterPoint(menu);
151
performMouseOperations(point);
152
point = Util.getCenterPoint(menuItem);
153
performMouseOperations(point);
154
}
155
156
private static void performMouseOperations(Point point) {
157
robot.mouseMove(point.x, point.y);
158
robot.mousePress(InputEvent.BUTTON1_MASK);
159
robot.mouseRelease(InputEvent.BUTTON1_MASK);
160
robot.delay(1000);
161
robot.waitForIdle();
162
}
163
}
164
165