1087N/A/*
2362N/A * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
1087N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1087N/A *
1087N/A * This code is free software; you can redistribute it and/or modify it
1087N/A * under the terms of the GNU General Public License version 2 only, as
1087N/A * published by the Free Software Foundation.
1087N/A *
1087N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1087N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1087N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1087N/A * version 2 for more details (a copy is included in the LICENSE file that
1087N/A * accompanied this code).
1087N/A *
1087N/A * You should have received a copy of the GNU General Public License version
1087N/A * 2 along with this work; if not, write to the Free Software Foundation,
1087N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1087N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
1087N/A */
1087N/A
1087N/A/* @test
1087N/A @bug 4783068
1087N/A @summary Disabled components should render grayed-out HTML
1087N/A @author Peter Zhelezniakov
1087N/A @run main Test4783068
1087N/A*/
1087N/A
1087N/Aimport java.awt.*;
1087N/Aimport java.awt.image.BufferedImage;
1087N/Aimport javax.swing.*;
1087N/Aimport javax.swing.plaf.metal.MetalLookAndFeel;
1087N/A
1087N/Apublic class Test4783068 {
1087N/A final static Color TEST_COLOR = Color.WHITE;
1087N/A
1087N/A final static String html = "<html>" +
1087N/A "This is a <font color='red'>colored</font> <b>text</b>" +
1087N/A "<p>with a <a href='http://ru.sun.com'>link</a>" +
1087N/A "<ul><li>an unordered<li>list</ul>" +
1087N/A "<ol><li>and an ordered<li>list</ol>" +
1087N/A "</html>";
1087N/A
1087N/A
1087N/A void test() {
1087N/A try {
1087N/A UIManager.setLookAndFeel(new MetalLookAndFeel());
1087N/A } catch (UnsupportedLookAndFeelException e) {
1087N/A throw new Error("Cannot set Metal LAF");
1087N/A }
1087N/A // Render text using background color
1087N/A UIManager.put("textInactiveText", TEST_COLOR);
1087N/A
1087N/A test(new JLabel(html));
1087N/A test(new JButton(html));
1087N/A
1087N/A JEditorPane pane = new JEditorPane("text/html", html);
1087N/A pane.setDisabledTextColor(TEST_COLOR);
1087N/A test(pane);
1087N/A }
1087N/A
1087N/A void test(JComponent c) {
1087N/A c.setEnabled(false);
1087N/A c.setOpaque(true);
1087N/A c.setBackground(TEST_COLOR);
1087N/A c.setBorder(null);
1087N/A Dimension size = c.getPreferredSize();
1087N/A c.setBounds(0, 0, size.width, size.height);
1087N/A
1087N/A BufferedImage image = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB);
1087N/A c.paint(image.getGraphics());
1087N/A
1087N/A int rgb = TEST_COLOR.getRGB();
1087N/A for (int i = 0; i < size.height; i++) {
1087N/A for (int j = 0; j < size.width; j++) {
1087N/A if (image.getRGB(j, i) != rgb) {
1087N/A throw new RuntimeException(
1087N/A String.format("Color mismatch at [%d, %d]", j, i));
1087N/A }
1087N/A }
1087N/A }
1087N/A }
1087N/A
1087N/A public static void main(String[] args) throws Exception {
1087N/A SwingUtilities.invokeAndWait(new Runnable() {
1087N/A @Override public void run() {
1087N/A new Test4783068().test();
1087N/A }
1087N/A });
1087N/A }
1087N/A}