5088N/A/*
5088N/A * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
5088N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5088N/A *
5088N/A * This code is free software; you can redistribute it and/or modify it
5088N/A * under the terms of the GNU General Public License version 2 only, as
5088N/A * published by the Free Software Foundation.
5088N/A *
5088N/A * This code is distributed in the hope that it will be useful, but WITHOUT
5088N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5088N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5088N/A * version 2 for more details (a copy is included in the LICENSE file that
5088N/A * accompanied this code).
5088N/A *
5088N/A * You should have received a copy of the GNU General Public License version
5088N/A * 2 along with this work; if not, write to the Free Software Foundation,
5088N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5088N/A *
5088N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5088N/A * or visit www.oracle.com if you need additional information or have any
5088N/A * questions.
5088N/A */
5088N/A
5088N/A/*
5088N/A * @test
5088N/A * @bug 7143614
5088N/A * @summary Issues with Synth Look&Feel
5088N/A * @author Pavel Porvatov
5088N/A */
5088N/A
5088N/Aimport sun.awt.SunToolkit;
5088N/A
5088N/Aimport javax.swing.plaf.ComponentUI;
5088N/Aimport javax.swing.plaf.basic.BasicButtonUI;
5088N/Aimport javax.swing.plaf.synth.SynthConstants;
5088N/Aimport javax.swing.plaf.synth.SynthLookAndFeel;
5088N/Aimport java.lang.reflect.Method;
5088N/A
5088N/Apublic class bug7143614 {
5088N/A private static Method setSelectedUIMethod;
5088N/A
5088N/A private static ComponentUI componentUI = new BasicButtonUI();
5088N/A
5088N/A public static void main(String[] args) throws Exception {
5088N/A setSelectedUIMethod = SynthLookAndFeel.class.getDeclaredMethod("setSelectedUI", ComponentUI.class,
5088N/A boolean.class, boolean.class, boolean.class, boolean.class);
5088N/A setSelectedUIMethod.setAccessible(true);
5088N/A
5088N/A setSelectedUIMethod.invoke(null, componentUI, true, true, true, true);
5088N/A
5088N/A validate();
5088N/A
5088N/A Thread thread = new ThreadInAnotherAppContext();
5088N/A
5088N/A thread.start();
5088N/A thread.join();
5088N/A
5088N/A validate();
5088N/A
5088N/A System.out.println("Test bug7143614 passed.");
5088N/A }
5088N/A
5088N/A private static void validate() throws Exception {
5088N/A Method getSelectedUIMethod = SynthLookAndFeel.class.getDeclaredMethod("getSelectedUI");
5088N/A
5088N/A getSelectedUIMethod.setAccessible(true);
5088N/A
5088N/A Method getSelectedUIStateMethod = SynthLookAndFeel.class.getDeclaredMethod("getSelectedUIState");
5088N/A
5088N/A getSelectedUIStateMethod.setAccessible(true);
5088N/A
5088N/A if (getSelectedUIMethod.invoke(null) != componentUI) {
5088N/A throw new RuntimeException("getSelectedUI returns invalid value");
5088N/A }
5088N/A if (((Integer) getSelectedUIStateMethod.invoke(null)).intValue() !=
5088N/A (SynthConstants.SELECTED | SynthConstants.FOCUSED)) {
5088N/A throw new RuntimeException("getSelectedUIState returns invalid value");
5088N/A }
5088N/A
5088N/A }
5088N/A
5088N/A private static class ThreadInAnotherAppContext extends Thread {
5088N/A public ThreadInAnotherAppContext() {
5088N/A super(new ThreadGroup("7143614"), "ThreadInAnotherAppContext");
5088N/A }
5088N/A
5088N/A public void run() {
5088N/A SunToolkit.createNewAppContext();
5088N/A
5088N/A try {
5088N/A setSelectedUIMethod.invoke(null, null, false, false, false, false);
5088N/A } catch (Exception e) {
5088N/A throw new RuntimeException(e);
5088N/A }
5088N/A }
5088N/A }
5088N/A}