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