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/JSpinner/8008657/bug8008657.java
38918 views
1
/*
2
* Copyright (c) 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
import java.awt.ComponentOrientation;
25
import java.awt.Robot;
26
import java.util.Calendar;
27
import java.util.Date;
28
import javax.swing.JFrame;
29
import javax.swing.JSpinner;
30
import javax.swing.JTextField;
31
import javax.swing.SpinnerDateModel;
32
import javax.swing.SpinnerModel;
33
import javax.swing.SpinnerNumberModel;
34
import javax.swing.SwingUtilities;
35
36
/**
37
* @test
38
* @bug 8008657
39
* @author Alexander Scherbatiy
40
* @summary JSpinner setComponentOrientation doesn't affect on text orientation
41
* @run main bug8008657
42
*/
43
public class bug8008657 {
44
45
private static Robot robot;
46
private static JSpinner spinner;
47
48
public static void main(String[] args) throws Exception {
49
50
robot = new Robot();
51
52
SwingUtilities.invokeAndWait(() -> {
53
createDateSpinner();
54
createAndShowUI();
55
});
56
57
robot.waitForIdle();
58
testSpinner(false);
59
60
SwingUtilities.invokeAndWait(() -> {
61
createNumberSpinner();
62
createAndShowUI();
63
});
64
65
robot.waitForIdle();
66
testSpinner(true);
67
}
68
69
static void testSpinner(boolean checkHorizontalAligment)
70
throws Exception {
71
72
SwingUtilities.invokeAndWait(() -> {
73
spinner.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
74
});
75
robot.waitForIdle();
76
77
SwingUtilities.invokeAndWait(() -> {
78
79
JTextField textField = getTextField();
80
if (!ComponentOrientation.RIGHT_TO_LEFT.equals(
81
textField.getComponentOrientation())) {
82
throw new RuntimeException("Wrong orientation!");
83
}
84
85
if (checkHorizontalAligment
86
&& textField.getHorizontalAlignment() != JTextField.LEFT) {
87
throw new RuntimeException("Wrong horizontal aligment!");
88
}
89
90
spinner.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
91
});
92
93
robot.waitForIdle();
94
95
SwingUtilities.invokeAndWait(() -> {
96
JTextField textField = getTextField();
97
if (!ComponentOrientation.LEFT_TO_RIGHT.equals(
98
textField.getComponentOrientation())) {
99
throw new RuntimeException("Wrong orientation!");
100
}
101
102
if (checkHorizontalAligment
103
&& textField.getHorizontalAlignment() != JTextField.RIGHT) {
104
throw new RuntimeException("Wrong horizontal aligment!");
105
}
106
107
spinner.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
108
});
109
}
110
111
static JTextField getTextField() {
112
return ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField();
113
}
114
115
static String getOrientation(ComponentOrientation orientation) {
116
return orientation == ComponentOrientation.LEFT_TO_RIGHT ? "LEFT_TO_RIGHT" : "RIGHT_TO_LEFT";
117
}
118
119
static void createDateSpinner() {
120
Calendar calendar = Calendar.getInstance();
121
Date initDate = calendar.getTime();
122
calendar.add(Calendar.YEAR, -1);
123
Date earliestDate = calendar.getTime();
124
calendar.add(Calendar.YEAR, 1);
125
Date latestDate = calendar.getTime();
126
SpinnerModel dateModel = new SpinnerDateModel(initDate,
127
earliestDate,
128
latestDate,
129
Calendar.YEAR);
130
spinner = new JSpinner();
131
spinner.setModel(dateModel);
132
}
133
134
static void createNumberSpinner() {
135
Calendar calendar = Calendar.getInstance();
136
calendar.add(Calendar.YEAR, -1);
137
calendar.add(Calendar.YEAR, 1);
138
int currentYear = calendar.get(Calendar.YEAR);
139
SpinnerModel yearModel = new SpinnerNumberModel(currentYear, //initial value
140
currentYear - 1, //min
141
currentYear + 2, //max
142
1); //step
143
spinner = new JSpinner();
144
spinner.setModel(yearModel);
145
}
146
147
static void createAndShowUI() {
148
JFrame frame = new JFrame("Test");
149
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
150
frame.setSize(300, 100);
151
frame.getContentPane().add(spinner);
152
frame.setVisible(true);
153
}
154
}
155
156