public class ImageCache extends Hashtable
Modifier and Type | Field and Description |
---|---|
static ImageCache |
cache
This is a global ImageCache that you can use.
|
serialVersionUID
Constructor and Description |
---|
ImageCache() |
ImageCache(String relativePathForLoad)
This calls ImageCache(relativePathForLoad,null).
|
ImageCache(String relativePathForLoad,
Class relativeToClassForLoad)
Create an ImageCache where Images can be loaded as resources relative to the specified class using
the "load()" or "tryLoad()" method.
|
Modifier and Type | Method and Description |
---|---|
void |
free()
Free all images and clear the cache.
|
Icon |
getAsIcon(String imageNames)
Get an Icon from a list of image names.
|
Icon |
getAsIcon(String imageNames,
boolean trimNonTransparent) |
IImage |
getCached(String imageName,
IImage defaultImage)
Get an image from the cache only.
|
IIcon |
getIcon(String imageNames)
Get an IIcons from a list of image names.
|
IIcon |
getIcon(String imageNames,
boolean trimNonTransparent) |
IImage |
getImage(String imageName) |
IImage |
getImage(String imageName,
boolean asAnIcon)
Load an Image given the imageName.
|
IImage |
getImage(String imageName,
int width,
int height)
Get an IImage scaled to a particular size.
|
IImage |
getImage(String imageName,
int maxWidth,
int maxHeight,
boolean allowScaleUp)
Deprecated.
|
IImage |
getImage(String imageName,
Object maskOrColor)
Deprecated.
|
IImage |
getImageFor(String relativePath,
Class requestingClass)
Get an Image relative to a class.
|
IImage |
getSizedImage(IIcon icon,
int width,
int height) |
IImage |
getSizedImage(String imageNames,
int width,
int height) |
IImage |
load(String imageName)
Deprecated.
DO NOT USE - this will be removed in 1.40
|
IImage |
load(String imageName,
int maxWidth,
int maxHeight,
boolean allowScaleUp)
Deprecated.
DO NOT USE - this will be removed in 1.40
|
boolean |
loadIntoCache(String imageName,
boolean replaceExisting)
Load the image into cache by creating a new Picture.
|
void |
putIntoCache(String imageName,
IImage image)
Put an image into the cache.
|
void |
setIcon(String imageNames,
Object image) |
Icon |
tryAsIcon(String imageNames,
Object defaultIcon)
Try to load an Icon but do not throw an exception on error.
|
IIcon |
tryIcon(String imageNames,
IIcon defaultIcon)
Try to load an IIcon but do not throw an exception on error.
|
IImage |
tryImage(String imageName,
IImage defaultImage)
Try to load an image but do not throw an exception on error.
|
clear, clone, contains, containsKey, containsValue, elements, entrySet, get, isEmpty, keys, keySet, put, putAll, rehash, remove, size, toString, values
public static ImageCache cache
public ImageCache(String relativePathForLoad, Class relativeToClassForLoad)
This allows for classes and packages to be renamed without change the name if icon paths - as long as they are kept relative to each other.
relativePathForLoad
- the relative path to check for images with load().relativeToClassForLoad
- the class relative to for checking. If this is null and relativePathForLoad is not null,
then this class is determined based on the calling class.public ImageCache(String relativePathForLoad)
public ImageCache()
public void putIntoCache(String imageName, IImage image)
imageName
- the name of the image.image
- the image.public boolean loadIntoCache(String imageName, boolean replaceExisting)
imageName
- the name of the image.replaceExisting
- if this is true then the loaded image replaces any
previous one with the same name.public IImage getCached(String imageName, IImage defaultImage)
imageName
- the name of the image.defaultImage
- a defaultImage to return if it is not in the cache. This may be
null.public IImage tryImage(String imageName, IImage defaultImage)
imageName
- the name of the image.defaultImage
- the defaultImage to return if the image could not be found or loaded.public IImage getImage(String imageName, Object maskOrColor) throws IllegalArgumentException
imageName
- The full resource name of the image.maskOrColor
- Either a resource name of a mask image or a Color object.IllegalArgumentException
- If the named image does not exist or is not formatted correctly.public IImage getImage(String imageName, int maxWidth, int maxHeight, boolean allowScaleUp)
imageName
- maxWidth
- maxHeight
- allowScaleUp
- IllegalArgumentException
- if the image is not found.public IImage getImage(String imageName, int width, int height)
imageName
- the name of the image/icon.width
- the requested width. This can be 0 if height is not 0.height
- the requested height. This can be 0 if width is not 0;public IImage load(String imageName, int maxWidth, int maxHeight, boolean allowScaleUp)
public IIcon tryIcon(String imageNames, IIcon defaultIcon)
imageNames
- the list of image names, separated by '|' characters.defaultIcon
- the default IIcons to return if the icon could not be found or loaded.public Icon tryAsIcon(String imageNames, Object defaultIcon)
imageNames
- the list of image names, separated by '|' characters.defaultIcon
- the default Object to return (it will be converted to an Icon) if the icon could not be found or loaded.public Icon getAsIcon(String imageNames)
imageNames
- the list of image names, separated by '|' characters.IllegalArgumentException
- if none of the images are found.public IIcon getIcon(String imageNames)
imageNames
- the list of image names, separated by '|' characters.IllegalArgumentException
- if none of the images are found.public IImage getImage(String imageName, boolean asAnIcon)
imageName
- the image name, which may be absolute or relative to the calling class or relative to the
application resources.asAnIcon
- set this true to load a plain single image as an Icon, false to leave it as a plain image.IllegalArgumentException
- if none of the images are found.public void free()
public IImage getImageFor(String relativePath, Class requestingClass)
relativePath
- a path and name relative to the requesting class path.requestingClass
- the class requesting the image.IllegalArgumentException
- if the image is not found.