Path: blob/master/test/jdk/javax/swing/JEditorPane/TestHTMLBulletsSizeAndAliasing.java
58328 views
/*1* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22/*23* @test24* @bug 8201925 820201325* @summary Verifies if JEditorPane unordered list bullets look pixelated26* and large relative to text font size27* @run main/manual TestHTMLBulletsSizeAndAliasing28*/29import java.awt.Dimension;30import java.awt.FlowLayout;31import java.awt.BorderLayout;32import java.awt.Component;33import java.awt.Graphics;34import java.awt.Graphics2D;35import java.awt.RenderingHints;36import java.awt.event.MouseAdapter;37import java.awt.event.MouseEvent;38import java.util.concurrent.CountDownLatch;39import java.util.concurrent.TimeUnit;40import javax.swing.JSplitPane;41import javax.swing.SwingUtilities;42import javax.swing.JDialog;43import javax.swing.JPanel;44import javax.swing.JButton;45import javax.swing.JFrame;46import javax.swing.JScrollPane;47import javax.swing.JTextArea;48import javax.swing.JEditorPane;4950public class TestHTMLBulletsSizeAndAliasing {5152public static void main(String[] args) throws Exception {53final CountDownLatch latch = new CountDownLatch(1);5455AliasingTest test = new AliasingTest(latch);56Thread T1 = new Thread(test);57T1.start();5859// wait for latch to complete60boolean ret = false;61try {62ret = latch.await(60, TimeUnit.SECONDS);63} catch (InterruptedException ie) {64throw ie;65}66if (!ret) {67test.dispose();68throw new RuntimeException(" User has not executed the test");69}7071if (test.testResult == false) {72throw new RuntimeException("JEditorPane unordered list bullets look pixelated");73}74}75}7677class AliasingTest implements Runnable {78static JFrame f;79static JDialog dialog;80public boolean testResult = false;81private final CountDownLatch latch;8283public AliasingTest(CountDownLatch latch) throws Exception {84this.latch = latch;85}8687@Override88public void run() {89try {90SwingUtilities.invokeAndWait(() -> {91createUI();92aliasingTest();93});94} catch (Exception ex) {95if (f != null) {96f.dispose();97}98latch.countDown();99throw new RuntimeException("createUI Failed: " + ex.getMessage());100}101102}103104public void dispose() {105dialog.dispose();106f.dispose();107}108109110private static String getHtml() {111return "<html><body>" +112"<ul>" +113"<li>Text</li>" +114"<li>Document</li>" +115"</ul>" +116"</body></html>";117}118119private static Component createSplitPane() {120JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,121createHtmlViewer(false), createHtmlViewer(true));122splitPane.setOneTouchExpandable(true);123splitPane.setResizeWeight(0.5);124splitPane.setPreferredSize(new Dimension(150, 150));125return splitPane;126}127128private static Component createHtmlViewer(boolean antialiasing) {129JEditorPane editorPane;130if (antialiasing) {131editorPane = new JEditorPane() {132@Override133public void paint(Graphics g) {134Graphics2D g2d = (Graphics2D) g.create();135g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);136super.paint(g2d);137g2d.dispose();138}139};140}141else {142editorPane = new JEditorPane();143}144editorPane.setEditable(false);145editorPane.setContentType("text/html");146editorPane.setText(getHtml());147return new JScrollPane(editorPane);148}149private static void aliasingTest() {150f = new JFrame("List Bullets");151f.add(createSplitPane());152f.pack();153f.setLocationRelativeTo(null);154f.setVisible(true);155}156157158private final void createUI() {159String description160= " INSTRUCTIONS:\n"161+ " A JEditorPane divided by SplitPane will be shown.\n"162+ " The upper html is rendered in a default JEditorPane.\n "163+ " The lower html is rendered in a JEditorPane using "164+ " rendering hints to turn on antialiasing.\n"165+ " If upper html bullets looks pixelated AND"166+ " larger than needed relative to text font size\n"167+ " and not as smooth as shown in lower html\n "168+ " then press fail else press pass";169170dialog = new JDialog();171dialog.setTitle("textselectionTest");172JTextArea textArea = new JTextArea(description);173textArea.setEditable(false);174final JButton passButton = new JButton("PASS");175passButton.addActionListener((e) -> {176testResult = true;177dispose();178latch.countDown();179});180final JButton failButton = new JButton("FAIL");181failButton.addActionListener((e) -> {182testResult = false;183dispose();184latch.countDown();185});186JPanel mainPanel = new JPanel(new BorderLayout());187mainPanel.add(textArea, BorderLayout.CENTER);188JPanel buttonPanel = new JPanel(new FlowLayout());189buttonPanel.add(passButton);190buttonPanel.add(failButton);191mainPanel.add(buttonPanel, BorderLayout.SOUTH);192dialog.add(mainPanel);193dialog.pack();194dialog.setVisible(true);195}196}197198199