net.sf.jomic.tools
Class ImageCache

java.lang.Object
  extended by net.sf.jomic.tools.ImageCache
All Implemented Interfaces:
CacheInfo
Direct Known Subclasses:
ComicCache.TitleImageCache

public class ImageCache
extends java.lang.Object
implements CacheInfo

Cache to store RenderedImages in memory. When the memory usage exceeds a maximum size, the least recent images are removed. Note that the cache holds at least one image, so if this is bigger than the maximum size, so is the whole cache.


Constructor Summary
ImageCache(java.lang.String newName, long newMaxMemorySize)
           
 
Method Summary
 void clear()
          Remove all entries from cache.
 java.awt.image.RenderedImage createBrokenImage()
          Create a broken image using the cache's default dimension.
 void dispose()
           
 java.awt.image.RenderedImage get(java.io.File imageFile)
           
 java.awt.image.RenderedImage get(java.io.File imageFile, ImageInCacheListener listener)
           
protected  java.awt.Dimension getDefaultImageDimension()
           
 java.awt.Dimension getDimension(java.io.File imageFile)
           
 int getEntryCount()
          Number of cache entries.
 long getMaxSize()
          Get number of bytes the cache may fill up before entries get thrown out.
 long getUsedSize()
          Get the approximate number of bytes currently used by all images in the cache.
 boolean has(java.io.File imageFile)
          Is the image for imageFile already stored in the cache?
protected  java.awt.image.RenderedImage obtainImage(java.io.File imageFile)
           
protected  java.awt.Dimension obtainImageDimension(java.io.File imageFile)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImageCache

public ImageCache(java.lang.String newName,
                  long newMaxMemorySize)
Method Detail

get

public java.awt.image.RenderedImage get(java.io.File imageFile)
                                 throws java.io.IOException
Throws:
java.io.IOException

get

public java.awt.image.RenderedImage get(java.io.File imageFile,
                                        ImageInCacheListener listener)
                                 throws java.io.IOException
Throws:
java.io.IOException

getDimension

public java.awt.Dimension getDimension(java.io.File imageFile)

getEntryCount

public int getEntryCount()
Description copied from interface: CacheInfo
Number of cache entries.

Specified by:
getEntryCount in interface CacheInfo

getMaxSize

public long getMaxSize()
Get number of bytes the cache may fill up before entries get thrown out. Note that the cache will hold at least 1 image, so if this is bigger than the maximum size, the actual size may exceed the maximum in this case.

Specified by:
getMaxSize in interface CacheInfo

getUsedSize

public long getUsedSize()
Get the approximate number of bytes currently used by all images in the cache.

Specified by:
getUsedSize in interface CacheInfo

getDefaultImageDimension

protected java.awt.Dimension getDefaultImageDimension()

clear

public void clear()
Remove all entries from cache.


createBrokenImage

public java.awt.image.RenderedImage createBrokenImage()
Create a broken image using the cache's default dimension.


dispose

public void dispose()

has

public boolean has(java.io.File imageFile)
Is the image for imageFile already stored in the cache?


obtainImage

protected java.awt.image.RenderedImage obtainImage(java.io.File imageFile)
                                            throws java.io.IOException
Throws:
java.io.IOException

obtainImageDimension

protected java.awt.Dimension obtainImageDimension(java.io.File imageFile)
                                           throws java.io.IOException
Throws:
java.io.IOException