ccs.cpc
Class ImageManager

java.lang.Object
  extended by ccs.cpc.ImageManager

public class ImageManager
extends java.lang.Object

ImageManager manages loading and caching images, and notifies interested ImageHolders when their image is ready.


Constructor Summary
ImageManager()
          Create an ImageManager.
 
Method Summary
 void addImageHolder(ImageHolder ih)
          Add an ImageHolder.
 void flush(VFile vf)
          Flush the specified image and remove it from the cache, if present.
 void flushAll()
          Empty the cache completely.
 CpcImage getImage(VFile vf)
          Return the image contained in the specified file, iff available.
 void imageLoaded(VFile job, CpcImage result)
          Notification from the ImageLoader that it's loaded an image.
 void loadImage(VFile job)
          Request that an image be loaded.
 void removeImageHolder(ImageHolder ih)
          Remove an ImageHolder.
 void setCacheLimit(java.awt.Component frame, int n)
          Set the cache size to n bytes. 8 MB is the default, and is generally a reasonable setting.
 void setImageLoader(ImageLoader iload)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImageManager

public ImageManager()
Create an ImageManager. NB. Must call setImageLoader before using.

Method Detail

setImageLoader

public void setImageLoader(ImageLoader iload)

addImageHolder

public void addImageHolder(ImageHolder ih)
Add an ImageHolder. ImageHolders will be notified asynchronously when an image is made available.


removeImageHolder

public void removeImageHolder(ImageHolder ih)
Remove an ImageHolder. Used when disposing of the ImageHolder at the end of its life.


getImage

public CpcImage getImage(VFile vf)
Return the image contained in the specified file, iff available. Never blocks.


flush

public void flush(VFile vf)
Flush the specified image and remove it from the cache, if present. This is for explicit "this image is known-bad, vape it" events, rather than images falling out of the cache from underuse.


flushAll

public void flushAll()
Empty the cache completely.


loadImage

public void loadImage(VFile job)
Request that an image be loaded. This always returns immediately; when the image is ready, imageLoaded will be called asynchronously.

Parameters:
job - The image to load.

imageLoaded

public void imageLoaded(VFile job,
                        CpcImage result)
Notification from the ImageLoader that it's loaded an image. The notification will be passed to all image holders; those that are interested will update themselves accordingly.


setCacheLimit

public void setCacheLimit(java.awt.Component frame,
                          int n)
Set the cache size to n bytes. 8 MB is the default, and is generally a reasonable setting. Note that this limit will be exceeded if a single image is larger than the cache limit.

Parameters:
frame - If the cache is too big relative to the max heap size, it will be capped. The notification dialog hangs off this frame.