Revision: 5894 http://sourceforge.net/p/jump-pilot/code/5894 Author: ma15569 Date: 2018-06-22 13:06:33 +0000 (Fri, 22 Jun 2018) Log Message: ----------- new modification
Modified Paths: -------------- core/trunk/src/com/vividsolutions/jump/workbench/ui/images/IconLoader.java 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 12:49:54 UTC (rev 5893) +++ core/trunk/src/com/vividsolutions/jump/workbench/ui/images/IconLoader.java 2018-06-22 13:06:33 UTC (rev 5894) @@ -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,88 @@ * 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) { + return getIcon(IconLoader.class.getResource(resolveFile(filename))); + } - // create a buffered image with transparency - BufferedImage bufImg = new BufferedImage(image.getWidth(null), - image.getHeight(null), BufferedImage.TYPE_INT_ARGB); + public static BufferedImage image(String filename) { + final ImageIcon icon = getIcon(IconLoader.class + .getResource(resolveFile(filename))); + final Image image = icon.getImage(); - // draw the image on to the buffered image - Graphics2D bGr = bufImg.createGraphics(); - bGr.drawImage(image, 0, 0, null); - bGr.dispose(); + // create a buffered image with transparency + final BufferedImage bufImg = new BufferedImage(image.getWidth(null), + image.getHeight(null), BufferedImage.TYPE_INT_ARGB); - return bufImg; - } + // draw the image on to the buffered image + final Graphics2D bGr = bufImg.createGraphics(); + bGr.drawImage(image, 0, 0, null); + bGr.dispose(); - protected static ImageIcon getIcon(URL url) { - // check for null - if (url == null) - throw new InvalidParameterException("parameter url must not be null."); + return bufImg; + } - String key = url.toExternalForm(); - // System.out.println(key); - ImageIcon icon = null; - // check cache - icon = iconCache.get(key); - if (icon != null) - return icon; + protected static ImageIcon getIcon(URL url) { + // check for null + if (url == null) { + throw new InvalidParameterException( + "parameter url must not be null."); + } - // 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); + 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) { + icon = DEFAULT_UNKNOW_ICON; + 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; - } } ------------------------------------------------------------------------------ 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