1859N/A/*
2362N/A * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
1859N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1859N/A *
1859N/A * This code is free software; you can redistribute it and/or modify it
1859N/A * under the terms of the GNU General Public License version 2 only, as
1859N/A * published by the Free Software Foundation.
1859N/A *
1859N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1859N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1859N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1859N/A * version 2 for more details (a copy is included in the LICENSE file that
1859N/A * accompanied this code).
1859N/A *
1859N/A * You should have received a copy of the GNU General Public License version
1859N/A * 2 along with this work; if not, write to the Free Software Foundation,
1859N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1859N/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.
1859N/A */
1859N/A
1859N/A/*
1859N/A * @test
1859N/A * @bug 6657138
1859N/A * @summary Verifies that buttons and labels don't share their ui's across appContexts
1859N/A * @author Alexander Potochkin
1859N/A */
1859N/A
1859N/Aimport sun.awt.SunToolkit;
1859N/A
1859N/Aimport javax.swing.*;
1859N/Aimport javax.swing.plaf.ButtonUI;
1859N/Aimport javax.swing.plaf.ComponentUI;
1859N/Aimport java.util.Collections;
1859N/Aimport java.util.HashMap;
1859N/Aimport java.util.Map;
1859N/Aimport java.util.Set;
1859N/A
1859N/Apublic class bug6657138 implements Runnable {
1859N/A
1859N/A private static Map<JComponent, Map<String, ComponentUI>> componentMap =
1859N/A Collections.synchronizedMap(
1859N/A new HashMap<JComponent, Map<String, ComponentUI>>());
1859N/A
1859N/A public void run() {
1859N/A SunToolkit.createNewAppContext();
1859N/A try {
1859N/A testUIMap();
1859N/A } catch (Exception e) {
1859N/A throw new RuntimeException(e);
1859N/A }
1859N/A }
1859N/A
1859N/A private static void testUIMap() throws Exception {
1859N/A UIManager.LookAndFeelInfo[] lafs = UIManager.getInstalledLookAndFeels();
1859N/A Set<JComponent> components = componentMap.keySet();
1859N/A for (JComponent c : components) {
1859N/A Map<String, ComponentUI> uiMap = componentMap.get(c);
1859N/A
1859N/A for (UIManager.LookAndFeelInfo laf : lafs) {
1859N/A if ("Nimbus".equals(laf.getName())) {
1859N/A // for some unclear reasons
1859N/A // Nimbus ui delegate for a button is null
1859N/A // when this method is called from the new AppContext
1859N/A continue;
1859N/A }
1859N/A String className = laf.getClassName();
1859N/A UIManager.setLookAndFeel(className);
1859N/A ComponentUI ui = UIManager.getUI(c);
1859N/A if (ui == null) {
1859N/A throw new RuntimeException("UI is null for " + c);
1859N/A }
1859N/A if (ui == uiMap.get(laf.getName())) {
1859N/A throw new RuntimeException(
1859N/A "Two AppContexts share the same UI delegate! \n" +
1859N/A c + "\n" + ui);
1859N/A }
1859N/A uiMap.put(laf.getName(), ui);
1859N/A }
1859N/A }
1859N/A }
1859N/A
1859N/A public static void main(String[] args) throws Exception {
1859N/A componentMap.put(new JButton("JButton"),
1859N/A new HashMap<String, ComponentUI>());
1859N/A componentMap.put(new JToggleButton("JToggleButton"),
1859N/A new HashMap<String, ComponentUI>());
1859N/A componentMap.put(new JRadioButton("JRadioButton"),
1859N/A new HashMap<String, ComponentUI>());
1859N/A componentMap.put(new JCheckBox("JCheckBox"),
1859N/A new HashMap<String, ComponentUI>());
1859N/A componentMap.put(new JCheckBox("JLabel"),
1859N/A new HashMap<String, ComponentUI>());
1859N/A testUIMap();
1859N/A ThreadGroup group = new ThreadGroup("6657138");
1859N/A Thread thread = new Thread(group, new bug6657138());
1859N/A thread.start();
1859N/A thread.join();
1859N/A }
1859N/A}
1859N/A