|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.refractions.udig.ui.ImageCache
public final class ImageCache
A weakly referenced cache of image descriptors to arrays of image instances
(representing normal, gray and disabled images). This is used to hold images
in memory while their descriptors are defined. When the image descriptors
become weakly referred to, the corresponding images in the array of images
will be disposed.
Weak references of equivalent image descriptors are mapped to the same array
of images (where equivalent descriptors are equals(Object)
).
It is recommended to use this class as a singleton, since it creates a thread
for cleaning out images.
It is the responsibility of the user to ensure that the image descriptors are
kept around as long as the images are needed. The users of this cache should
not explicitly dispose the images.
Upon request of a disabled or gray image, the normal image will be created as
well (if it was not already in the cache) in order to create the disabled or
gray version of the image.
This cache makes no guarantees on how long the cleaning process will take, or
when exactly it will occur.
This class may be instantiated; it is not intended to be subclassed.
Field Summary | |
---|---|
static int |
DISABLE
Types of images supported by the image cache. |
static int |
GRAY
|
static int |
REGULAR
|
Constructor Summary | |
---|---|
ImageCache()
Constructs a new instance of ImageCache , and starts a
thread to monitor the reference queue for image clean up. |
|
ImageCache(int initialLoadCapacity)
Constructs a new instance of ImageCache , and starts a
thread to monitor the reference queue for image clean up. |
|
ImageCache(int initialLoadCapacity,
float loadFactor)
Constructs a new instance of ImageCache , and starts a
thread to monitor the reference queue for image clean up. |
Method Summary | |
---|---|
void |
dispose()
Cleans up all images in the cache. |
Image |
getImage(ImageDescriptor imageDescriptor)
Returns the regular image for the given image descriptor. |
Image |
getImage(ImageDescriptor imageDescriptor,
int typeOfImage)
Returns the requested image for the given image descriptor and image type. |
Image |
getMissingImage()
Returns the image to display when no image can be found, or none is specified. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DISABLE
public static final int GRAY
public static final int REGULAR
Constructor Detail |
---|
public ImageCache()
ImageCache
, and starts a
thread to monitor the reference queue for image clean up.
public ImageCache(int initialLoadCapacity)
ImageCache
, and starts a
thread to monitor the reference queue for image clean up. If the passed
initial load capacity is negative, the image map is created with the
default HashMap
constructor.
initialLoadCapacity
- Initial load capacity for the image hash map.public ImageCache(int initialLoadCapacity, float loadFactor)
ImageCache
, and starts a
thread to monitor the reference queue for image clean up. If the passed
initial load capacity is negative or if the load factor is nonpositive,
the image map is created with the default HashMap
constructor.
initialLoadCapacity
- Initial load capacity for the image hash map.loadFactor
- Load factor for the image hash map.Method Detail |
---|
public final void dispose()
public final Image getImage(ImageDescriptor imageDescriptor)
descriptor
- The image descriptor with which a regular image should be
created; may be null
.
null
if the image descriptor passed in is
null
. Note that a missing image will be returned
if a problem occurs in the creation of the image.public final Image getImage(ImageDescriptor imageDescriptor, int typeOfImage)
descriptor
- The image descriptor with which the requested image should be
created; may be null
.typeOfImage
- The type of the desired image:
ImageCache.DISABLED
,
ImageCache.GRAY
or
ImageCache.NORMAL
.
null
if the image
descriptor passed in is null
, or if the image
type is invalid. Note that a missing image will be returned if a
problem occurs in the creation of the image.public final Image getMissingImage()
null
.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |