Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/jdk/javax/swing/JEditorPane/TestHTMLBulletsSizeAndAliasing.java
58328 views
1
/*
2
* Copyright (c) 2018, 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
* @test
25
* @bug 8201925 8202013
26
* @summary Verifies if JEditorPane unordered list bullets look pixelated
27
* and large relative to text font size
28
* @run main/manual TestHTMLBulletsSizeAndAliasing
29
*/
30
import java.awt.Dimension;
31
import java.awt.FlowLayout;
32
import java.awt.BorderLayout;
33
import java.awt.Component;
34
import java.awt.Graphics;
35
import java.awt.Graphics2D;
36
import java.awt.RenderingHints;
37
import java.awt.event.MouseAdapter;
38
import java.awt.event.MouseEvent;
39
import java.util.concurrent.CountDownLatch;
40
import java.util.concurrent.TimeUnit;
41
import javax.swing.JSplitPane;
42
import javax.swing.SwingUtilities;
43
import javax.swing.JDialog;
44
import javax.swing.JPanel;
45
import javax.swing.JButton;
46
import javax.swing.JFrame;
47
import javax.swing.JScrollPane;
48
import javax.swing.JTextArea;
49
import javax.swing.JEditorPane;
50
51
public class TestHTMLBulletsSizeAndAliasing {
52
53
public static void main(String[] args) throws Exception {
54
final CountDownLatch latch = new CountDownLatch(1);
55
56
AliasingTest test = new AliasingTest(latch);
57
Thread T1 = new Thread(test);
58
T1.start();
59
60
// wait for latch to complete
61
boolean ret = false;
62
try {
63
ret = latch.await(60, TimeUnit.SECONDS);
64
} catch (InterruptedException ie) {
65
throw ie;
66
}
67
if (!ret) {
68
test.dispose();
69
throw new RuntimeException(" User has not executed the test");
70
}
71
72
if (test.testResult == false) {
73
throw new RuntimeException("JEditorPane unordered list bullets look pixelated");
74
}
75
}
76
}
77
78
class AliasingTest implements Runnable {
79
static JFrame f;
80
static JDialog dialog;
81
public boolean testResult = false;
82
private final CountDownLatch latch;
83
84
public AliasingTest(CountDownLatch latch) throws Exception {
85
this.latch = latch;
86
}
87
88
@Override
89
public void run() {
90
try {
91
SwingUtilities.invokeAndWait(() -> {
92
createUI();
93
aliasingTest();
94
});
95
} catch (Exception ex) {
96
if (f != null) {
97
f.dispose();
98
}
99
latch.countDown();
100
throw new RuntimeException("createUI Failed: " + ex.getMessage());
101
}
102
103
}
104
105
public void dispose() {
106
dialog.dispose();
107
f.dispose();
108
}
109
110
111
private static String getHtml() {
112
return "<html><body>" +
113
"<ul>" +
114
"<li>Text</li>" +
115
"<li>Document</li>" +
116
"</ul>" +
117
"</body></html>";
118
}
119
120
private static Component createSplitPane() {
121
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
122
createHtmlViewer(false), createHtmlViewer(true));
123
splitPane.setOneTouchExpandable(true);
124
splitPane.setResizeWeight(0.5);
125
splitPane.setPreferredSize(new Dimension(150, 150));
126
return splitPane;
127
}
128
129
private static Component createHtmlViewer(boolean antialiasing) {
130
JEditorPane editorPane;
131
if (antialiasing) {
132
editorPane = new JEditorPane() {
133
@Override
134
public void paint(Graphics g) {
135
Graphics2D g2d = (Graphics2D) g.create();
136
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
137
super.paint(g2d);
138
g2d.dispose();
139
}
140
};
141
}
142
else {
143
editorPane = new JEditorPane();
144
}
145
editorPane.setEditable(false);
146
editorPane.setContentType("text/html");
147
editorPane.setText(getHtml());
148
return new JScrollPane(editorPane);
149
}
150
private static void aliasingTest() {
151
f = new JFrame("List Bullets");
152
f.add(createSplitPane());
153
f.pack();
154
f.setLocationRelativeTo(null);
155
f.setVisible(true);
156
}
157
158
159
private final void createUI() {
160
String description
161
= " INSTRUCTIONS:\n"
162
+ " A JEditorPane divided by SplitPane will be shown.\n"
163
+ " The upper html is rendered in a default JEditorPane.\n "
164
+ " The lower html is rendered in a JEditorPane using "
165
+ " rendering hints to turn on antialiasing.\n"
166
+ " If upper html bullets looks pixelated AND"
167
+ " larger than needed relative to text font size\n"
168
+ " and not as smooth as shown in lower html\n "
169
+ " then press fail else press pass";
170
171
dialog = new JDialog();
172
dialog.setTitle("textselectionTest");
173
JTextArea textArea = new JTextArea(description);
174
textArea.setEditable(false);
175
final JButton passButton = new JButton("PASS");
176
passButton.addActionListener((e) -> {
177
testResult = true;
178
dispose();
179
latch.countDown();
180
});
181
final JButton failButton = new JButton("FAIL");
182
failButton.addActionListener((e) -> {
183
testResult = false;
184
dispose();
185
latch.countDown();
186
});
187
JPanel mainPanel = new JPanel(new BorderLayout());
188
mainPanel.add(textArea, BorderLayout.CENTER);
189
JPanel buttonPanel = new JPanel(new FlowLayout());
190
buttonPanel.add(passButton);
191
buttonPanel.add(failButton);
192
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
193
dialog.add(mainPanel);
194
dialog.pack();
195
dialog.setVisible(true);
196
}
197
}
198
199