Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JPopupMenu/6580930/bug6580930.java
38918 views
1
/*
2
* Copyright (c) 2007, 2014, 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
@test
25
@bug 6580930 7184956
26
@summary Swing Popups should overlap taskbar
27
@author Alexander Potochkin
28
@library ../../../../lib/testlibrary
29
@build ExtendedRobot
30
@run main bug6580930
31
*/
32
33
import javax.swing.*;
34
import java.awt.*;
35
import java.awt.event.InputEvent;
36
import java.awt.event.KeyEvent;
37
38
public class bug6580930 {
39
private static ExtendedRobot robot;
40
private static JFrame frame;
41
private static JPopupMenu popup;
42
private static Toolkit toolkit;
43
private static volatile boolean skipTest = false;
44
45
private static void createGui() {
46
frame = new JFrame();
47
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
48
frame.setUndecorated(true);
49
50
popup = new JPopupMenu("Menu");
51
for (int i = 0; i < 7; i++) {
52
popup.add(new JMenuItem("MenuItem"));
53
}
54
JPanel panel = new JPanel();
55
panel.setComponentPopupMenu(popup);
56
frame.add(panel);
57
58
frame.setSize(200, 200);
59
}
60
61
62
public static void main(String[] args) throws Exception {
63
SwingUtilities.invokeAndWait(new Runnable() {
64
public void run() {
65
JPopupMenu.setDefaultLightWeightPopupEnabled(true);
66
bug6580930.createGui();
67
}
68
});
69
70
toolkit = Toolkit.getDefaultToolkit();
71
robot = new ExtendedRobot();
72
robot.setAutoDelay(10);
73
robot.waitForIdle();
74
75
SwingUtilities.invokeAndWait(new Runnable() {
76
public void run() {
77
Insets insets = toolkit.getScreenInsets(frame.getGraphicsConfiguration());
78
if (insets.bottom == 0) {
79
System.out.println("This test is only for configurations with taskbar on the bottom");
80
81
skipTest = true;
82
}
83
84
Dimension screenSize = toolkit.getScreenSize();
85
frame.setLocation(screenSize.width/2, screenSize.height - frame.getHeight() - insets.bottom + 10);
86
frame.setVisible(true);
87
}
88
});
89
90
robot.waitForIdle();
91
92
if(skipTest) {
93
return;
94
}
95
Point loc = frame.getLocationOnScreen();
96
97
robot.mouseMove(loc.x, loc.y);
98
showPopup();
99
robot.waitForIdle();
100
if (isHeavyWeightMenuVisible()) {
101
throw new RuntimeException("HeavyWeightPopup is unexpectedly visible");
102
}
103
104
robot.keyPress(KeyEvent.VK_ESCAPE);
105
robot.keyRelease(KeyEvent.VK_ESCAPE);
106
107
int x = loc.x;
108
int y = loc.y + (frame.getHeight() - popup.getPreferredSize().height) + 1;
109
robot.mouseMove(x, y);
110
111
showPopup();
112
113
if (!popup.getLocationOnScreen().equals(new Point(x, y))) {
114
throw new RuntimeException("Popup is unexpectedly shifted");
115
}
116
117
if (!isHeavyWeightMenuVisible()) {
118
throw new RuntimeException("HeavyWeightPopup is unexpectedly hidden");
119
}
120
}
121
122
private static void showPopup() {
123
robot.mousePress(InputEvent.BUTTON1_MASK);
124
robot.mouseRelease(InputEvent.BUTTON1_MASK);
125
robot.waitForIdle();
126
if (!popup.isShowing()) {
127
robot.mousePress(InputEvent.BUTTON2_MASK);
128
robot.mouseRelease(InputEvent.BUTTON2_MASK);
129
robot.waitForIdle();
130
if (!popup.isShowing()) {
131
robot.mousePress(InputEvent.BUTTON3_MASK);
132
robot.mouseRelease(InputEvent.BUTTON3_MASK);
133
robot.waitForIdle();
134
}
135
}
136
}
137
138
private static boolean isHeavyWeightMenuVisible() {
139
Window[] windows = Window.getWindows();
140
for (Window window : windows) {
141
if (window.getClass().getSimpleName().equals("HeavyWeightWindow")
142
&& window.isVisible()) {
143
return true;
144
}
145
}
146
return false;
147
}
148
}
149
150