Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Mouse/EnterExitEvents/ModalDialogEnterExitEventsTest.java
41153 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 8050478
28
* @summary Cursor not updating correctly after closing a modal dialog.
29
* The root cause of the issue was the lack of a mouse exit event
30
* during displaying of a modal dialog.
31
* @author Dmitry Markov
32
* @library ../../regtesthelpers
33
* @build Util
34
* @run main ModalDialogEnterExitEventsTest
35
*/
36
37
import javax.swing.JButton;
38
import javax.swing.JDialog;
39
import javax.swing.JFrame;
40
import javax.swing.SwingUtilities;
41
import java.awt.FlowLayout;
42
import java.awt.Frame;
43
import java.awt.Robot;
44
import java.awt.event.ActionEvent;
45
import java.awt.event.ActionListener;
46
import java.awt.event.MouseAdapter;
47
import java.awt.event.MouseEvent;
48
import java.util.concurrent.atomic.AtomicInteger;
49
50
import test.java.awt.regtesthelpers.Util;
51
52
public class ModalDialogEnterExitEventsTest {
53
private static volatile AtomicInteger mouseEnterCount = new AtomicInteger();
54
private static volatile AtomicInteger mouseExitCount = new AtomicInteger();
55
56
private static JFrame frame;
57
private static JDialog dialog;
58
private static JButton openButton;
59
private static JButton closeButton;
60
61
public static void main(String[] args) throws Exception {
62
try {
63
Robot robot = Util.createRobot();
64
65
SwingUtilities.invokeAndWait(new Runnable() {
66
@Override
67
public void run() {
68
createAndShowGUI();
69
}
70
});
71
Util.waitForIdle(robot);
72
73
Util.clickOnComp(frame, robot, 500);
74
Util.waitForIdle(robot);
75
76
mouseEnterCount.set(0);
77
mouseExitCount.set(0);
78
79
Util.clickOnComp(openButton, robot, 500);
80
Util.waitForIdle(robot);
81
Util.waitTillShown(dialog);
82
if (mouseExitCount.get() != 1) {
83
throw new RuntimeException("Test FAILED. Wrong number of "
84
+ "MouseExited events = " + mouseExitCount.get());
85
}
86
87
Util.clickOnComp(closeButton, robot, 500);
88
Util.waitForIdle(robot);
89
robot.delay(200);
90
if (mouseEnterCount.get() != 1) {
91
throw new RuntimeException("Test FAILED. Wrong number of "
92
+ "MouseEntered events = "+ mouseEnterCount.get());
93
}
94
} finally {
95
if (frame != null) {
96
SwingUtilities.invokeAndWait(() -> frame.dispose());
97
}
98
}
99
}
100
101
private static void createAndShowGUI() {
102
frame = new JFrame("ModalDialogEnterExitEventsTest");
103
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
104
frame.setLayout(new FlowLayout());
105
frame.addMouseListener(new MouseAdapter() {
106
@Override
107
public void mouseExited(MouseEvent e) {
108
mouseExitCount.getAndIncrement();
109
}
110
111
@Override
112
public void mouseEntered(MouseEvent e) {
113
mouseEnterCount.getAndIncrement();
114
}
115
});
116
openButton = new JButton("Open Dialog");
117
openButton.addActionListener(new ActionListener() {
118
@Override
119
public void actionPerformed(ActionEvent e) {
120
dialog = new JDialog(frame, "Modal Dialog", true);
121
dialog.setLayout(new FlowLayout());
122
closeButton = new JButton("Close");
123
closeButton.addActionListener(new ActionListener() {
124
@Override
125
public void actionPerformed(ActionEvent e) {
126
dialog.dispose();
127
}
128
});
129
dialog.add(closeButton);
130
dialog.setSize(200, 200);
131
dialog.setLocationRelativeTo(null);
132
dialog.setVisible(true);
133
}
134
});
135
frame.add(openButton);
136
frame.setExtendedState(Frame.MAXIMIZED_BOTH);
137
frame.setVisible(true);
138
}
139
}
140
141
142