APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.swing.plaf.nimbus

pack-priv Class ImageCache

extends Object
Class Inheritance
Imports
java.awt.GraphicsConfiguration, .Image, java.lang.ref.ReferenceQueue, .SoftReference, java.util.Arrays, .Iterator, .LinkedHashMap, .Map, java.util.concurrent.locks.ReadWriteLock, .ReentrantReadWriteLock

ImageCache - A fixed pixel count sized cache of Images keyed by arbitrary set of arguments. All images are held with SoftReferences so they will be dropped by the GC if heap memory gets tight. When our size hits max pixel count least recently requested images are removed first.
Author
Created by Jasper Potts (Aug 7, 2007)

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
ImageCache.PixelCountSoftReference

Extended SoftReference that stores the pixel count even after the image is lost

Field Summary

Modifier and TypeField and Description
private int
private static final ImageCache
private ReadWriteLock
private final LinkedHashMap<Integer, ImageCache.PixelCountSoftReference>
private final int
private final int
private ReferenceQueue<Image>

Constructor Summary

AccessConstructor and Description
public
public
ImageCache(int maxPixelCount, int maxSingleImagePixelSize)

Method Summary

Modifier and TypeMethod and Description
public void
flush()

Clear the cache

public Image

Returns:

Returns the cached Image, or null there is no cached image for key
getImage
(GraphicsConfiguration
The graphics configuration, needed if cached image is a Volatile Image. Used as part of cache key
config
,
int
The image width, used as part of cache key
w
,
int
The image height, used as part of cache key
h
,
Object...
Other arguments to use as part of the cache key
args
)

Get the cached image for given keys

pack-priv static ImageCache
getInstance()

Get static singleton instance

private int
hash(GraphicsConfiguration config, int w, int h, Object... args)

Create a unique hash from all the input

public boolean

Returns:

True if the image size is less than max
isImageCachable
(int
The image width
w
,
int
The image height
h
)

Check if the image size is to big to be stored in the cache

public boolean

Returns:

true if the image could be cached or false if the image is too big
setImage
(Image
The image to store in cache
image
,
GraphicsConfiguration
The graphics configuration, needed if cached image is a Volatile Image. Used as part of cache key
config
,
int
The image width, used as part of cache key
w
,
int
The image height, used as part of cache key
h
,
Object...
Other arguments to use as part of the cache key
args
)

Sets the cached image for the specified constraints.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

currentPixelCountback to summary
private int currentPixelCount
instanceback to summary
private static final ImageCache instance
lockback to summary
private ReadWriteLock lock
mapback to summary
private final LinkedHashMap<Integer, ImageCache.PixelCountSoftReference> map
maxPixelCountback to summary
private final int maxPixelCount
maxSingleImagePixelSizeback to summary
private final int maxSingleImagePixelSize
referenceQueueback to summary
private ReferenceQueue<Image> referenceQueue

Constructor Detail

ImageCacheback to summary
public ImageCache()
ImageCacheback to summary
public ImageCache(int maxPixelCount, int maxSingleImagePixelSize)

Method Detail

flushback to summary
public void flush()

Clear the cache

getImageback to summary
public Image getImage(GraphicsConfiguration config, int w, int h, Object... args)

Get the cached image for given keys

Parameters
config:GraphicsConfiguration

The graphics configuration, needed if cached image is a Volatile Image. Used as part of cache key

w:int

The image width, used as part of cache key

h:int

The image height, used as part of cache key

args:Object[]

Other arguments to use as part of the cache key

Returns:Image

Returns the cached Image, or null there is no cached image for key

getInstanceback to summary
pack-priv static ImageCache getInstance()

Get static singleton instance

hashback to summary
private int hash(GraphicsConfiguration config, int w, int h, Object... args)

Create a unique hash from all the input

isImageCachableback to summary
public boolean isImageCachable(int w, int h)

Check if the image size is to big to be stored in the cache

Parameters
w:int

The image width

h:int

The image height

Returns:boolean

True if the image size is less than max

setImageback to summary
public boolean setImage(Image image, GraphicsConfiguration config, int w, int h, Object... args)

Sets the cached image for the specified constraints.

Parameters
image:Image

The image to store in cache

config:GraphicsConfiguration

The graphics configuration, needed if cached image is a Volatile Image. Used as part of cache key

w:int

The image width, used as part of cache key

h:int

The image height, used as part of cache key

args:Object[]

Other arguments to use as part of the cache key

Returns:boolean

true if the image could be cached or false if the image is too big

javax.swing.plaf.nimbus back to summary

private Class ImageCache.PixelCountSoftReference

extends SoftReference<Image>
Class Inheritance

Extended SoftReference that stores the pixel count even after the image is lost

Field Summary

Modifier and TypeField and Description
private final Object[]
private final GraphicsConfiguration
private final int
h

private final int
private final int
private final int
w

Constructor Summary

AccessConstructor and Description
public
PixelCountSoftReference(Image referent, ReferenceQueue<? super Image> q, int pixelCount, int hash, GraphicsConfiguration config, int w, int h, Object[] args)

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(GraphicsConfiguration config, int w, int h, Object[] args)

Inherited from java.lang.ref.SoftReference:
get

Field Detail

argsback to summary
private final Object[] args
configback to summary
private final GraphicsConfiguration config
hback to summary
private final int h
hashback to summary
private final int hash
pixelCountback to summary
private final int pixelCount
wback to summary
private final int w

Constructor Detail

PixelCountSoftReferenceback to summary
public PixelCountSoftReference(Image referent, ReferenceQueue<? super Image> q, int pixelCount, int hash, GraphicsConfiguration config, int w, int h, Object[] args)

Method Detail

equalsback to summary
public boolean equals(GraphicsConfiguration config, int w, int h, Object[] args)