Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JPopupMenu/6800513/bug6800513.java
41153 views
1
/*
2
* Copyright 2012 Red Hat, Inc. All Rights Reserved.
3
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
*
6
* This code is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License version 2 only, as
8
* published by the Free Software Foundation.
9
*
10
* This code is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
* version 2 for more details (a copy is included in the LICENSE file that
14
* accompanied this code).
15
*
16
* You should have received a copy of the GNU General Public License version
17
* 2 along with this work; if not, write to the Free Software Foundation,
18
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
*
20
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21
* or visit www.oracle.com if you need additional information or have any
22
* questions.
23
*/
24
25
/*
26
* @test
27
* @key headful
28
* @bug 6800513
29
* @summary GTK-LaF renders menus incompletely
30
* @author Mario Torre
31
* @modules java.desktop/javax.swing:open
32
* @library ../../regtesthelpers/
33
* @build Util
34
* @run main bug6800513
35
*/
36
37
import javax.swing.*;
38
import java.awt.*;
39
import java.awt.event.InputEvent;
40
import java.beans.PropertyChangeEvent;
41
import java.beans.PropertyChangeListener;
42
import java.lang.reflect.Field;
43
import java.util.concurrent.Callable;
44
45
public class bug6800513 {
46
47
private static JPopupMenu popupMenu;
48
private static JMenu menu;
49
private static JFrame frame;
50
private static Robot robot;
51
52
public static void testFrame(final boolean defaultLightWeightPopupEnabled,
53
String expectedPopupClass) throws Exception {
54
55
SwingUtilities.invokeAndWait(new Runnable() {
56
public void run() {
57
JPopupMenu.setDefaultLightWeightPopupEnabled(defaultLightWeightPopupEnabled);
58
createAndShowUI();
59
}
60
});
61
62
robot.waitForIdle();
63
64
clickOnMenu();
65
66
robot.waitForIdle();
67
68
Field getPopup = JPopupMenu.class.getDeclaredField("popup");
69
getPopup.setAccessible(true);
70
Popup popup = (Popup) getPopup.get(popupMenu);
71
72
if (popup == null) {
73
throw new Exception("popup is null!");
74
}
75
76
String className = popup.getClass().getName();
77
if (!className.equals(expectedPopupClass)) {
78
throw new Exception("popup class is: " + className +
79
", expected: " + expectedPopupClass);
80
}
81
82
SwingUtilities.invokeAndWait(new Runnable() {
83
@Override
84
public void run() {
85
frame.dispose();
86
popupMenu = null;
87
}
88
});
89
90
robot.waitForIdle();
91
}
92
93
94
public static void clickOnMenu() throws Exception {
95
Rectangle bounds = Util.invokeOnEDT(new Callable<Rectangle>() {
96
@Override
97
public Rectangle call() throws Exception {
98
return new Rectangle(menu.getLocationOnScreen(), menu.getSize());
99
}
100
});
101
102
robot.setAutoDelay(100);
103
104
robot.mouseMove(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
105
106
robot.mousePress(InputEvent.BUTTON1_MASK);
107
robot.mouseRelease(InputEvent.BUTTON1_MASK);
108
}
109
110
private static class PopupListener implements PropertyChangeListener {
111
@Override
112
public void propertyChange(PropertyChangeEvent evt) {
113
if (evt.toString().contains("visible") && ((Boolean) evt.getNewValue() == true)) {
114
popupMenu = (JPopupMenu) evt.getSource();
115
}
116
}
117
}
118
119
public static void createAndShowUI() {
120
frame = new JFrame();
121
122
JMenuBar menuBar = new JMenuBar();
123
menu = new JMenu("Menu");
124
125
menu.add(new JMenuItem("Menu Item #1"));
126
menu.add(new JMenuItem("Menu Item #2"));
127
menu.add(new JMenuItem("Menu Item #3"));
128
129
menuBar.add(menu);
130
131
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
132
frame.setJMenuBar(menuBar);
133
frame.setSize(500, 500);
134
frame.setLocationRelativeTo(null);
135
136
PopupListener listener = new PopupListener();
137
menu.getPopupMenu().addPropertyChangeListener(listener);
138
139
frame.setVisible(true);
140
}
141
142
public static void main(String[] args) throws Exception {
143
robot = new Robot();
144
testFrame(false, "javax.swing.PopupFactory$HeavyWeightPopup");
145
146
testFrame(true, "javax.swing.PopupFactory$LightWeightPopup");
147
}
148
}
149
150