Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JSpinner/TestJSpinnerPressUnpress.java
41152 views
1
/*
2
* Copyright (c) 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
* @bug 8234733
27
* @summary Verify that JSpinner up/down button rendering is changed
28
* according to pressed state in GTKLookAndFeel
29
* @run main/manual TestJSpinnerPressUnpress
30
*/
31
32
import java.awt.Color;
33
import java.awt.GridBagConstraints;
34
import java.awt.GridBagLayout;
35
import java.awt.Insets;
36
import java.awt.event.ActionEvent;
37
import java.awt.event.WindowAdapter;
38
import java.awt.event.WindowEvent;
39
import java.util.concurrent.CountDownLatch;
40
import java.util.concurrent.TimeUnit;
41
import javax.swing.JButton;
42
import javax.swing.JSpinner;
43
import javax.swing.JFrame;
44
import javax.swing.JPanel;
45
import javax.swing.JTextArea;
46
import javax.swing.UIManager;
47
import javax.swing.SwingUtilities;
48
import javax.swing.UnsupportedLookAndFeelException;
49
50
public class TestJSpinnerPressUnpress {
51
private static JFrame mainFrame = new JFrame();
52
private static volatile boolean testResult = false;
53
private static volatile CountDownLatch countDownLatch;
54
private static final String GTK_LAF_CLASS = "GTKLookAndFeel";
55
private static final String INSTRUCTIONS = "INSTRUCTIONS:\n\n" +
56
"Verify that when spinner up/down button is pressed to change\n" +
57
"the spinner value, the button's rendering is changed to show\n" +
58
"the pressed state. If yes, Press Pass, Otherwise, Press Fail.";
59
60
public static void main(String args[]) throws Exception {
61
if (!System.getProperty("os.name").startsWith("Linux")) {
62
System.out.println("This test is meant for Linux platform only");
63
return;
64
}
65
countDownLatch = new CountDownLatch(1);
66
67
for (UIManager.LookAndFeelInfo lookAndFeelInfo :
68
UIManager.getInstalledLookAndFeels()) {
69
if (lookAndFeelInfo.getClassName().contains(GTK_LAF_CLASS)) {
70
try {
71
UIManager.setLookAndFeel(lookAndFeelInfo.getClassName());
72
} catch (final UnsupportedLookAndFeelException ignored) {
73
System.out.println("GTK L&F could not be set, so this " +
74
"test can not be run in this scenario ");
75
return;
76
}
77
}
78
}
79
SwingUtilities.invokeLater(TestJSpinnerPressUnpress::createUI);
80
countDownLatch.await(15, TimeUnit.MINUTES);
81
SwingUtilities.invokeLater(mainFrame::dispose);
82
83
if (!testResult) {
84
throw new RuntimeException("Test failed!");
85
}
86
}
87
88
private static void createUI() {
89
GridBagLayout layout = new GridBagLayout();
90
JPanel mainControlPanel = new JPanel(layout);
91
JPanel resultButtonPanel = new JPanel(layout);
92
93
GridBagConstraints gbc = new GridBagConstraints();
94
95
gbc.gridx = 0;
96
gbc.gridy = 0;
97
gbc.insets = new Insets(5, 15, 5, 15);
98
gbc.fill = GridBagConstraints.HORIZONTAL;
99
mainControlPanel.add(new JSpinner(), gbc);
100
101
JTextArea instructionTextArea = new JTextArea();
102
instructionTextArea.setText(INSTRUCTIONS);
103
instructionTextArea.setEditable(false);
104
105
gbc.gridx = 0;
106
gbc.gridy = 1;
107
gbc.fill = GridBagConstraints.HORIZONTAL;
108
mainControlPanel.add(instructionTextArea, gbc);
109
110
JButton passButton = new JButton("Pass");
111
passButton.setActionCommand("Pass");
112
passButton.addActionListener((ActionEvent e) -> {
113
testResult = true;
114
countDownLatch.countDown();
115
116
});
117
118
JButton failButton = new JButton("Fail");
119
failButton.setActionCommand("Fail");
120
failButton.addActionListener(e -> {
121
countDownLatch.countDown();
122
});
123
124
gbc.gridx = 0;
125
gbc.gridy = 0;
126
127
resultButtonPanel.add(passButton, gbc);
128
129
gbc.gridx = 1;
130
gbc.gridy = 0;
131
resultButtonPanel.add(failButton, gbc);
132
133
gbc.gridx = 0;
134
gbc.gridy = 2;
135
mainControlPanel.add(resultButtonPanel, gbc);
136
137
mainFrame.add(mainControlPanel);
138
mainFrame.pack();
139
140
mainFrame.addWindowListener(new WindowAdapter() {
141
@Override
142
public void windowClosing(WindowEvent e) {
143
mainFrame.dispose();
144
countDownLatch.countDown();
145
}
146
});
147
mainFrame.setVisible(true);
148
}
149
}
150
151