Revision: 5891
          http://sourceforge.net/p/jump-pilot/code/5891
Author:   ma15569
Date:     2018-06-22 11:57:38 +0000 (Fri, 22 Jun 2018)
Log Message:
-----------
Apply patch to use a default icon id the choosen on does not exist

Modified Paths:
--------------
    core/trunk/src/com/vividsolutions/jump/workbench/ui/images/IconLoader.java

Added Paths:
-----------
    core/trunk/src/com/vividsolutions/jump/workbench/ui/images/default_icon.png

Modified: 
core/trunk/src/com/vividsolutions/jump/workbench/ui/images/IconLoader.java
===================================================================
--- core/trunk/src/com/vividsolutions/jump/workbench/ui/images/IconLoader.java  
2018-06-22 05:39:45 UTC (rev 5890)
+++ core/trunk/src/com/vividsolutions/jump/workbench/ui/images/IconLoader.java  
2018-06-22 11:57:38 UTC (rev 5891)
@@ -1,4 +1,3 @@
-
 /*
  * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI 
  * for visualizing and manipulating spatial features with geometry and 
attributes.
@@ -48,75 +47,97 @@
  * Gets an icon from this class' package.
  */
 public class IconLoader {
-  // cache icons, in case they are requested more than once to speedup OJ start
-  private static HashMap<String, ImageIcon> iconCache = new HashMap<>();
+    // cache icons, in case they are requested more than once to speedup OJ
+    // start
+    private static HashMap<String, ImageIcon> iconCache = new HashMap<>();
 
-  public static ImageIcon icon(String filename) {
-    return getIcon(IconLoader.class.getResource(resolveFile(filename)));
-  }
+    // default icon if the choosen one doesn't exist //
+    // Adapted from Kosmo SAIG
+    public final static ImageIcon DEFAULT_UNKNOW_ICON = new ImageIcon(
+            IconLoader.class.getResource("default_icon.png"));
 
-  public static BufferedImage image(String filename) {
-    ImageIcon icon = getIcon(
-        IconLoader.class.getResource(resolveFile(filename)));
-    Image image = icon.getImage();
+    public static ImageIcon icon(String filename) {
+        ImageIcon icon = null;
+        try {
+            icon = 
getIcon(IconLoader.class.getResource(resolveFile(filename)));
+        } catch (final Exception e) {
+            icon = DEFAULT_UNKNOW_ICON;
+        }
+        return icon;
+    }
 
-    // create a buffered image with transparency
-    BufferedImage bufImg = new BufferedImage(image.getWidth(null),
-        image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
+    // public static ImageIcon icon(String filename) {
+    // return getIcon(IconLoader.class.getResource(resolveFile(filename)));
+    // }
 
-    // draw the image on to the buffered image
-    Graphics2D bGr = bufImg.createGraphics();
-    bGr.drawImage(image, 0, 0, null);
-    bGr.dispose();
+    public static BufferedImage image(String filename) {
+        final ImageIcon icon = getIcon(IconLoader.class
+                .getResource(resolveFile(filename)));
+        final Image image = icon.getImage();
 
-    return bufImg;
-  }
+        // create a buffered image with transparency
+        final BufferedImage bufImg = new BufferedImage(image.getWidth(null),
+                image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
 
-  protected static ImageIcon getIcon(URL url) {
-    // check for null
-    if (url == null)
-      throw new InvalidParameterException("parameter url must not be null.");
+        // draw the image on to the buffered image
+        final Graphics2D bGr = bufImg.createGraphics();
+        bGr.drawImage(image, 0, 0, null);
+        bGr.dispose();
 
-    String key = url.toExternalForm();
-    // System.out.println(key);
-    ImageIcon icon = null;
-    // check cache
-    icon = iconCache.get(key);
-    if (icon != null)
-      return icon;
+        return bufImg;
+    }
 
-    // try loading the image
-    try {
-      // we keep using ImageIcon, as other loaders like ImageIO, commons 
Imaging
-      // choke on our icon gifs currently
-      icon = new ImageIcon(url);
-      // cache the image
-      iconCache.put(key, icon);
-    } catch (Exception e) {
-      Logger.error(e);
+    protected static ImageIcon getIcon(URL url) {
+        // check for null
+        if (url == null) {
+            throw new InvalidParameterException(
+                    "parameter url must not be null.");
+        }
+
+        final String key = url.toExternalForm();
+        // System.out.println(key);
+        ImageIcon icon = null;
+        // check cache
+        icon = iconCache.get(key);
+        if (icon != null) {
+            return icon;
+        }
+
+        // try loading the image
+        try {
+            // we keep using ImageIcon, as other loaders like ImageIO, commons
+            // Imaging
+            // choke on our icon gifs currently
+            icon = new ImageIcon(url);
+            // cache the image
+            iconCache.put(key, icon);
+        } catch (final Exception e) {
+            Logger.error(e);
+        }
+        if (icon == null) {
+            Logger.error("icon '" + key + "' is null!");
+        }
+
+        return icon;
     }
-    if (icon == null)
-      Logger.error("icon '" + key + "' is null!");
 
-    return icon;
-  }
+    /**
+     * utility method to automagically resolve images that moved into their
+     * appropriate iconset subfolders for legacy code
+     * 
+     * @param filename
+     * @return
+     */
+    protected static String resolveFile(String filename) {
+        // iterate over each location, return on first hit
+        for (final String path : new String[] { "", "famfam/", "fugue/" }) {
+            if (IconLoader.class.getResource(path + filename) != null) {
+                return path + filename;
+            }
+        }
 
-  /**
-   * utility method to automagically resolve images that moved into their
-   * appropriate iconset subfolders for legacy code
-   * 
-   * @param filename
-   * @return
-   */
-  protected static String resolveFile(String filename) {
-    // iterate over each location, return on first hit
-    for (String path : new String[] { "", "famfam/", "fugue/" }) {
-      if (IconLoader.class.getResource(path + filename) != null)
-        return path + filename;
+        // if push comes to shove, we let the calling method deal w/ the
+        // consequences, exactly as it was before
+        return filename;
     }
-
-    // if push comes to shove, we let the calling method deal w/ the
-    // consequences, exactly as it was before
-    return filename;
-  }
 }

Added: 
core/trunk/src/com/vividsolutions/jump/workbench/ui/images/default_icon.png
===================================================================
(Binary files differ)

Index: 
core/trunk/src/com/vividsolutions/jump/workbench/ui/images/default_icon.png
===================================================================
--- core/trunk/src/com/vividsolutions/jump/workbench/ui/images/default_icon.png 
2018-06-22 05:39:45 UTC (rev 5890)
+++ core/trunk/src/com/vividsolutions/jump/workbench/ui/images/default_icon.png 
2018-06-22 11:57:38 UTC (rev 5891)

Property changes on: 
core/trunk/src/com/vividsolutions/jump/workbench/ui/images/default_icon.png
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to