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