Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.
/ lanai Public archive

Commit be55178

Browse files
committedAug 17, 2020
8249674: Redo: Nimbus JTree renderer properties persist across L&F changes
Reviewed-by: psadhukhan, prr
1 parent f47f30e commit be55178

File tree

3 files changed

+105
-5
lines changed

3 files changed

+105
-5
lines changed
 

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
* An icon that delegates to a painter.
4444
* @author rbair
4545
*/
46-
class NimbusIcon implements SynthIcon {
46+
class NimbusIcon implements SynthIcon, UIResource {
4747
private int width;
4848
private int height;
4949
private String prefix;

‎src/java.desktop/share/classes/javax/swing/plaf/nimbus/skin.laf

+4-4
Original file line numberDiff line numberDiff line change
@@ -27352,10 +27352,10 @@
2735227352
<contentMargins top="0" bottom="0" left="0" right="0"/>
2735327353
<style>
2735427354
<textForeground>
27355-
<matte red="0" green="0" blue="0" alpha="0" uiDefaultParentName="text" hueOffset="0.0" saturationOffset="0.0" brightnessOffset="0.0" alphaOffset="0" uiResource="false"/>
27355+
<matte red="0" green="0" blue="0" alpha="0" uiDefaultParentName="text" hueOffset="0.0" saturationOffset="0.0" brightnessOffset="0.0" alphaOffset="0" uiResource="true"/>
2735627356
</textForeground>
2735727357
<textBackground>
27358-
<matte red="255" green="255" blue="255" alpha="255" uiDefaultParentName="nimbusLightBackground" hueOffset="0.0" saturationOffset="0.0" brightnessOffset="0.0" alphaOffset="0" uiResource="false"/>
27358+
<matte red="255" green="255" blue="255" alpha="255" uiDefaultParentName="nimbusLightBackground" hueOffset="0.0" saturationOffset="0.0" brightnessOffset="0.0" alphaOffset="0" uiResource="true"/>
2735927359
</textBackground>
2736027360
<background>
2736127361
<matte red="255" green="255" blue="255" alpha="255" uiDefaultParentName="nimbusLightBackground" hueOffset="0.0" saturationOffset="0.0" brightnessOffset="0.0" alphaOffset="0"/>
@@ -27379,10 +27379,10 @@
2737927379
<insets top="2" left="0" bottom="1" right="5"/>
2738027380
</uiProperty>
2738127381
<uiProperty name="selectionForeground" type="COLOR">
27382-
<matte red="255" green="255" blue="255" alpha="255" uiDefaultParentName="nimbusSelectedText" hueOffset="0.0" saturationOffset="0.0" brightnessOffset="0.0" alphaOffset="0" uiResource="false"/>
27382+
<matte red="255" green="255" blue="255" alpha="255" uiDefaultParentName="nimbusSelectedText" hueOffset="0.0" saturationOffset="0.0" brightnessOffset="0.0" alphaOffset="0" uiResource="true"/>
2738327383
</uiProperty>
2738427384
<uiProperty name="selectionBackground" type="COLOR">
27385-
<matte red="57" green="105" blue="138" alpha="255" uiDefaultParentName="nimbusSelectionBackground" hueOffset="0.0" saturationOffset="0.0" brightnessOffset="0.0" alphaOffset="0" uiResource="false"/>
27385+
<matte red="57" green="105" blue="138" alpha="255" uiDefaultParentName="nimbusSelectionBackground" hueOffset="0.0" saturationOffset="0.0" brightnessOffset="0.0" alphaOffset="0" uiResource="true"/>
2738627386
</uiProperty>
2738727387
<uiProperty name="dropLineColor" type="COLOR">
2738827388
<matte red="242" green="242" blue="242" alpha="255" uiDefaultParentName="nimbusFocus" hueOffset="0.0" saturationOffset="0.0" brightnessOffset="0" alphaOffset="0"/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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+
import javax.swing.plaf.nimbus.NimbusLookAndFeel;
28+
import java.awt.Color;
29+
30+
/**
31+
* @test
32+
* @bug 8249674
33+
* @summary Nimbus JTree renderer properties persist across L&F changes
34+
* @key headful
35+
* @run main NimbusPropertiesDoNotImplUIResource
36+
*/
37+
38+
public class NimbusPropertiesDoNotImplUIResource {
39+
private static final String[] defPropertyKeys = new String[] {
40+
"Tree.leafIcon", "Tree.closedIcon",
41+
"Tree.openIcon", "Tree.selectionForeground",
42+
"Tree.textForeground", "Tree.selectionBackground",
43+
"Tree.textBackground", "Tree.selectionBorderColor"};
44+
private static String failedKeys = null;
45+
46+
public static void main(String[] args) throws Exception {
47+
UIManager.LookAndFeelInfo[] installedLookAndFeels;
48+
installedLookAndFeels = UIManager.getInstalledLookAndFeels();
49+
50+
for (UIManager.LookAndFeelInfo LF : installedLookAndFeels) {
51+
try {
52+
UIManager.setLookAndFeel(LF.getClassName());
53+
failedKeys = null;
54+
for (String propertyKey : defPropertyKeys) {
55+
verifyProperty(propertyKey);
56+
}
57+
if(failedKeys != null) {
58+
throw new RuntimeException("JTree renderer Properties " +
59+
failedKeys + " are not instance of UIResource for "
60+
+ LF.getClassName());
61+
}
62+
} catch(UnsupportedLookAndFeelException e) {
63+
System.out.println("Note: LookAndFeel " + LF.getClassName()
64+
+ " is not supported on this configuration");
65+
}
66+
}
67+
68+
//Check that the both uiResource option true and false are working for
69+
//getDerivedColor method of NimbusLookAndFeel
70+
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
71+
Color color1 = ((NimbusLookAndFeel)UIManager.getLookAndFeel())
72+
.getDerivedColor("text", 0, 0, 0, 0, false);
73+
if(color1 instanceof UIResource) {
74+
throw new RuntimeException("color1 should not be instance of " +
75+
"UIResource");
76+
}
77+
78+
Color color2 = ((NimbusLookAndFeel)UIManager.getLookAndFeel())
79+
.getDerivedColor("text", 0, 0, 0, 0, true);
80+
if(!(color2 instanceof UIResource)) {
81+
throw new RuntimeException("color2 should be instance of " +
82+
"UIResource");
83+
}
84+
85+
}
86+
87+
private static void verifyProperty(String propertyKey) {
88+
Object property = UIManager.get(propertyKey);
89+
if (property == null) {
90+
return;
91+
}
92+
if (!(property instanceof UIResource)) {
93+
if(failedKeys == null) {
94+
failedKeys = ":" + propertyKey;
95+
} else {
96+
failedKeys += "," + propertyKey;
97+
}
98+
}
99+
}
100+
}

0 commit comments

Comments
 (0)
This repository has been archived.