diff -r 768c414c7ce8 openide.util/apichanges.xml --- a/openide.util/apichanges.xml Fri Dec 24 18:32:29 2010 +0300 +++ b/openide.util/apichanges.xml Thu Dec 30 17:49:35 2010 +0100 @@ -51,6 +51,23 @@ Actions API + + + ImageUtilities support "url" attribute + + + + + +

+ Images loaded by + ImageUtilities.loadImage now + respond to getProperty("url", null) calls. +

+
+ + +
New implementation of WeakSet with two new methods putIfAbsent and resize diff -r 768c414c7ce8 openide.util/manifest.mf --- a/openide.util/manifest.mf Fri Dec 24 18:32:29 2010 +0300 +++ b/openide.util/manifest.mf Thu Dec 30 17:49:35 2010 +0100 @@ -1,5 +1,5 @@ Manifest-Version: 1.0 OpenIDE-Module: org.openide.util OpenIDE-Module-Localizing-Bundle: org/openide/util/Bundle.properties -OpenIDE-Module-Specification-Version: 8.11 +OpenIDE-Module-Specification-Version: 8.12 diff -r 768c414c7ce8 openide.util/src/org/openide/util/ImageUtilities.java --- a/openide.util/src/org/openide/util/ImageUtilities.java Fri Dec 24 18:32:29 2010 +0300 +++ b/openide.util/src/org/openide/util/ImageUtilities.java Thu Dec 30 17:49:35 2010 +0100 @@ -61,6 +61,7 @@ import java.awt.image.WritableRaster; import java.io.IOException; import java.lang.ref.SoftReference; +import java.net.URL; import java.util.HashMap; import java.util.HashSet; import java.util.Hashtable; @@ -139,6 +140,9 @@ * or org/netbeans/modules/foo/resources/foo_mybranding.gif. * *

Caching of loaded images can be used internally to improve performance. + *

Since version 8.12 the returned image object responds to call + * image.getProperty("url", null) by returning the internal + * {@link URL} of the found and loaded resource. * * @param resource resource path of the image (no initial slash) * @param localized true for localized search @@ -245,7 +249,7 @@ return cached; } } - cached = ToolTipImage.createNew(text, image); + cached = ToolTipImage.createNew(text, image, null); imageToolTipCache.put(key, new ActiveRef(cached, imageToolTipCache, key)); return cached; } @@ -527,7 +531,7 @@ ERR.log(Level.FINE, "loading icon {0} = {1}", new Object[] {n, result}); name = new String(name).intern(); // NOPMD - result = ToolTipImage.createNew("", result); + result = ToolTipImage.createNew("", result, url); cache.put(name, new ActiveRef(result, cache, name)); return result; } else { // no icon found @@ -601,7 +605,7 @@ ColorModel model = colorModel(bitmask? Transparency.BITMASK: Transparency.TRANSLUCENT); ToolTipImage buffImage = new ToolTipImage(str.toString(), - model, model.createCompatibleWritableRaster(w, h), model.isAlphaPremultiplied(), null + model, model.createCompatibleWritableRaster(w, h), model.isAlphaPremultiplied(), null, null ); java.awt.Graphics g = buffImage.createGraphics(); @@ -738,14 +742,20 @@ private static class ToolTipImage extends BufferedImage implements Icon { final String toolTipText; ImageIcon imageIcon; + final URL url; - public static ToolTipImage createNew(String toolTipText, Image image) { + public static ToolTipImage createNew(String toolTipText, Image image, URL url) { ImageUtilities.ensureLoaded(image); boolean bitmask = (image instanceof Transparency) && ((Transparency) image).getTransparency() != Transparency.TRANSLUCENT; ColorModel model = colorModel(bitmask ? Transparency.BITMASK : Transparency.TRANSLUCENT); int w = image.getWidth(null); int h = image.getHeight(null); - ToolTipImage newImage = new ToolTipImage(toolTipText, model, model.createCompatibleWritableRaster(w, h), model.isAlphaPremultiplied(), null); + ToolTipImage newImage = new ToolTipImage( + toolTipText, + model, + model.createCompatibleWritableRaster(w, h), + model.isAlphaPremultiplied(), null, url + ); java.awt.Graphics g = newImage.createGraphics(); g.drawImage(image, 0, 0, null); @@ -753,26 +763,21 @@ return newImage; } - public ToolTipImage(String toolTipText, ColorModel cm, WritableRaster raster, boolean isRasterPremultiplied, Hashtable properties) { + public ToolTipImage( + String toolTipText, ColorModel cm, WritableRaster raster, + boolean isRasterPremultiplied, Hashtable properties, URL url + ) { super(cm, raster, isRasterPremultiplied, properties); this.toolTipText = toolTipText; - } - - public ToolTipImage(String toolTipText, int width, int height, int imageType, IndexColorModel cm) { - super(width, height, imageType, cm); - this.toolTipText = toolTipText; + this.url = url; } public ToolTipImage(String toolTipText, int width, int height, int imageType) { super(width, height, imageType); this.toolTipText = toolTipText; + this.url = null; } - public ToolTipImage(String toolTipText, BufferedImage image) { - super(image.getWidth(), image.getHeight(), image.getType()); - this.toolTipText = toolTipText; - } - synchronized ImageIcon getIcon() { if (imageIcon == null) { imageIcon = new ImageIcon(this); @@ -791,6 +796,18 @@ public void paintIcon(Component c, Graphics g, int x, int y) { g.drawImage(this, x, y, null); } + + @Override + public Object getProperty(String name, ImageObserver observer) { + if ("url".equals(name)) { // NOI18N + if (url != null) { + return url; + } else { + return imageIcon.getImage().getProperty("url", observer); + } + } + return super.getProperty(name, observer); + } } private static class LazyDisabledIcon implements Icon { diff -r 768c414c7ce8 openide.util/test/unit/src/org/openide/util/ImageUtilitiesTest.java --- a/openide.util/test/unit/src/org/openide/util/ImageUtilitiesTest.java Fri Dec 24 18:32:29 2010 +0300 +++ b/openide.util/test/unit/src/org/openide/util/ImageUtilitiesTest.java Thu Dec 30 17:49:35 2010 +0100 @@ -47,6 +47,7 @@ import java.awt.Image; import java.awt.Transparency; import java.awt.image.BufferedImage; +import java.net.URL; import javax.swing.Icon; import junit.framework.*; @@ -180,11 +181,17 @@ assertNotNull("Should not be null", icon); assertNotNull("Should not be null", image); + URL u = getClass().getResource("/org/openide/util/testimage.png"); + assertNotNull("URL found", u); + assertEquals("URL obtained", u, image.getProperty("url", null)); + Icon icon2 = ImageUtilities.image2Icon(image); Image image2 = ImageUtilities.icon2Image(icon); assertEquals("Should be same instance", icon, icon2); assertEquals("Should be same instance", image, image2); + + assertEquals("Url is still there", u, image2.getProperty("url", null)); } public void testLoadingNonExisting() {