20 package net.sf.gridarta.model.face;
22 import java.lang.ref.SoftReference;
23 import java.util.HashMap;
25 import javax.swing.ImageIcon;
26 import org.apache.log4j.Category;
27 import org.apache.log4j.Logger;
28 import org.jetbrains.annotations.NotNull;
29 import org.jetbrains.annotations.Nullable;
49 private final Map<String, SoftReference<ImageIcon>>
cache =
new HashMap<>();
54 ImageIcon icon = null;
55 final String realFaceName = String.format(
"%s-%d", faceName, stretch);
56 final SoftReference<ImageIcon> ref = cache.get(realFaceName);
63 cache.put(realFaceName,
new SoftReference<>(icon));
71 if (LOG.isDebugEnabled()) {
72 LOG.debug(
"Clearing image cache.");
84 protected abstract ImageIcon
createImage(@NotNull String faceName,
long stretch);
Abstract Base class for FaceProviders which implements a memory sensitive cache.
This interface represents a lazy loader that provides images on demand.
abstract ImageIcon createImage(@NotNull String faceName, long stretch)
Create an image not found in the cache.
static final Category LOG
The Logger for printing log messages.
final Map< String, SoftReference< ImageIcon > > cache
The HashMap to provide the icons from.
ImageIcon getImageIconForFacename(@NotNull final String faceName, final long stretch)
Get an image from this FaceProvider.
void reload()
Reload faces.