sdedic commented on a change in pull request #3414:
URL: https://github.com/apache/netbeans/pull/3414#discussion_r780762528
##########
File path: platform/openide.util.ui/src/org/openide/util/ImageUtilities.java
##########
@@ -825,22 +850,62 @@ private static final ToolTipImage doMergeImages(Image
image1, Image image2, int
str.append(toolTip);
}
Object firstUrl = image1.getProperty("url", null);
+ Object firstUri = image1.getProperty("uri", null);
ColorModel model = colorModel(bitmask? Transparency.BITMASK:
Transparency.TRANSLUCENT);
// Provide a delegate Icon for scalable rendering.
Icon delegateIcon = new MergedIcon(image2Icon(image1),
image2Icon(image2), x, y);
ToolTipImage buffImage = new ToolTipImage(str.toString(), delegateIcon,
- model, model.createCompatibleWritableRaster(w, h),
model.isAlphaPremultiplied(), null, firstUrl instanceof URL ? (URL)firstUrl :
null
+ model, model.createCompatibleWritableRaster(w, h),
model.isAlphaPremultiplied(), null,
+ firstUrl instanceof URL ? (URL)firstUrl : null,
+ firstUri instanceof URI ? (URI)firstUri : null
);
// Also provide an Image-based rendering for backwards-compatibility.
java.awt.Graphics g = buffImage.createGraphics();
- g.drawImage(image1, 0, 0, null);
- g.drawImage(image2, x, y, null);
+ drawImage(g, image1, 0, 0, null);
+ drawImage(g, image2, x, y, null);
g.dispose();
return buffImage;
}
+
+ /**
+ * Retrieves the original icon from a possible wrapper.
+ * @param image image
+ * @return the icon, if reachable.
+ */
+ private static Icon originalIcon(Image image) {
+ if (image instanceof ToolTipImage) {
+ return ((ToolTipImage) image).getDelegateIcon();
+ }
+ Object o = image.getProperty("originalIcon", null); // NOI18N
+ if (o instanceof Icon) {
+ // do not bother if the property is not loaded now.
+ return (Icon)o;
+ }
+ return null;
+ }
+
+ private static Image originalImage(Image image) {
+ Object o = image.getProperty("originalImage", null); // NOI18N
+ return o instanceof Image ? (Image)o : image;
+ }
+
+ /**
+ * Draws an image on graphics. The difference between a direct {@link
Graphics#drawImage(java.awt.Image, int, int, java.awt.image.ImageObserver)} call
+ * and this is that if the image is wrapped (i.e. as an attempt to add
some metadata to it), the original will be used if the wrapper is cooperative.
The
+ * wrapper image may not be compatible with the SurfaceManager and a
direct draw would result in an IllegalArgumentException.
Review comment:
I wrapped an Image instance in UIDefaults (an ImageIconUIResource,
"Tree.openIcon") with a delegating implementation: created an Image delegate
for the original Toolkit image, adding just the id metadata, delegating other
stuff to the original. Wrapped in an `ImageIcon`, put back to UIDefaults.
When such image got painted, the SurfaceManager of the delegate was still
`null`,
[`SurfaceManager.getManager`](https://github.com/JetBrains/jdk8u_jdk/blob/master/src/share/classes/sun/awt/image/SurfaceManager.java#L73)
attempted to cast it to a `BufferedImage`, which it is not, then threw
`IllegalArgumentException`.
..... and that's it ! My bad and thanks for make me looking into it once
more. If I create a BufferedImage in the first place, the instance will work
without any hassle. I thought that merely delegating `Image.getGraphics` will
be sufficient, but it is not.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists