This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
When I want to use sun.swing.ImageIconUIResource or com.sun.java.swing.plaf.gtk.GTKIconFactory$SynthExpanderIcon for explorer folder icon I get ClassCastException from org.netbeans.modules.apisupport.project.ui.UIUtil.getTreeFolderIcon(UIUtil.java:662). It blocks fix of issue #72066. I will attach diff for modifying GtkLFCustoms - it is necessary to apply this patch to reproduce this issue. It happens on GTK L&F.
It happens when I want to expand root node in some nb project eg. core.
Created attachment 52119 [details] IDE log
Created attachment 52120 [details] IDE log
Created attachment 52122 [details] Patch for GtkLFCustoms.java
You likely know much more about it than I do. If you know what to fix that will work on all platforms, go ahead. For reference, the code is mkrauskopf's.
Fix is to use Utilities.icon2image on value retrieved from UIManager. Value cannot be directly casted to Image. The same code is at apisupport/project,java/project,java/j2seproject modules.
I use grep to find out all usages of Utilities.icon2image and then checked if it is really this code pattern. I found 3 occurrences. Fix uses Utilities.icon2image on icon returned from UIManager - second value from UIManager was directly casted to Image which does not work for all cases. 'Icon' object generaly can just implement javax.swing.Icon interface. Modified: /cvs/apisupport/project/src/org/netbeans/modules/apisupport/project/ui/UIUtil.java new revision: 1.40; previous revision: 1.39 /cvs/java/j2seproject/src/org/netbeans/modules/java/j2seproject/ui/LibrariesNode.java new revision: 1.25; previous revision: 1.24 /cvs/java/project/src/org/netbeans/spi/java/project/support/ui/PackageRootNode.java new revision: 1.29; previous revision: 1.28
I am going to rollback this fix as I found that we put Image instance into these 2 keys "Nb.Explorer.Folder.icon" and "Nb.Explorer.Folder.openedIcon" for another L&Fs. IMO it is incorrect and should be reviewed. It is not consistent with UIManager keys as all 'icon' keys are objects implementing Icon interface NOT Image instances. At http://bits.netbeans.org/dev/javadoc/org-openide-loaders/architecture-summary.html it is documented that: Nb.Explorer.Folder.icon - Icon or Image for closed folder. Nb.Explorer.Folder.openedIcon - Icon or Image for opened folder. But current code simply casts returned value to java.awt.Image. Code should looks like this: Object value = UIManager.get(opened ? OPENED_ICON_KEY_UIMANAGER_NB : ICON_KEY_UIMANAGER_NB); // #70263 if (value instanceof Icon) { base = Utilities.icon2Image((Icon) value); } else if (value instanceof Image) { base = (Image) value; } Jarda suggests we can wrap Image into our own Image subclass which will implement Icon interface. This way we get Object which can be Image and Icon.
Fix reverted. I will close this issue as WONTFIX. We will discuss and select some solution. Modified: /cvs/apisupport/project/src/org/netbeans/modules/apisupport/project/ui/UIUtil.java new revision: 1.41; previous revision: 1.40 /cvs/java/j2seproject/src/org/netbeans/modules/java/j2seproject/ui/LibrariesNode.java new revision: 1.26; previous revision: 1.25 /cvs/java/project/src/org/netbeans/spi/java/project/support/ui/PackageRootNode.java new revision: 1.30; previous revision: 1.29
Closing