Skip to content

Commit 13bcda4

Browse files
committed
8041701: Nimbus JTree renderer properties persist across L&F changes
Reviewed-by: serb, psadhukhan
1 parent 54c0178 commit 13bcda4

3 files changed

Lines changed: 85 additions & 6 deletions

File tree

src/java.desktop/share/classes/javax/swing/plaf/nimbus/DerivedColor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
package javax.swing.plaf.nimbus;
2626

2727
import javax.swing.UIManager;
28+
import javax.swing.plaf.UIResource;
2829
import java.awt.Color;
2930
import java.beans.PropertyChangeSupport;
3031
import java.beans.PropertyChangeListener;
@@ -39,7 +40,7 @@
3940
* @author Jasper Potts
4041
*/
4142
@SuppressWarnings("serial") // Same-version serialization only
42-
class DerivedColor extends Color {
43+
class DerivedColor extends Color implements UIResource {
4344
private final String uiDefaultParentName;
4445
private final float hOffset, sOffset, bOffset;
4546
private final int aOffset;

src/java.desktop/share/classes/javax/swing/plaf/nimbus/NimbusIcon.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,26 @@
2424
*/
2525
package javax.swing.plaf.nimbus;
2626

27+
import javax.swing.JComponent;
28+
import javax.swing.JMenu;
29+
import javax.swing.JToolBar;
2730
import javax.swing.Painter;
31+
import javax.swing.UIManager;
32+
import javax.swing.plaf.UIResource;
33+
import javax.swing.plaf.synth.SynthContext;
2834
import javax.swing.plaf.synth.SynthIcon;
2935

30-
import javax.swing.plaf.synth.SynthContext;
31-
import javax.swing.*;
32-
import java.awt.*;
36+
import java.awt.BorderLayout;
37+
import java.awt.Component;
38+
import java.awt.Graphics2D;
39+
import java.awt.Graphics;
3340
import java.awt.image.BufferedImage;
34-
import javax.swing.plaf.UIResource;
3541

3642
/**
3743
* An icon that delegates to a painter.
3844
* @author rbair
3945
*/
40-
class NimbusIcon implements SynthIcon {
46+
class NimbusIcon implements SynthIcon, UIResource {
4147
private int width;
4248
private int height;
4349
private String prefix;
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright (c) 2020, 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+
import javax.swing.UIManager;
25+
import javax.swing.UnsupportedLookAndFeelException;
26+
import javax.swing.plaf.UIResource;
27+
28+
/**
29+
* @test
30+
* @bug 8041701
31+
* @summary Nimbus JTree renderer properties persist across L&F changes
32+
* @key headful
33+
* @run main NimbusPropertiesDoNotImplUIResource
34+
*/
35+
36+
public class NimbusPropertiesDoNotImplUIResource {
37+
private static final String[] defPropertyKeys = new String[] {
38+
"Tree.leafIcon", "Tree.closedIcon",
39+
"Tree.openIcon", "Tree.selectionForeground",
40+
"Tree.textForeground", "Tree.selectionBackground",
41+
"Tree.textBackground", "Tree.selectionBorderColor"};
42+
43+
public static void main(String[] args) throws Exception {
44+
UIManager.LookAndFeelInfo[] installedLookAndFeels;
45+
installedLookAndFeels = UIManager.getInstalledLookAndFeels();
46+
47+
for (UIManager.LookAndFeelInfo LF : installedLookAndFeels) {
48+
try {
49+
UIManager.setLookAndFeel(LF.getClassName());
50+
for (String propertyKey : defPropertyKeys) {
51+
verifyProperty(propertyKey);
52+
}
53+
} catch(UnsupportedLookAndFeelException e) {
54+
System.out.println("Note: LookAndFeel " + LF.getClassName()
55+
+ " is not supported on this configuration");
56+
}
57+
}
58+
59+
}
60+
61+
private static void verifyProperty(String propertyKey) {
62+
Object property = UIManager.get(propertyKey);
63+
if (property == null) {
64+
return;
65+
}
66+
if (!(property instanceof UIResource)) {
67+
throw new RuntimeException("Property '"+ propertyKey
68+
+"' is instance of '"+property.getClass()
69+
+"' instead of UIResource.");
70+
}
71+
}
72+
}

0 commit comments

Comments
 (0)