1 /* 2 * Copyright (c) 2015, 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 4960629 7124238 26 @summary Tests if font for html text on widgets in correct. 27 @author Denis Sharypov 28 @run main bug4960629 29 */ 30 31 import java.awt.Font; 32 import java.lang.reflect.InvocationTargetException; 33 import javax.swing.JFrame; 34 import javax.swing.JLabel; 35 import javax.swing.SwingUtilities; 36 import javax.swing.UIManager; 37 import javax.swing.plaf.basic.BasicHTML; 38 import javax.swing.text.AttributeSet; 39 import javax.swing.text.View; 40 import javax.swing.text.html.StyleSheet; 41 import javax.swing.text.html.HTMLDocument; 42 43 public class bug4960629 { 44 private boolean passed = false; 45 private JLabel label = null; 46 private JFrame f = null; 47 48 public void createAndShowGUI() throws Exception { 49 try { 50 UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); 51 label = new JLabel("<html><P>This is a test of the</P></html>"); 52 System.out.println("UIManager.getLookAndFeel()" 53 + UIManager.getLookAndFeel().getClass()); 54 f = new JFrame(); 55 f.getContentPane().add(label); 56 f.pack(); 57 f.setVisible(true); 58 test(); 59 } finally { 60 f.dispose(); 61 } 62 } 63 64 bug4960629() throws InvocationTargetException, InterruptedException { 65 SwingUtilities.invokeAndWait(new Runnable() { 66 @Override 67 public void run() { 68 try { 69 createAndShowGUI(); 70 } catch (Exception e) { 71 throw new RuntimeException("Exception " 72 + e.getMessage()); 73 } 74 } 75 }); 76 } 77 78 private void test() { 79 View root = ((View)label.getClientProperty(BasicHTML.propertyKey)) 80 .getView(0); 81 int n = root.getViewCount(); 82 View v = root.getView(n - 1); 83 AttributeSet attrs = v.getAttributes(); 84 StyleSheet ss = ((HTMLDocument) v.getDocument()).getStyleSheet(); 85 Font font = ss.getFont(attrs); 86 System.out.println(font.getSize()); 87 passed = (font.getSize() == 12); 88 if(!passed) { 89 throw new RuntimeException("Test failed."); 90 } 91 } 92 93 public static void main(String args[]) throws Throwable { 94 new bug4960629(); 95 } 96 }