Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/MultiUIDefaults/4331767/bug4331767.java
38855 views
/*1* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24@bug 433176725@summary Tests that custom implementation of UIDefaults.getUIError() is26called when an UI error occurs27@author Peter Zhelezniakov28@run main bug433176729*/30import javax.swing.*;31import javax.swing.plaf.metal.MetalLookAndFeel;32import java.util.Locale;3334public class bug433176735{36private static boolean passed = false;3738public static void main(String[] argv) {39try {40UIManager.setLookAndFeel(new BrokenLookAndFeel());41} catch (Exception e) {42throw new Error("Failed to set BrokenLookAndFeel, cannot test", e);43}4445// This should call BrokenUIDefaults.getUIError()46new JButton();4748if (!passed) {49throw new RuntimeException("Failed: Custom getUIError() not called");50}51}5253static class BrokenUIDefaults extends UIDefaults {54UIDefaults defaults;5556public BrokenUIDefaults(UIDefaults def) {57defaults = def;58}5960public Object get(Object key) {61if ("ButtonUI".equals(key)) {62System.err.println("[II] Called BrokenUIDefaults.get(Object)");63return "a nonexistent class";64}65return defaults.get(key);66}6768public Object get(Object key, Locale l) {69if ("ButtonUI".equals(key)) {70System.err.println("[II] Called BrokenUIDefaults.get(Object, Locale)");71return "a nonexistent class";72}73return defaults.get(key, l);74}7576protected void getUIError(String msg) {77System.err.println("[II] BrokenUIDefaults.getUIError() called, test passes");78passed = true;79}80}8182static class BrokenLookAndFeel extends MetalLookAndFeel {83UIDefaults defaults;8485public BrokenLookAndFeel() {86defaults = new BrokenUIDefaults(super.getDefaults());87}8889public UIDefaults getDefaults() {90return defaults;91}92}93}949596