eirikbakke commented on a change in pull request #3414:
URL: https://github.com/apache/netbeans/pull/3414#discussion_r780094535



##########
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:
       Which wrapper images did you observe to cause an 
IllegalArgumentException?

##########
File path: platform/openide.util.ui/src/org/openide/util/ImageUtilities.java
##########
@@ -1069,31 +1140,55 @@ public static ToolTipImage createNew(String 
toolTipText, Image image, URL url) {
             if (url == null) {
                 Object value = image.getProperty("url", null);
                 url = (value instanceof URL) ? (URL) value : null;
-            }            
-            Icon icon = (image instanceof ToolTipImage)
-                    ? ((ToolTipImage) image).getDelegateIcon() : null;
+            }        
+            if (uri == null) {
+                Object value = image.getProperty("uri", null);
+                if (value instanceof URI) {
+                    uri = (URI)value;
+                }
+            }
+            // try to derive a missing URL from URI or vice versa. 

Review comment:
       This is very ugly. Would really prefer just one or the other...

##########
File path: platform/openide.util.ui/src/org/openide/util/FilteredIcon.java
##########
@@ -87,4 +89,8 @@ protected Image createAndPaintImage(
         return Toolkit.getDefaultToolkit().createImage(
                 new FilteredImageSource(img.getSource(), filter));
     }
+    
+    public String getFilterType() {
+        return filterType;

Review comment:
       Where is this used? Why is it needed?

##########
File path: platform/openide.util.ui/src/org/openide/util/ImageUtilities.java
##########
@@ -352,7 +369,14 @@ private static ToolTipImage icon2ToolTipImage(Icon icon, 
URL url) {
         should really only be called on the Event Dispatch Thread. 
Constructing the component once
         on the EDT fixed the problem. Read-only operations from non-EDT 
threads shouldn't really be
         a problem; most Icon implementations won't ever access the component 
parameter anyway. */
-        icon.paintIcon(dummyIconComponent, g, 0, 0);
+        try {
+            icon.paintIcon(dummyIconComponent, g, 0, 0);
+        } catch (ClassCastException ex) {
+            // java.desktop/javax.swing.plaf.metal.OceanTheme$IFIcon.paintIcon 
assumes a different component,
+            // so let's try second most used one type, it satisfies 
AbstractButton, JCheckbox. Not all cases are
+            // covered, however.

Review comment:
       Ugly, but I can't think of a better solution...

##########
File path: platform/openide.util.ui/src/org/openide/util/ImageUtilities.java
##########
@@ -1057,10 +1122,16 @@ private void readObjectNoData() throws 
ObjectStreamException {
         final Icon delegateIcon;
         // May be null.
         final URL url;
+        
+        /**
+         * This is a better ID than URL, as it may not be openable, but it is 
just an ID.
+         */
+        final URI uri;

Review comment:
       Is this really necessary? Keep either an URL or an URI, but not both. 
It'll be really error-prone to maintain them both.

##########
File path: platform/openide.util.ui/src/org/openide/util/ImageUtilities.java
##########
@@ -118,17 +125,26 @@
      * {@code Image}. See comment in {@link #icon2ToolTipImage(Icon, URL)}.
      */
     private static volatile Component dummyIconComponent;
+    
+    /**
+     * Second dummy component. Some {@link Icon#paintIcon(java.awt.Component, 
java.awt.Graphics, int, int)} are very picky and downcast the
+     * Component to a specific subclass. JCheckBox will satisfy checkboxes, 
abstract buttons etc. Will not eliminate all cases, but helps.
+     * 
+     */
+    private static volatile Component dummyIconComponent2;
 
     static {
         /* Could have used Mutex.EVENT.writeAccess here, but it doesn't seem 
to be available during
         testing. */
         if (EventQueue.isDispatchThread()) {
             dummyIconComponent = new JLabel();
+            dummyIconComponent2 = new JButton();

Review comment:
       Maybe rename these dummyIconComponentLabel/dummyIconComponentButton.

##########
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.
+     * 
+     * @param g graphics
+     * @param image image to draw
+     * @param x x coordinate
+     * @param y y coordinate
+     * @param observer the image observer callback.
+     */
+    private static void drawImage(Graphics g, Image image, int x, int y, 
ImageObserver observer) {

Review comment:
       Maybe rename to drawUnwrappedImage?




-- 
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

Reply via email to