Revision: 5896 http://sourceforge.net/p/jump-pilot/code/5896 Author: edso Date: 2018-06-22 14:11:24 +0000 (Fri, 22 Jun 2018) Log Message: ----------- keep original formatting move default icon into saig folder as it came from kosmo (re)implement default icon and make the iconloaders more robust in case icons are missing or not loadable
Modified Paths: -------------- core/trunk/src/com/vividsolutions/jump/workbench/ui/images/IconLoader.java core/trunk/src/com/vividsolutions/jump/workbench/ui/images/famfam/IconLoaderFamFam.java core/trunk/src/org/openjump/core/ui/images/IconLoader.java Added Paths: ----------- core/trunk/src/com/vividsolutions/jump/workbench/ui/images/saig/default_icon.png Removed 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 14:08:57 UTC (rev 5895) +++ core/trunk/src/com/vividsolutions/jump/workbench/ui/images/IconLoader.java 2018-06-22 14:11:24 UTC (rev 5896) @@ -50,14 +50,15 @@ 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<>(); + //default icon if the choosen one doesn't exist from Kosmo SAIG + private static ImageIcon DEFAULT_UNKNOWN_ICON = new ImageIcon(IconLoader.class.getResource("saig/default_icon.png")); public static ImageIcon icon(String filename) { - return getIcon(IconLoader.class.getResource(resolveFile(filename))); + return getIcon(filename); } public static BufferedImage image(String filename) { - ImageIcon icon = getIcon( - IconLoader.class.getResource(resolveFile(filename))); + ImageIcon icon = getIcon(filename); Image image = icon.getImage(); // create a buffered image with transparency @@ -72,21 +73,40 @@ return bufImg; } + protected static ImageIcon getIcon(String filename) { + // automagically search through subfolders + filename = resolveFile(filename); + return getIcon(IconLoader.class, filename); + } + + // utility method for the icon loaders based on this + // like below but protected against null URLs because of non existing files/paths + protected static ImageIcon getIcon(Class clazz, String filename) { + URL url = clazz.getResource(filename); + + // didn't find the file via resource loading + if (url == null) { + Logger.error("Couldn't find '"+filename+"' via resource loading. Returning dummy default icon for now."); + return DEFAULT_UNKNOWN_ICON; + } + + return getIcon(url); + } + protected static ImageIcon getIcon(URL url) { + ImageIcon icon = null; // check for null if (url == null) throw new InvalidParameterException("parameter url must not be null."); 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 { + // check cache + icon = iconCache.get(key); + if (icon != null) + return icon; + // we keep using ImageIcon, as other loaders like ImageIO, commons Imaging // choke on our icon gifs currently icon = new ImageIcon(url); @@ -93,10 +113,9 @@ // cache the image iconCache.put(key, icon); } catch (Exception e) { - Logger.error(e); + icon = DEFAULT_UNKNOWN_ICON; + Logger.error("Error loading '"+key+"'. Using dummy default icon for now.", e); } - if (icon == null) - Logger.error("icon '" + key + "' is null!"); return icon; } @@ -110,7 +129,7 @@ */ protected static String resolveFile(String filename) { // iterate over each location, return on first hit - for (String path : new String[] { "", "famfam/", "fugue/" }) { + for (String path : new String[] { "", "famfam/", "fugue/", "saig/" }) { if (IconLoader.class.getResource(path + filename) != null) return path + filename; } Deleted: core/trunk/src/com/vividsolutions/jump/workbench/ui/images/default_icon.png =================================================================== (Binary files differ) Modified: core/trunk/src/com/vividsolutions/jump/workbench/ui/images/famfam/IconLoaderFamFam.java =================================================================== --- core/trunk/src/com/vividsolutions/jump/workbench/ui/images/famfam/IconLoaderFamFam.java 2018-06-22 14:08:57 UTC (rev 5895) +++ core/trunk/src/com/vividsolutions/jump/workbench/ui/images/famfam/IconLoaderFamFam.java 2018-06-22 14:11:24 UTC (rev 5896) @@ -40,7 +40,10 @@ /** * Gets an icon from this class' package. + * + * @deprecated use com.vividsolutions.jump.workbench.ui.images.IconLoader instead */ +@Deprecated public class IconLoaderFamFam extends IconLoader{ public static ImageIcon icon(String filename) { return getIcon(IconLoaderFamFam.class.getResource(filename)); Copied: core/trunk/src/com/vividsolutions/jump/workbench/ui/images/saig/default_icon.png (from rev 5893, core/trunk/src/com/vividsolutions/jump/workbench/ui/images/default_icon.png) =================================================================== (Binary files differ) Modified: core/trunk/src/org/openjump/core/ui/images/IconLoader.java =================================================================== --- core/trunk/src/org/openjump/core/ui/images/IconLoader.java 2018-06-22 14:08:57 UTC (rev 5895) +++ core/trunk/src/org/openjump/core/ui/images/IconLoader.java 2018-06-22 14:11:24 UTC (rev 5896) @@ -38,9 +38,12 @@ /** * Gets an icon from this class' package. + * + * @deprecated use com.vividsolutions.jump.workbench.ui.images.IconLoader instead */ +@Deprecated public class IconLoader extends com.vividsolutions.jump.workbench.ui.images.IconLoader{ public static ImageIcon icon(String filename) { - return getIcon(IconLoader.class.getResource(filename)); + return getIcon(org.openjump.core.ui.images.IconLoader.class, 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