Lines 61-66
Link Here
|
61 |
import java.awt.image.RGBImageFilter; |
61 |
import java.awt.image.RGBImageFilter; |
62 |
import java.awt.image.WritableRaster; |
62 |
import java.awt.image.WritableRaster; |
63 |
import java.io.IOException; |
63 |
import java.io.IOException; |
|
|
64 |
import java.lang.ref.Reference; |
64 |
import java.lang.ref.SoftReference; |
65 |
import java.lang.ref.SoftReference; |
65 |
import java.net.URL; |
66 |
import java.net.URL; |
66 |
import java.util.HashMap; |
67 |
import java.util.HashMap; |
Lines 90-101
Link Here
|
90 |
/** separator for individual parts of tool tip text */ |
91 |
/** separator for individual parts of tool tip text */ |
91 |
static final String TOOLTIP_SEPAR = "<br>"; // NOI18N |
92 |
static final String TOOLTIP_SEPAR = "<br>"; // NOI18N |
92 |
/** a value that indicates that the icon does not exists */ |
93 |
/** a value that indicates that the icon does not exists */ |
93 |
private static final ActiveRef<String> NO_ICON = new ActiveRef<String>(null, null, null); |
94 |
private static final Reference<Image> NO_ICON = new SoftReference<Image>(null); |
94 |
|
95 |
|
95 |
private static final Map<String,ActiveRef<String>> cache = new HashMap<String,ActiveRef<String>>(128); |
96 |
private static final Map<String,Reference<Image>> cache = new HashMap<String,Reference<Image>>(128); |
96 |
private static final Map<String,ActiveRef<String>> localizedCache = new HashMap<String,ActiveRef<String>>(128); |
97 |
private static final Map<String,Reference<Image>> localizedCache = new HashMap<String,Reference<Image>>(128); |
97 |
private static final Map<CompositeImageKey,ActiveRef<CompositeImageKey>> compositeCache = new HashMap<CompositeImageKey,ActiveRef<CompositeImageKey>>(128); |
98 |
private static final Map<CompositeImageKey,Reference<Image>> compositeCache = new HashMap<CompositeImageKey,Reference<Image>>(128); |
98 |
private static final Map<ToolTipImageKey, ActiveRef<ToolTipImageKey>> imageToolTipCache = new HashMap<ToolTipImageKey, ActiveRef<ToolTipImageKey>>(128); |
99 |
private static final Map<ToolTipImageKey, Reference<Image>> imageToolTipCache = new HashMap<ToolTipImageKey, Reference<Image>>(128); |
99 |
|
100 |
|
100 |
private static RGBImageFilter imageIconFilter = null; |
101 |
private static RGBImageFilter imageIconFilter = null; |
101 |
|
102 |
|
Lines 251-257
Link Here
|
251 |
Image cached; |
252 |
Image cached; |
252 |
|
253 |
|
253 |
synchronized (compositeCache) { |
254 |
synchronized (compositeCache) { |
254 |
ActiveRef<CompositeImageKey> r = compositeCache.get(k); |
255 |
Reference<Image> r = compositeCache.get(k); |
255 |
if (r != null) { |
256 |
if (r != null) { |
256 |
cached = r.get(); |
257 |
cached = r.get(); |
257 |
if (cached != null) { |
258 |
if (cached != null) { |
Lines 307-313
Link Here
|
307 |
ToolTipImageKey key = new ToolTipImageKey(image, text); |
308 |
ToolTipImageKey key = new ToolTipImageKey(image, text); |
308 |
Image cached; |
309 |
Image cached; |
309 |
synchronized (imageToolTipCache) { |
310 |
synchronized (imageToolTipCache) { |
310 |
ActiveRef<ToolTipImageKey> r = imageToolTipCache.get(key); |
311 |
Reference<Image> r = imageToolTipCache.get(key); |
311 |
if (r != null) { |
312 |
if (r != null) { |
312 |
cached = r.get(); |
313 |
cached = r.get(); |
313 |
if (cached != null) { |
314 |
if (cached != null) { |
Lines 424-430
Link Here
|
424 |
static Image getIcon(String resource, boolean localized) { |
425 |
static Image getIcon(String resource, boolean localized) { |
425 |
if (localized) { |
426 |
if (localized) { |
426 |
synchronized (localizedCache) { |
427 |
synchronized (localizedCache) { |
427 |
ActiveRef<String> ref = localizedCache.get(resource); |
428 |
Reference<Image> ref = localizedCache.get(resource); |
428 |
Image img = null; |
429 |
Image img = null; |
429 |
|
430 |
|
430 |
// no icon for this name (already tested) |
431 |
// no icon for this name (already tested) |
Lines 495-501
Link Here
|
495 |
* and is not optimized/interned |
496 |
* and is not optimized/interned |
496 |
*/ |
497 |
*/ |
497 |
private static Image getIcon(String name, ClassLoader loader, boolean localizedQuery) { |
498 |
private static Image getIcon(String name, ClassLoader loader, boolean localizedQuery) { |
498 |
ActiveRef<String> ref = cache.get(name); |
499 |
Reference<Image> ref = cache.get(name); |
499 |
Image img = null; |
500 |
Image img = null; |
500 |
|
501 |
|
501 |
// no icon for this name (already tested) |
502 |
// no icon for this name (already tested) |
Lines 791-802
Link Here
|
791 |
} |
792 |
} |
792 |
|
793 |
|
793 |
/** Cleaning reference. */ |
794 |
/** Cleaning reference. */ |
794 |
private static final class ActiveRef<T> extends SoftReference<Image> implements Runnable { |
795 |
private static final class ActiveRef<T> extends CallbackReferences.SoftCallback<Image> { |
795 |
private final Map<T,ActiveRef<T>> holder; |
796 |
private final Map<T,Reference<Image>> holder; |
796 |
private final T key; |
797 |
private final T key; |
797 |
|
798 |
|
798 |
public ActiveRef(Image o, Map<T,ActiveRef<T>> holder, T key) { |
799 |
public ActiveRef(Image o, Map<T,Reference<Image>> holder, T key) { |
799 |
super(o, Utilities.activeReferenceQueue()); |
800 |
super(o); |
800 |
this.holder = holder; |
801 |
this.holder = holder; |
801 |
this.key = key; |
802 |
this.key = key; |
802 |
} |
803 |
} |