This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 193944
Collapse All | Expand All

(-)a/openide.util/apichanges.xml (+17 lines)
Lines 51-56 Link Here
51
    <apidef name="actions">Actions API</apidef>
51
    <apidef name="actions">Actions API</apidef>
52
</apidefs>
52
</apidefs>
53
<changes>
53
<changes>
54
    <change id="ImageUtilities.URL">
55
        <api name="util"/>
56
        <summary>ImageUtilities support "url" attribute</summary>
57
        <version major="8" minor="12"/>
58
        <date day="10" month="1" year="2011"/>
59
        <author login="jtulach"/>
60
        <compatibility addition="yes"/>
61
        <description>
62
            <p>
63
            Images loaded by <a href="@TOP@/org/openide/util/ImageUtilities.html#loadImage(java.lang.String,%20boolean)">
64
            ImageUtilities.loadImage</a> now
65
            respond to <code>getProperty("url", null)</code> calls.
66
            </p>
67
        </description>
68
        <class package="org.openide.util" name="ImageUtilities"/>
69
        <issue number="193944"/>
70
    </change>
54
    <change id="WeakSet.putIfAbsent">
71
    <change id="WeakSet.putIfAbsent">
55
        <api name="util"/>
72
        <api name="util"/>
56
        <summary>New implementation of WeakSet with two new methods <code>putIfAbsent</code> and <code>resize</code>
73
        <summary>New implementation of WeakSet with two new methods <code>putIfAbsent</code> and <code>resize</code>
(-)a/openide.util/manifest.mf (-1 / +1 lines)
Lines 1-5 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.openide.util
2
OpenIDE-Module: org.openide.util
3
OpenIDE-Module-Localizing-Bundle: org/openide/util/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/openide/util/Bundle.properties
4
OpenIDE-Module-Specification-Version: 8.11
4
OpenIDE-Module-Specification-Version: 8.12
5
5
(-)a/openide.util/src/org/openide/util/ImageUtilities.java (-16 / +33 lines)
Lines 61-66 Link Here
61
import java.awt.image.WritableRaster;
61
import java.awt.image.WritableRaster;
62
import java.io.IOException;
62
import java.io.IOException;
63
import java.lang.ref.SoftReference;
63
import java.lang.ref.SoftReference;
64
import java.net.URL;
64
import java.util.HashMap;
65
import java.util.HashMap;
65
import java.util.HashSet;
66
import java.util.HashSet;
66
import java.util.Hashtable;
67
import java.util.Hashtable;
Lines 139-144 Link Here
139
     * or <samp>org/netbeans/modules/foo/resources/foo_mybranding.gif</samp>.
140
     * or <samp>org/netbeans/modules/foo/resources/foo_mybranding.gif</samp>.
140
     * 
141
     * 
141
     * <p>Caching of loaded images can be used internally to improve performance.
142
     * <p>Caching of loaded images can be used internally to improve performance.
143
     * <p> Since version 8.12 the returned image object responds to call
144
     * <code>image.getProperty("url", null)</code> by returning the internal
145
     * {@link URL} of the found and loaded <code>resource</code>.
142
     * 
146
     * 
143
     * @param resource resource path of the image (no initial slash)
147
     * @param resource resource path of the image (no initial slash)
144
     * @param localized true for localized search
148
     * @param localized true for localized search
Lines 245-251 Link Here
245
                    return cached;
249
                    return cached;
246
                }
250
                }
247
            }
251
            }
248
            cached = ToolTipImage.createNew(text, image);
252
            cached = ToolTipImage.createNew(text, image, null);
249
            imageToolTipCache.put(key, new ActiveRef<ToolTipImageKey>(cached, imageToolTipCache, key));
253
            imageToolTipCache.put(key, new ActiveRef<ToolTipImageKey>(cached, imageToolTipCache, key));
250
            return cached;
254
            return cached;
251
        }
255
        }
Lines 527-533 Link Here
527
531
528
                ERR.log(Level.FINE, "loading icon {0} = {1}", new Object[] {n, result});
532
                ERR.log(Level.FINE, "loading icon {0} = {1}", new Object[] {n, result});
529
                name = new String(name).intern(); // NOPMD
533
                name = new String(name).intern(); // NOPMD
530
                result = ToolTipImage.createNew("", result);
534
                result = ToolTipImage.createNew("", result, url);
531
                cache.put(name, new ActiveRef<String>(result, cache, name));
535
                cache.put(name, new ActiveRef<String>(result, cache, name));
532
                return result;
536
                return result;
533
            } else { // no icon found
537
            } else { // no icon found
Lines 601-607 Link Here
601
        
605
        
602
        ColorModel model = colorModel(bitmask? Transparency.BITMASK: Transparency.TRANSLUCENT);
606
        ColorModel model = colorModel(bitmask? Transparency.BITMASK: Transparency.TRANSLUCENT);
603
        ToolTipImage buffImage = new ToolTipImage(str.toString(), 
607
        ToolTipImage buffImage = new ToolTipImage(str.toString(), 
604
                model, model.createCompatibleWritableRaster(w, h), model.isAlphaPremultiplied(), null
608
                model, model.createCompatibleWritableRaster(w, h), model.isAlphaPremultiplied(), null, null
605
            );
609
            );
606
610
607
        java.awt.Graphics g = buffImage.createGraphics();
611
        java.awt.Graphics g = buffImage.createGraphics();
Lines 738-751 Link Here
738
    private static class ToolTipImage extends BufferedImage implements Icon {
742
    private static class ToolTipImage extends BufferedImage implements Icon {
739
        final String toolTipText;
743
        final String toolTipText;
740
        ImageIcon imageIcon;
744
        ImageIcon imageIcon;
745
        final URL url;
741
746
742
        public static ToolTipImage createNew(String toolTipText, Image image) {
747
        public static ToolTipImage createNew(String toolTipText, Image image, URL url) {
743
            ImageUtilities.ensureLoaded(image);
748
            ImageUtilities.ensureLoaded(image);
744
            boolean bitmask = (image instanceof Transparency) && ((Transparency) image).getTransparency() != Transparency.TRANSLUCENT;
749
            boolean bitmask = (image instanceof Transparency) && ((Transparency) image).getTransparency() != Transparency.TRANSLUCENT;
745
            ColorModel model = colorModel(bitmask ? Transparency.BITMASK : Transparency.TRANSLUCENT);
750
            ColorModel model = colorModel(bitmask ? Transparency.BITMASK : Transparency.TRANSLUCENT);
746
            int w = image.getWidth(null);
751
            int w = image.getWidth(null);
747
            int h = image.getHeight(null);
752
            int h = image.getHeight(null);
748
            ToolTipImage newImage = new ToolTipImage(toolTipText, model, model.createCompatibleWritableRaster(w, h), model.isAlphaPremultiplied(), null);
753
            ToolTipImage newImage = new ToolTipImage(
754
                toolTipText,
755
                model,
756
                model.createCompatibleWritableRaster(w, h),
757
                model.isAlphaPremultiplied(), null, url
758
            );
749
759
750
            java.awt.Graphics g = newImage.createGraphics();
760
            java.awt.Graphics g = newImage.createGraphics();
751
            g.drawImage(image, 0, 0, null);
761
            g.drawImage(image, 0, 0, null);
Lines 753-778 Link Here
753
            return newImage;
763
            return newImage;
754
        }
764
        }
755
        
765
        
756
        public ToolTipImage(String toolTipText, ColorModel cm, WritableRaster raster, boolean isRasterPremultiplied, Hashtable<?, ?> properties) {
766
        public ToolTipImage(
767
            String toolTipText, ColorModel cm, WritableRaster raster,
768
            boolean isRasterPremultiplied, Hashtable<?, ?> properties, URL url
769
        ) {
757
            super(cm, raster, isRasterPremultiplied, properties);
770
            super(cm, raster, isRasterPremultiplied, properties);
758
            this.toolTipText = toolTipText;
771
            this.toolTipText = toolTipText;
759
        }
772
            this.url = url;
760
761
        public ToolTipImage(String toolTipText, int width, int height, int imageType, IndexColorModel cm) {
762
            super(width, height, imageType, cm);
763
            this.toolTipText = toolTipText;
764
        }
773
        }
765
774
766
        public ToolTipImage(String toolTipText, int width, int height, int imageType) {
775
        public ToolTipImage(String toolTipText, int width, int height, int imageType) {
767
            super(width, height, imageType);
776
            super(width, height, imageType);
768
            this.toolTipText = toolTipText;
777
            this.toolTipText = toolTipText;
778
            this.url = null;
769
        }
779
        }
770
        
780
        
771
        public ToolTipImage(String toolTipText, BufferedImage image) {
772
            super(image.getWidth(), image.getHeight(), image.getType());
773
            this.toolTipText = toolTipText;
774
        }
775
776
        synchronized ImageIcon getIcon() {
781
        synchronized ImageIcon getIcon() {
777
            if (imageIcon == null) {
782
            if (imageIcon == null) {
778
                imageIcon = new ImageIcon(this);
783
                imageIcon = new ImageIcon(this);
Lines 791-796 Link Here
791
        public void paintIcon(Component c, Graphics g, int x, int y) {
796
        public void paintIcon(Component c, Graphics g, int x, int y) {
792
            g.drawImage(this, x, y, null);
797
            g.drawImage(this, x, y, null);
793
        }
798
        }
799
800
        @Override
801
        public Object getProperty(String name, ImageObserver observer) {
802
            if ("url".equals(name)) { // NOI18N
803
                if (url != null) {
804
                    return url;
805
                } else {
806
                    return imageIcon.getImage().getProperty("url", observer);
807
                }
808
            }
809
            return super.getProperty(name, observer);
810
        }
794
    }
811
    }
795
812
796
    private static class LazyDisabledIcon implements Icon {
813
    private static class LazyDisabledIcon implements Icon {
(-)a/openide.util/test/unit/src/org/openide/util/ImageUtilitiesTest.java (+7 lines)
Lines 47-52 Link Here
47
import java.awt.Image;
47
import java.awt.Image;
48
import java.awt.Transparency;
48
import java.awt.Transparency;
49
import java.awt.image.BufferedImage;
49
import java.awt.image.BufferedImage;
50
import java.net.URL;
50
import javax.swing.Icon;
51
import javax.swing.Icon;
51
import junit.framework.*;
52
import junit.framework.*;
52
53
Lines 180-190 Link Here
180
        assertNotNull("Should not be null", icon);
181
        assertNotNull("Should not be null", icon);
181
        assertNotNull("Should not be null", image);
182
        assertNotNull("Should not be null", image);
182
183
184
        URL u = getClass().getResource("/org/openide/util/testimage.png");
185
        assertNotNull("URL found", u);
186
        assertEquals("URL obtained", u, image.getProperty("url", null));
187
183
        Icon icon2 = ImageUtilities.image2Icon(image);
188
        Icon icon2 = ImageUtilities.image2Icon(image);
184
        Image image2 = ImageUtilities.icon2Image(icon);
189
        Image image2 = ImageUtilities.icon2Image(icon);
185
190
186
        assertEquals("Should be same instance", icon, icon2);
191
        assertEquals("Should be same instance", icon, icon2);
187
        assertEquals("Should be same instance", image, image2);
192
        assertEquals("Should be same instance", image, image2);
193
194
        assertEquals("Url is still there", u, image2.getProperty("url", null));
188
    }
195
    }
189
196
190
    public void testLoadingNonExisting() {
197
    public void testLoadingNonExisting() {

Return to bug 193944