Path: blob/master/test/jdk/javax/swing/JLabel/GetSpanHiDpiBug.java
41149 views
/*1* Copyright (c) 2017, 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 817802525* @summary Verifies if SPANs in HTML text are rendered properly in hidpi26* @run main/manual/othervm -Dsun.java2d.uiScale=2.25 GetSpanHiDpiBug27*/28import java.awt.BorderLayout;29import java.awt.FlowLayout;30import java.beans.PropertyChangeSupport;31import java.util.concurrent.CountDownLatch;32import java.util.concurrent.TimeUnit;33import javax.swing.JButton;34import javax.swing.JDialog;35import javax.swing.JFrame;36import javax.swing.JLabel;37import javax.swing.JPanel;38import javax.swing.JTextArea;39import javax.swing.SwingUtilities;4041public class GetSpanHiDpiBug {42public static void main(String[] args) throws Exception {4344final CountDownLatch latch = new CountDownLatch(1);45SpanTest test = new SpanTest(latch);46Thread T1 = new Thread(test);47T1.start();4849// wait for latch to complete50boolean ret = false;51try {52ret = latch.await(3000, TimeUnit.SECONDS);53} catch (InterruptedException ie) {54throw ie;55}56if (!ret) {57test.dispose();58throw new RuntimeException(" User has not executed the test");59}60if (test.testResult == false) {61throw new RuntimeException("Some characters overlap");62}63}64}6566class SpanTest implements Runnable {67static JFrame f;68static JDialog dialog;69public boolean testResult = false;70private final CountDownLatch latch;7172public SpanTest(CountDownLatch latch) throws Exception {73this.latch = latch;74}7576@Override77public void run() {78try {79createUI();80spanTest();81} catch (Exception ex) {82dispose();83latch.countDown();84throw new RuntimeException("createUI Failed: " + ex.getMessage());85}86}8788public void dispose() {89if (dialog != null) {90dialog.dispose();91}92if (f != null) {93f.dispose();94}95}9697private static void spanTest() throws Exception {98SwingUtilities.invokeAndWait(new Runnable() {99@Override100public void run() {101JLabel label =102new JLabel("<html><span>A few words to get started "103+ "before the bug</span><span>overlapping text</span></html>");104f = new JFrame("");105f.getContentPane().add(label, BorderLayout.CENTER);106f.setSize(500,500);107f.setVisible(true);108}109});110}111112private final void createUI() throws Exception {113SwingUtilities.invokeAndWait(new Runnable() {114@Override115public void run() {116String description117= " INSTRUCTIONS:\n"118+ " A string will be shown.\n "119+ " Press Pass if there is no overlap of characters\n"120+ " else press Fail.";121122dialog = new JDialog();123dialog.setTitle("textselectionTest");124JTextArea textArea = new JTextArea(description);125textArea.setEditable(false);126final JButton passButton = new JButton("PASS");127passButton.addActionListener((e) -> {128testResult = true;129dispose();130latch.countDown();131});132final JButton failButton = new JButton("FAIL");133failButton.addActionListener((e) -> {134testResult = false;135dispose();136latch.countDown();137});138JPanel mainPanel = new JPanel(new BorderLayout());139mainPanel.add(textArea, BorderLayout.CENTER);140JPanel buttonPanel = new JPanel(new FlowLayout());141buttonPanel.add(passButton);142buttonPanel.add(failButton);143mainPanel.add(buttonPanel, BorderLayout.SOUTH);144dialog.add(mainPanel);145dialog.pack();146dialog.setVisible(true);147}148});149}150}151152153