2602N/A/*
2602N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2602N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2602N/A *
2602N/A * This code is free software; you can redistribute it and/or modify it
2602N/A * under the terms of the GNU General Public License version 2 only, as
2602N/A * published by the Free Software Foundation.
2602N/A *
2602N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2602N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2602N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2602N/A * version 2 for more details (a copy is included in the LICENSE file that
2602N/A * accompanied this code).
2602N/A *
2602N/A * You should have received a copy of the GNU General Public License version
2602N/A * 2 along with this work; if not, write to the Free Software Foundation,
2602N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2602N/A *
2602N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2602N/A * or visit www.oracle.com if you need additional information or have any
2602N/A * questions.
2602N/A */
2602N/A
2602N/A/*
2602N/A * @test
2602N/A * @bug 6199676
2602N/A * @summary Tests preview panel after L&F changing
2602N/A * @author Sergey Malenkov
2602N/A */
2602N/A
2602N/Aimport java.awt.Component;
2602N/Aimport java.awt.Container;
2602N/Aimport javax.swing.JColorChooser;
2602N/Aimport javax.swing.JFrame;
2602N/Aimport javax.swing.JPanel;
2602N/Aimport javax.swing.SwingUtilities;
2602N/Aimport javax.swing.UIManager;
2602N/Aimport javax.swing.UIManager.LookAndFeelInfo;
2602N/A
2602N/Apublic class Test6199676 implements Runnable {
2602N/A public static void main(String[] args) {
2602N/A SwingUtilities.invokeLater(new Test6199676());
2602N/A }
2602N/A
2602N/A private static void exit(String error) {
2602N/A if (error != null) {
2602N/A System.err.println(error);
2602N/A System.exit(1);
2602N/A }
2602N/A else {
2602N/A System.exit(0);
2602N/A }
2602N/A }
2602N/A
2602N/A private static Component getPreview(Container container) {
2602N/A String name = "ColorChooser.previewPanelHolder";
2602N/A for (Component component : container.getComponents()) {
2602N/A if (!name.equals(component.getName())) {
2602N/A component = (component instanceof Container)
2602N/A ? getPreview((Container) component)
2602N/A : null;
2602N/A }
2602N/A if (component instanceof Container) {
2602N/A container = (Container) component;
2602N/A return 1 == container.getComponentCount()
2602N/A ? container.getComponent(0)
2602N/A : null;
2602N/A }
2602N/A }
2602N/A return null;
2602N/A }
2602N/A
2602N/A private static boolean isShowing(Component component) {
2602N/A return (component != null) && component.isShowing();
2602N/A }
2602N/A
2602N/A private int index;
2602N/A private boolean updated;
2602N/A private JColorChooser chooser;
2602N/A
2602N/A public synchronized void run() {
2602N/A if (this.chooser == null) {
2602N/A this.chooser = new JColorChooser();
2602N/A
2602N/A JFrame frame = new JFrame(getClass().getName());
2602N/A frame.add(this.chooser);
2602N/A frame.setVisible(true);
2602N/A }
2602N/A else if (this.updated) {
2602N/A if (isShowing(this.chooser.getPreviewPanel())) {
2602N/A exit("custom preview panel is showing");
2602N/A }
2602N/A exit(null);
2602N/A }
2602N/A else {
2602N/A Component component = this.chooser.getPreviewPanel();
2602N/A if (component == null) {
2602N/A component = getPreview(this.chooser);
2602N/A }
2602N/A if (!isShowing(component)) {
2602N/A exit("default preview panel is not showing");
2602N/A }
2602N/A this.updated = true;
2602N/A this.chooser.setPreviewPanel(new JPanel());
2602N/A }
2602N/A LookAndFeelInfo[] infos = UIManager.getInstalledLookAndFeels();
2602N/A LookAndFeelInfo info = infos[++this.index % infos.length];
2602N/A try {
2602N/A UIManager.setLookAndFeel(info.getClassName());
2602N/A }
2602N/A catch (Exception exception) {
2602N/A exit("could not change L&F");
2602N/A }
2602N/A SwingUtilities.updateComponentTreeUI(this.chooser);
2602N/A SwingUtilities.invokeLater(this);
2602N/A }
2602N/A}