Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JTabbedPane/4310381/bug4310381.java
41153 views
1
/*
2
* Copyright (c) 2012, 2017, 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
* Portions Copyright (c) 2012 IBM Corporation
26
*/
27
28
/*
29
* @test
30
* @bug 4310381 8075918 8004029
31
* @summary Text in multi-row/col JTabbedPane tabs can be truncated/clipped
32
@run main/manual bug4310381
33
*/
34
import java.awt.GridBagConstraints;
35
import java.awt.GridBagLayout;
36
import java.awt.event.ActionEvent;
37
import java.util.concurrent.CountDownLatch;
38
import java.util.concurrent.TimeUnit;
39
import javax.swing.BorderFactory;
40
import javax.swing.JButton;
41
import javax.swing.JFrame;
42
import javax.swing.JPanel;
43
import javax.swing.JTextArea;
44
import javax.swing.SwingUtilities;
45
import javax.swing.UIManager;
46
import java.awt.Insets;
47
import javax.swing.UIManager;
48
import javax.swing.UnsupportedLookAndFeelException;
49
import java.util.concurrent.TimeUnit;
50
import java.util.concurrent.CountDownLatch;
51
import javax.swing.JTabbedPane;
52
import javax.swing.JLabel;
53
import java.awt.Dimension;
54
55
public class bug4310381 {
56
private static TestUI test = null;
57
private static JFrame frame = null;
58
private static JTabbedPane tab = null;
59
private static JPanel panel = null;
60
private static CountDownLatch testLatch = null;
61
62
private static void init() {
63
frame = new JFrame();
64
tab = new JTabbedPane();
65
panel = new JPanel();
66
createContentPane();
67
tab.setTabPlacement(JTabbedPane.TOP);
68
tab.setTabLayoutPolicy(JTabbedPane.WRAP_TAB_LAYOUT);
69
frame.setMinimumSize(new Dimension(100, 200));
70
}
71
72
public static void main(String[] args) throws Exception {
73
testLatch = new CountDownLatch(1);
74
test = new TestUI(testLatch);
75
76
// initialize the test UI system
77
SwingUtilities.invokeAndWait(() -> {
78
try {
79
test.createUI();
80
} catch (Exception ex) {
81
throw new RuntimeException("Exception while creating UI");
82
}
83
});
84
85
// update the laf
86
for(UIManager.LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
87
// set laf and create the frame and its sub components
88
setLookAndFeel(laf);
89
90
// update and show UI
91
SwingUtilities.invokeAndWait(() -> {
92
init();
93
frame.setTitle(laf.getClassName());
94
showUI();
95
});
96
97
final CountDownLatch latch = new CountDownLatch(1);
98
if(!latch.await(10, TimeUnit.SECONDS)) {
99
frame.setVisible(false);
100
}
101
102
// disposing the frame
103
SwingUtilities.invokeAndWait(() -> {
104
frame.dispose();
105
});
106
}
107
108
boolean status = testLatch.await(1, TimeUnit.MINUTES);
109
if (!status) {
110
System.out.println("Test timed out.");
111
}
112
113
if (test.testResult == false) {
114
disposeUI();
115
throw new RuntimeException("Test Failed.");
116
}
117
}
118
119
public static void disposeUI() throws Exception {
120
SwingUtilities.invokeAndWait(() -> {
121
if(test != null) {
122
test.disposeUI();
123
}
124
});
125
}
126
127
static void setLookAndFeel(final UIManager.LookAndFeelInfo laf) throws Exception {
128
try {
129
UIManager.setLookAndFeel(laf.getClassName());
130
} catch (ClassNotFoundException | InstantiationException |
131
UnsupportedLookAndFeelException | IllegalAccessException e) {
132
disposeUI();
133
throw new RuntimeException(e);
134
}
135
}
136
137
public static void showUI() {
138
frame.getContentPane().add(tab);
139
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
140
frame.setLocationRelativeTo(null);
141
frame.setPreferredSize(new Dimension(100, 200));
142
frame.pack();
143
frame.setVisible(true);
144
}
145
146
private static void createContentPane() {
147
String a2z = "abcdefghijklmnopqrstuvwxyz";
148
149
tab.addTab("0" + a2z + a2z, new JLabel((UIManager.getLookAndFeel())
150
.getName() + " Look and Feel"));
151
tab.addTab("1" + a2z, new JLabel("1" + a2z));
152
tab.addTab("2" + a2z, new JLabel("2" + a2z));
153
tab.addTab("3", new JPanel()); // The last tab in Metal isn't truncated, that's ok
154
}
155
}
156
157
class TestUI {
158
159
private static JFrame mainFrame;
160
private static JPanel mainControlPanel;
161
162
private static JTextArea instructionTextArea;
163
164
private static JPanel resultButtonPanel;
165
private static JButton passButton;
166
private static JButton failButton;
167
168
private GridBagConstraints gbc;
169
private static GridBagLayout layout;
170
private final CountDownLatch latch;
171
public boolean testResult = false;
172
173
public TestUI(CountDownLatch latch) {
174
this.latch = latch;
175
}
176
177
public final void createUI() throws Exception {
178
mainFrame = new JFrame();
179
180
layout = new GridBagLayout();
181
mainControlPanel = new JPanel(layout);
182
resultButtonPanel = new JPanel(layout);
183
184
gbc = new GridBagConstraints();
185
186
// Create Test instructions
187
String instructions
188
= "See for different look and feel tabbed panes titles \n"
189
+ " contain three dots(...) at the end if the pane size \n"
190
+ " cannot accommadate the title completely.\n"
191
+ "If yes, click on 'pass' else click on 'fail'\n";
192
193
instructionTextArea = new JTextArea();
194
instructionTextArea.setText(instructions);
195
instructionTextArea.setEditable(false);
196
instructionTextArea.setBorder(BorderFactory.
197
createTitledBorder("Test Instructions"));
198
199
gbc.gridx = 0;
200
gbc.gridy = 0;
201
mainControlPanel.add(instructionTextArea, gbc);
202
203
// Add customization to this test ui
204
customize();
205
206
// Create resultButtonPanel with Pass, Fail buttons
207
passButton = new JButton("Pass");
208
passButton.setActionCommand("Pass");
209
passButton.addActionListener((ActionEvent e) -> {
210
System.out.println("Pass Button pressed!");
211
testResult = true;
212
latch.countDown();
213
disposeUI();
214
});
215
216
failButton = new JButton("Fail");
217
failButton.setActionCommand("Fail");
218
failButton.addActionListener((ActionEvent e) -> {
219
System.out.println("Fail Button pressed!");
220
testResult = false;
221
latch.countDown();
222
disposeUI();
223
});
224
225
gbc.gridx = 0;
226
gbc.gridy = 0;
227
resultButtonPanel.add(passButton, gbc);
228
229
gbc.gridx = 1;
230
gbc.gridy = 0;
231
resultButtonPanel.add(failButton, gbc);
232
233
gbc.gridx = 0;
234
gbc.gridy = 2;
235
mainControlPanel.add(resultButtonPanel, gbc);
236
237
mainFrame.add(mainControlPanel);
238
mainFrame.pack();
239
mainFrame.setVisible(true);
240
}
241
242
public void disposeUI() {
243
mainFrame.dispose();
244
}
245
246
private void customize() throws Exception {
247
// Customize the test UI title
248
mainFrame.setTitle("Tabbed Pane Title Test");
249
}
250
}
251