You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2018/11/20 09:32:05 UTC

[GitHub] sdedic closed pull request #942: Attempt to load PNG for legacy GIFs

sdedic closed pull request #942: Attempt to load PNG for legacy GIFs
URL: https://github.com/apache/incubator-netbeans/pull/942
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/platform/openide.util.ui/src/org/openide/util/ImageUtilities.java b/platform/openide.util.ui/src/org/openide/util/ImageUtilities.java
index c90164e8b0..0a0868c51e 100644
--- a/platform/openide.util.ui/src/org/openide/util/ImageUtilities.java
+++ b/platform/openide.util.ui/src/org/openide/util/ImageUtilities.java
@@ -19,7 +19,6 @@
 
 package org.openide.util;
 
-import java.awt.Color;
 import java.awt.Component;
 import java.awt.Graphics;
 import java.awt.HeadlessException;
@@ -32,7 +31,6 @@
 import java.awt.image.FilteredImageSource;
 import java.awt.image.ImageObserver;
 import java.awt.image.ImageProducer;
-import java.awt.image.IndexColorModel;
 import java.awt.image.RGBImageFilter;
 import java.awt.image.WritableRaster;
 import java.io.IOException;
@@ -64,7 +62,7 @@
 public final class ImageUtilities {
 
     private static final Logger LOGGER = Logger.getLogger(ImageUtilities.class.getName());
-
+    
     /** separator for individual parts of tool tip text */
     static final String TOOLTIP_SEPAR = "<br>"; // NOI18N
     /** a value that indicates that the icon does not exists */
@@ -528,16 +526,24 @@ private static Image getIcon(String name, ClassLoader loader, boolean localizedQ
                 warn = false;
                 n = name;
             }
+            
+            String tryName = n;
+            if (n.endsWith(".gif") && n.length() > 4) { // NOI8N
+                tryName = n.substring(0, n.length() - 4) + ".png"; // NOI18N
+            }
 
             // we have to load it
-            java.net.URL url = (loader != null) ? loader.getResource(n)
-                                                : ImageUtilities.class.getClassLoader().getResource(n);
-
-//            img = (url == null) ? null : Toolkit.getDefaultToolkit().createImage(url);
+            java.net.URL url = (loader != null) ? loader.getResource(tryName)
+                                                : ImageUtilities.class.getClassLoader().getResource(tryName);
+            if (url == null && n != tryName) { 
+                tryName = n;
+                url = (loader != null) ? loader.getResource(tryName)
+                                                : ImageUtilities.class.getClassLoader().getResource(tryName);
+            }
             Image result = null;
             try {
                 if (url != null) {
-                    if (name.endsWith(".png")) {
+                    if (tryName.endsWith(".png")) {
                         ImageInputStream stream = ImageIO.createImageInputStream(url.openStream());
                         ImageReadParam param = PNG_READER.getDefaultReadParam();
                         try {
@@ -545,7 +551,7 @@ private static Image getIcon(String name, ClassLoader loader, boolean localizedQ
                             result = PNG_READER.read(0, param);
                         }
                         catch (IOException ioe1) {
-                            ERR.log(Level.INFO, "Image "+name+" is not PNG", ioe1);
+                            ERR.log(Level.INFO, "Image " + tryName + " is not PNG", ioe1);
                         }
                         stream.close();
                     } 
diff --git a/platform/openide.util.ui/test/unit/src/org/openide/util/ImageUtilitiesTest.java b/platform/openide.util.ui/test/unit/src/org/openide/util/ImageUtilitiesTest.java
index 087a49d61b..6b8c52cf90 100644
--- a/platform/openide.util.ui/test/unit/src/org/openide/util/ImageUtilitiesTest.java
+++ b/platform/openide.util.ui/test/unit/src/org/openide/util/ImageUtilitiesTest.java
@@ -279,4 +279,16 @@ public void testLoadDarkImage() {
         icon = ImageUtilities.loadImageIcon("org/openide/util/darkicon.png", true);
         assertEquals("The default icon is 16x16 pixels", 16, icon.getIconWidth());
     }
+    
+    /**
+     * Checks that .gif request falls back on .png image, if the requested
+     * format is not present
+     */
+    public void testLoadPngImageInsteadOfMissingGif() {
+        Image img = ImageUtilities.loadImage("org/openide/util/gifimage.gif");
+        assertEquals(17, img.getWidth(null));
+        
+        img = ImageUtilities.loadImage("org/openide/util/gifimage2.gif");
+        assertEquals(16, img.getWidth(null));
+    }
 }
diff --git a/platform/openide.util.ui/test/unit/src/org/openide/util/gifimage.gif b/platform/openide.util.ui/test/unit/src/org/openide/util/gifimage.gif
new file mode 100644
index 0000000000..e1a53fd267
Binary files /dev/null and b/platform/openide.util.ui/test/unit/src/org/openide/util/gifimage.gif differ
diff --git a/platform/openide.util.ui/test/unit/src/org/openide/util/gifimage.png b/platform/openide.util.ui/test/unit/src/org/openide/util/gifimage.png
new file mode 100644
index 0000000000..d239c4e675
Binary files /dev/null and b/platform/openide.util.ui/test/unit/src/org/openide/util/gifimage.png differ
diff --git a/platform/openide.util.ui/test/unit/src/org/openide/util/gifimage2.gif b/platform/openide.util.ui/test/unit/src/org/openide/util/gifimage2.gif
new file mode 100644
index 0000000000..e1a53fd267
Binary files /dev/null and b/platform/openide.util.ui/test/unit/src/org/openide/util/gifimage2.gif differ


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists