Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/MultiUIDefaults/4331767/bug4331767.java
38855 views
1
/*
2
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/* @test
25
@bug 4331767
26
@summary Tests that custom implementation of UIDefaults.getUIError() is
27
called when an UI error occurs
28
@author Peter Zhelezniakov
29
@run main bug4331767
30
*/
31
import javax.swing.*;
32
import javax.swing.plaf.metal.MetalLookAndFeel;
33
import java.util.Locale;
34
35
public class bug4331767
36
{
37
private static boolean passed = false;
38
39
public static void main(String[] argv) {
40
try {
41
UIManager.setLookAndFeel(new BrokenLookAndFeel());
42
} catch (Exception e) {
43
throw new Error("Failed to set BrokenLookAndFeel, cannot test", e);
44
}
45
46
// This should call BrokenUIDefaults.getUIError()
47
new JButton();
48
49
if (!passed) {
50
throw new RuntimeException("Failed: Custom getUIError() not called");
51
}
52
}
53
54
static class BrokenUIDefaults extends UIDefaults {
55
UIDefaults defaults;
56
57
public BrokenUIDefaults(UIDefaults def) {
58
defaults = def;
59
}
60
61
public Object get(Object key) {
62
if ("ButtonUI".equals(key)) {
63
System.err.println("[II] Called BrokenUIDefaults.get(Object)");
64
return "a nonexistent class";
65
}
66
return defaults.get(key);
67
}
68
69
public Object get(Object key, Locale l) {
70
if ("ButtonUI".equals(key)) {
71
System.err.println("[II] Called BrokenUIDefaults.get(Object, Locale)");
72
return "a nonexistent class";
73
}
74
return defaults.get(key, l);
75
}
76
77
protected void getUIError(String msg) {
78
System.err.println("[II] BrokenUIDefaults.getUIError() called, test passes");
79
passed = true;
80
}
81
}
82
83
static class BrokenLookAndFeel extends MetalLookAndFeel {
84
UIDefaults defaults;
85
86
public BrokenLookAndFeel() {
87
defaults = new BrokenUIDefaults(super.getDefaults());
88
}
89
90
public UIDefaults getDefaults() {
91
return defaults;
92
}
93
}
94
}
95
96