bug4960629.java revision 17565:b762aafa34e3
1193323Sed/* 2193323Sed * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. 3193323Sed * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4193323Sed * 5193323Sed * This code is free software; you can redistribute it and/or modify it 6193323Sed * under the terms of the GNU General Public License version 2 only, as 7193323Sed * published by the Free Software Foundation. 8193323Sed * 9193323Sed * This code is distributed in the hope that it will be useful, but WITHOUT 10193323Sed * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11193323Sed * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12193323Sed * version 2 for more details (a copy is included in the LICENSE file that 13193323Sed * accompanied this code). 14193323Sed * 15193323Sed * You should have received a copy of the GNU General Public License version 16249423Sdim * 2 along with this work; if not, write to the Free Software Foundation, 17218893Sdim * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18249423Sdim * 19193323Sed * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20193323Sed * or visit www.oracle.com if you need additional information or have any 21249423Sdim * questions. 22234353Sdim */ 23249423Sdim 24249423Sdim/** 25249423Sdim * @test 26249423Sdim * @key headful 27249423Sdim * @bug 4960629 7124238 28193323Sed * @summary Tests if font for html text on widgets in correct. 29198892Srdivacky * @author Denis Sharypov 30218893Sdim * @run main bug4960629 31193323Sed */ 32193323Sed 33193323Sedimport java.awt.Font; 34193323Sedimport java.lang.reflect.InvocationTargetException; 35193323Sedimport javax.swing.JFrame; 36193323Sedimport javax.swing.JLabel; 37193323Sedimport javax.swing.SwingUtilities; 38198090Srdivackyimport javax.swing.UIManager; 39193323Sedimport javax.swing.plaf.basic.BasicHTML; 40193323Sedimport javax.swing.text.AttributeSet; 41218893Sdimimport javax.swing.text.View; 42218893Sdimimport javax.swing.text.html.StyleSheet; 43218893Sdimimport javax.swing.text.html.HTMLDocument; 44193323Sed 45193323Sedpublic class bug4960629 { 46193323Sed private boolean passed = false; 47212904Sdim private JLabel label = null; 48212904Sdim private JFrame f = null; 49212904Sdim 50193323Sed public void createAndShowGUI() throws Exception { 51193323Sed try { 52193323Sed UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); 53193323Sed label = new JLabel("<html><P>This is a test of the</P></html>"); 54193323Sed System.out.println("UIManager.getLookAndFeel()" 55249423Sdim + UIManager.getLookAndFeel().getClass()); 56193323Sed f = new JFrame(); 57193323Sed f.getContentPane().add(label); 58218893Sdim f.pack(); 59234353Sdim f.setVisible(true); 60218893Sdim test(); 61234353Sdim } finally { 62193323Sed if (f != null) { f.dispose(); } 63218893Sdim } 64249423Sdim } 65193323Sed 66193323Sed bug4960629() throws InvocationTargetException, InterruptedException { 67234353Sdim SwingUtilities.invokeAndWait(new Runnable() { 68193323Sed @Override 69218893Sdim public void run() { 70249423Sdim try { 71218893Sdim createAndShowGUI(); 72218893Sdim } catch (Exception e) { 73218893Sdim throw new RuntimeException("Exception " 74218893Sdim + e.getMessage()); 75193323Sed } 76193323Sed } 77193323Sed }); 78193323Sed } 79195098Sed 80218893Sdim private void test() { 81218893Sdim View root = ((View)label.getClientProperty(BasicHTML.propertyKey)) 82249423Sdim .getView(0); 83193323Sed int n = root.getViewCount(); 84234353Sdim View v = root.getView(n - 1); 85234353Sdim AttributeSet attrs = v.getAttributes(); 86234353Sdim StyleSheet ss = ((HTMLDocument) v.getDocument()).getStyleSheet(); 87234353Sdim Font font = ss.getFont(attrs); 88234353Sdim System.out.println(font.getSize()); 89193323Sed passed = (font.getSize() == 12); 90218893Sdim if(!passed) { 91218893Sdim throw new RuntimeException("Test failed."); 92218893Sdim } 93193323Sed } 94218893Sdim 95193323Sed public static void main(String args[]) throws Throwable { 96193323Sed new bug4960629(); 97218893Sdim } 98218893Sdim} 99218893Sdim