United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6792401 Windows LAF: ActiveWindowsIcon should not be greedy with fallback icon
JDK-6792401 : Windows LAF: ActiveWindowsIcon should not be greedy with fallback icon

Details
Type:
Bug
Submit Date:
2009-01-11
Status:
Closed
Updated Date:
2011-01-19
Project Name:
JDK
Resolved Date:
2009-05-18
Component:
client-libs
OS:
generic
Sub-Component:
javax.swing
CPU:
generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:
6u14 (b01)

Related Reports
Backport:
Duplicate:

Sub Tasks

Description
Windows LAF initDefault() contains following code:

            "Tree.openIcon",   new ActiveWindowsIcon("win.icon.shellIconBPP", "shell32Icon 5",
						     (Icon)table.get("Tree.openIcon")),
            "Tree.closedIcon", new ActiveWindowsIcon("win.icon.shellIconBPP", "shell32Icon 4",
						     (Icon)table.get("Tree.closedIcon")),

It is lazy trying to fetch system icon from the native library but it is greedy creating icon object for fallback.

This is just 2 tiny icons. Their creation do not waste much resources per se. 
But this also cause extra request to open resources.jar file and retrieve couple of entries from it. And this is much more expensive.

                                    

Comments
EVALUATION

Unfortunately once WindowsLAF replaces the original icons with ActiveValues, there's no reliable way to get the original icons without resolving the lazy values. And we need them as fallback images. So we could keep names of the images as fallback values. Yes, this means some code from Basic is going to be duplicated in WinLAF.
                                     
2009-01-13
SUGGESTED FIX

diff -r da8e4dad0b0e addon/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java
--- a/addon/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java	Tue Jan 13 01:29:36 2009 +0300
+++ b/addon/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java	Tue Jan 13 02:03:43 2009 +0300
@@ -1568,9 +1568,9 @@ public class WindowsLookAndFeel extends 
             "Tree.expandedIcon", treeExpandedIcon,
             "Tree.collapsedIcon", treeCollapsedIcon,
             "Tree.openIcon",   new ActiveWindowsIcon("win.icon.shellIconBPP", "shell32Icon 5",
-						     (Icon)table.get("Tree.openIcon")),
+						     "Tree.openIcon"),
             "Tree.closedIcon", new ActiveWindowsIcon("win.icon.shellIconBPP", "shell32Icon 4",
-						     (Icon)table.get("Tree.closedIcon")),
+						     "Tree.closedIcon"),
 	    "Tree.focusInputMap",
 	       new UIDefaults.LazyInputMap(new Object[] {
                                     "ADD", "expand",
@@ -2221,14 +2221,14 @@ public class WindowsLookAndFeel extends 
      */
     private class ActiveWindowsIcon implements UIDefaults.ActiveValue {
 	private Icon icon;
-	private Icon fallback;
+	private String resource;
 	private String nativeImageName;
 	private DesktopProperty desktopProperty;
 
 	ActiveWindowsIcon(String desktopPropertyName,
-			  String nativeImageName, Icon fallback) {
+			  String nativeImageName, String resource) {
 	    this.nativeImageName = nativeImageName;
-	    this.fallback = fallback;
+	    this.resource = resource;
 
 	    if (System.getProperty("os.name").startsWith("Windows ") &&
 		System.getProperty("os.version").compareTo("5.1") < 0) {
@@ -2250,8 +2250,8 @@ public class WindowsLookAndFeel extends 
 		    icon = new ImageIconUIResource(image);
 		}
 	    }
-	    if (icon == null && fallback != null) {
-		icon = fallback;
+	    if (icon == null) {
+            return (Icon)table.get(resource);
 	    }
 	    return icon;
 	}
                                     
2009-01-12



Hardware and Software, Engineered to Work Together