com.xj.anylogic.engine.presentation
Class ImageCache

java.lang.Object
  extended by com.xj.anylogic.engine.presentation.ImageCache

public class ImageCache
extends java.lang.Object

A cache for images deiplayed in AnyLogic presentation graphics. A cached image is identified by either its presentable object (active object or experiment) or its URL. An image is cached as BufferedImage with either its original width and height or width and height requested by the user. Note that if the same image is drawn twice with different width and height, or its dimensions change all the time, that may seriously slow down the presentation as the image will be reloaded and the new BufferedImage will be created on each frame.

Author:
XJ Technologies Company Ltd. www.anylogic.com

Constructor Summary
ImageCache()
           
 
Method Summary
 void clear()
          Clears the cache.
 java.awt.image.BufferedImage getCachedImage(Presentable p, java.lang.String filename, int width, int height)
          Deprecated. use getCachedImage(Presentable, String, String, int, int)
 java.awt.image.BufferedImage getCachedImage(Presentable p, java.lang.String packagePrefix, java.lang.String fileName, int width, int height)
          Returns an already cached buffered image identified by its owner presentable object, filename and dimensions.
 java.awt.image.BufferedImage getCachedImage(java.net.URL url, int width, int height)
          Returns an already cached buffered image identified by its url and dimensions.
 java.awt.image.BufferedImage getCAD(Presentable p, java.lang.String packagePrefix, java.lang.String fileName, int id, int width, int height, java.awt.Color backgroundColor, java.lang.String[] layerNames, boolean[] layersVisibility, java.awt.Color[] customLayerColors, boolean invertDefaultColors, boolean forceRedraw)
          Deprecated. this method will be removed in the future releases, please use getCAD(Presentable, String, String, int, int, int, Color, String[], boolean[], Color[], int, boolean)
 java.awt.image.BufferedImage getCAD(Presentable p, java.lang.String packagePrefix, java.lang.String fileName, int id, int width, int height, java.awt.Color backgroundColor, java.lang.String[] layerNames, boolean[] layersVisibility, java.awt.Color[] customLayerColors, int drawingAttributes, boolean forceRedraw)
          This method is not intended to be called by user
Fetches a cached buffered CAD image identified by its owner presentable object or creates, adds to cache and returns a new one.
 java.awt.image.BufferedImage getImage(Presentable p, java.lang.String packagePrefix, java.lang.String fileName, int width, int height)
          Fetches a cached buffered image identified by its owner presentable object or creates, adds to cache and returns a new one.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImageCache

public ImageCache()
Method Detail

getImage

public java.awt.image.BufferedImage getImage(Presentable p,
                                             java.lang.String packagePrefix,
                                             java.lang.String fileName,
                                             int width,
                                             int height)
Fetches a cached buffered image identified by its owner presentable object or creates, adds to cache and returns a new one. If the requested width or height are different (more than by 1 pixel in any dimension) than stored in cache, the cached image is resized.

Parameters:
p - the presentable object
packagePrefix - the package name of original active object where this image is defined, formatted using '/' characters; with '/' character at the beginning and at the end
fileName - the file name of the image, relative to the class of p
width - the requested width of the image, or -1 for original size
height - the requested height of the image, or -1 for original size
Returns:
cached buffered image

getCAD

@Deprecated
public java.awt.image.BufferedImage getCAD(Presentable p,
                                                      java.lang.String packagePrefix,
                                                      java.lang.String fileName,
                                                      int id,
                                                      int width,
                                                      int height,
                                                      java.awt.Color backgroundColor,
                                                      java.lang.String[] layerNames,
                                                      boolean[] layersVisibility,
                                                      java.awt.Color[] customLayerColors,
                                                      boolean invertDefaultColors,
                                                      boolean forceRedraw)
Deprecated. this method will be removed in the future releases, please use getCAD(Presentable, String, String, int, int, int, Color, String[], boolean[], Color[], int, boolean)


getCAD

public java.awt.image.BufferedImage getCAD(Presentable p,
                                           java.lang.String packagePrefix,
                                           java.lang.String fileName,
                                           int id,
                                           int width,
                                           int height,
                                           java.awt.Color backgroundColor,
                                           java.lang.String[] layerNames,
                                           boolean[] layersVisibility,
                                           java.awt.Color[] customLayerColors,
                                           int drawingAttributes,
                                           boolean forceRedraw)
This method is not intended to be called by user
Fetches a cached buffered CAD image identified by its owner presentable object or creates, adds to cache and returns a new one. If the requested width or height are different (more than by 1 pixel in any dimension) than stored in cache, the cached image is resized.

Parameters:
p - the presentable object
packagePrefix - the package name of original active object where this image is defined, formatted using '/' characters; with '/' character at the beginning and at the end
fileName - the file name of the image, relative to the class of p
id - some id of the model element, used to distinguish between different CAD image elements referring to the same cad file
width - the requested width of the image, or -1 for original size
height - the requested height of the image, or -1 for original size
backgroundColor - the background color for CAD drawing
layerNames - the array of names of CAD layers to be drawn
layersVisibility - the array of the same length as layerNames. Contains true values for layers which should be drawn.
customLayerColors - the array of the same length as layerNames. Allows user to specify custom color for all the shapes in a particular layer(s). Default layer colors are used for layers having null item in this array.
drawingAttributes - the drawing attributes, this value should be zero or an "OR" combination of CAD_* constants, e.g. CAD_NEGATIVE | CAD_ANTIALIASING
forceRedraw - if true, CAD will be rerendered even if its cached image seems up-to-date
Returns:
cached buffered CAD image

clear

public void clear()
Clears the cache.


getCachedImage

public java.awt.image.BufferedImage getCachedImage(Presentable p,
                                                   java.lang.String packagePrefix,
                                                   java.lang.String fileName,
                                                   int width,
                                                   int height)
Returns an already cached buffered image identified by its owner presentable object, filename and dimensions. If such image is not cached, returns null.

Parameters:
p - the presentable object
packagePrefix - the package name of original active object where this image is defined, formatted using '/' characters; with '/' character at the beginning and at the end
fileName - the file name of the image, relative to the class of p
width - the width of the image
height - the height of the image
Returns:
cached buffered image or null

getCachedImage

@Deprecated
public java.awt.image.BufferedImage getCachedImage(Presentable p,
                                                              java.lang.String filename,
                                                              int width,
                                                              int height)
Deprecated. use getCachedImage(Presentable, String, String, int, int)

Returns an already cached buffered image identified by its owner presentable object, filename and dimensions. If such image is not cached, returns null.

Parameters:
p - the presentable object
filename - the file name of the image, relative to the class of p
width - the width of the image
height - the height of the image
Returns:
cached buffered image or null

getCachedImage

public java.awt.image.BufferedImage getCachedImage(java.net.URL url,
                                                   int width,
                                                   int height)
Returns an already cached buffered image identified by its url and dimensions. If such image is not cached, returns null.

Parameters:
url - the URL of the image
width - the width of the image
height - the height of the image
Returns:
cached buffered image


Copyright © 1991-2008 XJ Technlogies. All Rights Reserved.