4624N/A
4624N/A/*
4624N/A * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
4624N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4624N/A *
4624N/A * This code is free software; you can redistribute it and/or modify it
4624N/A * under the terms of the GNU General Public License version 2 only, as
4624N/A * published by the Free Software Foundation.
4624N/A *
4624N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4624N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4624N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4624N/A * version 2 for more details (a copy is included in the LICENSE file that
4624N/A * accompanied this code).
4624N/A *
4624N/A * You should have received a copy of the GNU General Public License version
4624N/A * 2 along with this work; if not, write to the Free Software Foundation,
4624N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4624N/A *
4624N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4624N/A * or visit www.oracle.com if you need additional information or have any
4624N/A * questions.
4624N/A */
4624N/A
4624N/A/*
4624N/A * @test
4624N/A * @bug 4251579
4624N/A * @summary Tests if style sheets are working in JLabel
4624N/A * @author Denis Sharypov
4624N/A * @run main bug4251579
4624N/A */
4624N/Aimport java.awt.*;
4624N/Aimport javax.swing.*;
4624N/A
4624N/Aimport sun.awt.SunToolkit;
4624N/A
4624N/Apublic class bug4251579 {
4624N/A
4624N/A private static JLabel htmlComponent;
4624N/A
4624N/A public static void main(String[] args) throws Exception {
4624N/A SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
4624N/A final Robot robot = new Robot();
4624N/A robot.setAutoDelay(50);
4624N/A
4624N/A SwingUtilities.invokeAndWait(new Runnable() {
4624N/A
4624N/A @Override
4624N/A public void run() {
4624N/A createAndShowGUI();
4624N/A }
4624N/A });
4624N/A
4624N/A toolkit.realSync();
4624N/A
4624N/A SwingUtilities.invokeAndWait(new Runnable() {
4624N/A
4624N/A @Override
4624N/A public void run() {
4624N/A boolean passed = false;
4624N/A
4624N/A Point p = htmlComponent.getLocationOnScreen();
4624N/A Dimension d = htmlComponent.getSize();
4624N/A int x0 = p.x;
4624N/A int y = p.y + d.height / 2;
4624N/A
4624N/A for (int x = x0; x < x0 + d.width; x++) {
4624N/A if (robot.getPixelColor(x, y).equals(Color.blue)) {
4624N/A passed = true;
4624N/A break;
4624N/A }
4624N/A }
4624N/A
4624N/A if (!passed) {
4624N/A throw new RuntimeException("Test failed.");
4624N/A }
4624N/A
4624N/A }
4624N/A });
4624N/A }
4624N/A
4624N/A private static void createAndShowGUI() {
4624N/A
4624N/A String htmlText =
4624N/A "<html>"
4624N/A + "<head><style> .blue{ color:blue; } </style></head>"
4624N/A + "<body"
4624N/A + "<P class=\"blue\"> should be rendered with BLUE class definition</P>"
4624N/A + "</body>";
4624N/A
4624N/A JFrame mainFrame = new JFrame("bug4251579");
4624N/A mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
4624N/A
4624N/A htmlComponent = new JLabel(htmlText);
4624N/A mainFrame.getContentPane().add(htmlComponent);
4624N/A
4624N/A mainFrame.pack();
4624N/A mainFrame.setVisible(true);
4624N/A }
4624N/A}