org.jrabbit.base.graphics.image
Class ImageCache

java.lang.Object
  extended by org.jrabbit.base.data.structures.BaseKeyedContainer<T>
      extended by org.jrabbit.base.data.cache.Cache<T>
          extended by org.jrabbit.base.data.cache.GroupedCache<Image>
              extended by org.jrabbit.base.graphics.image.ImageCache
All Implemented Interfaces:
java.lang.Iterable<Image>, Destroyable, Factory<Image>, Accepter<Image>, Container<Image>, KeyedContainer<Image>, Remover<Image>

public class ImageCache
extends GroupedCache<Image>

A Cache for holding Images. In addition to simply holding images for access, an ImageCache adds some simple methods for managing the scaling filter (i.e., pixelation or smoothing) for groups of images.

Author:
Chris Molini

Nested Class Summary
private  class ImageCache.ImageFactory
          The default Factory attempts to create an Image as if its reference was a filepath pointing to the desired source file.
 
Nested classes/interfaces inherited from class org.jrabbit.base.data.cache.GroupedCache
GroupedCache.EntryList
 
Field Summary
private  boolean smoothImages
          Whether or not images are supposed to be smoothed or not.
 
Fields inherited from class org.jrabbit.base.data.cache.GroupedCache
groups
 
Fields inherited from class org.jrabbit.base.data.structures.BaseKeyedContainer
contents, factory
 
Constructor Summary
ImageCache()
          Creates an empty ImageCache and sets its Factory to the default.
 
Method Summary
 boolean add(Image image)
          Adds an Image, and checks whether the add was successful.
 void setImageSmooth(boolean smooth)
          Sets whether or not images should be pixelated or smoothed.
 void setImageSmooth(boolean smooth, java.lang.String groupName)
          Changes the scaling filter for a particular group of Images in the Cache.
 
Methods inherited from class org.jrabbit.base.data.cache.GroupedCache
addGroup, addGroup, addIntoGroup, addIntoGroup, addIntoGroup, addIntoGroup, clearGroups, destroyGroup, disgroup, emptyGroup, groups, objectsReferenced, objectsReferenced, removeFromGroup, wipeGroup
 
Methods inherited from class org.jrabbit.base.data.cache.Cache
destroy, get, get, removeAndDestroy, setTo
 
Methods inherited from class org.jrabbit.base.data.structures.BaseKeyedContainer
add, add, add, clear, contains, contains, create, createMap, factory, iterator, remove, remove, remove, remove, setFactory, size
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

smoothImages

private boolean smoothImages
Whether or not images are supposed to be smoothed or not. Images have the appropriate value applied to them whenever they are added to the cache.

Constructor Detail

ImageCache

public ImageCache()
Creates an empty ImageCache and sets its Factory to the default. If an Image is requested that is not in the list, the Factory attempts to create one as if its reference was a filepath pointing to the desired source file.

Method Detail

add

public boolean add(Image image)
Adds an Image, and checks whether the add was successful. NOTE: If the Image is added, its smoothing flag is set to the default value of the cache.

Specified by:
add in interface Accepter<Image>
Overrides:
add in class BaseKeyedContainer<Image>
Parameters:
object - The object to add.
Returns:
Whether or not the add was successful.

setImageSmooth

public void setImageSmooth(boolean smooth)
Sets whether or not images should be pixelated or smoothed. Immediately on this call, every image in the cache has its scaling filter updated to deal with this change. Additionally, every Image created by the factory will have the same filter applied to it. NOTE: If you create images externally, and add them after setting this value, you need to set the scaling filter yourself.

Parameters:
smooth - True if images should have a smoothed appearance, false if they should be pixelated.

setImageSmooth

public void setImageSmooth(boolean smooth,
                           java.lang.String groupName)
Changes the scaling filter for a particular group of Images in the Cache.

Parameters:
smooth - Whether or not to smooth the image.
groupName - The name of the group to use.