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 { |