LEONARDI Application Composer - 8.9.0.40 by W4 S.A.

leon.misc
Class LyImages

java.lang.Object
  extended by leon.misc.LyResourceBundle
      extended by leon.misc.LyImages

public class LyImages
extends LyResourceBundle

This class is used to manage images of an application. It is based on the mechanism of LyResourceBundle. Images are put in a cache for memory optimization.


Field Summary
static java.lang.String __VERSION
           
static java.lang.String DEFAULT_DISABLED_IMAGE
          Default disabled image key.
static java.lang.String DEFAULT_IMAGE
          Default image key.
static java.lang.String DISABLE_PREFIX
          The prefix used for disabled images.
static int[] NOT_FOUND
          Not found key (internal use).
 
Fields inherited from class leon.misc.LyResourceBundle
PACKAGE_DIR, PROPERTIES_DIR, UPPER_CASE_KEYS_ONLY
 
Constructor Summary
LyImages(LyEnvironment environment)
          Constructor with a given environment.
LyImages(LyEnvironment environment, java.lang.String name)
          Constructor with a given environment and name.
LyImages(LyEnvironment environment, java.lang.String name, java.lang.String skin)
          Constructor with a given environment and name.
 
Method Summary
 boolean checkImage(java.lang.String key)
          Checks if given key image corresponds to a known image.
 void clearCache()
          Clears application images (reset the cache).
 void free()
          Clears all resources of this bundle.
 java.lang.Object getDefaultImage()
          Gets the current environment view manager default image.
 java.lang.String getDisabledImageUrl(java.lang.String key)
          Gets the disable image URL corresponding to the given key.
static java.lang.String getDisableImageFileName(java.lang.String imageFileName)
          Gets the disable image file name from the given image file name.
 java.lang.Object getImage(java.lang.String key, java.lang.String sizeCode, boolean defaultImage)
          Retrieves an image corresponding to a given key and size.
 java.lang.String getImageFileName(java.lang.String key)
          Gets the image file name corresponding to the given key.
 java.lang.String getImagePath(java.lang.String key)
          Gets the image path corresponding to the given key.
 int[] getImageSize(java.lang.String path, boolean enableLoadImage)
          This method retrieves information about an image size.
 java.lang.String getImageSizeInfo(int width, int height)
          Builds the image size description [VISIBLE_SEP3 + width + VISIBLE_SEP2 + height + VISIBLE_SEP3_BIS].
 java.lang.String getImageUrl(java.lang.String key)
          Gets the image URL corresponding to the given key.
 java.lang.String getImageUrl(java.lang.String key, boolean disabled)
          Return the image url corresponding to the key passed.
 java.lang.String getImageUrl(java.lang.String key, boolean disabled, boolean defaultImage)
          Gets the image url corresponding to the given key.
 java.lang.String getPath(java.lang.String imageName)
          Gets path corresponding to given image name for associated environment.
 java.lang.String getPathWithoutSize(java.lang.String path)
          Retrieves the path of an image without the information about its size.
 java.lang.Object getScaledInstance(java.lang.Object image, int width, int height)
          Creates a scaled version of the given image.
 boolean isImageAnimated(java.lang.String path)
          Indicates if an image is animated or not.
 boolean isInCache(java.lang.Object image)
          Indicates whether given image is contained in the images cache.
 java.lang.Object loadImage(java.lang.Object component, java.lang.String path)
          Loads an image.
 java.lang.Object loadImage(java.lang.Object component, java.lang.String path, boolean newImage)
          Loads an image.
 java.lang.Object loadImage(java.lang.Object component, java.lang.String path, boolean newImage, boolean raiseError)
          Loads an image.
 void put(java.lang.String key, java.lang.String value)
          Adds a resource in this resource bundle.
 void putCache(java.lang.String path, java.lang.Object image)
          Adds the specified pair (path/image) to the image cache.
 void removeCache(java.lang.String path)
          Removes the image associated to given key from the cache.
 
Methods inherited from class leon.misc.LyResourceBundle
checkKey, get, getKeyList, getKeys, getSonEnvironments, hasKey, remove, removeBundles, saveTo
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

__VERSION

public static final java.lang.String __VERSION
See Also:
Constant Field Values

DEFAULT_IMAGE

public static java.lang.String DEFAULT_IMAGE
Default image key.


DEFAULT_DISABLED_IMAGE

public static java.lang.String DEFAULT_DISABLED_IMAGE
Default disabled image key.


NOT_FOUND

public static final int[] NOT_FOUND
Not found key (internal use).


DISABLE_PREFIX

public static java.lang.String DISABLE_PREFIX
The prefix used for disabled images.

Constructor Detail

LyImages

public LyImages(LyEnvironment environment)
Constructor with a given environment. Calls LyImages(environment, null).

Parameters:
environment - The environment of the images bundle.

LyImages

public LyImages(LyEnvironment environment,
                java.lang.String name)
Constructor with a given environment and name. Calls LyImages(environment, name, environment.getLocale()).

Parameters:
environment - The environment of the images bundle.
name - The name of the images bundle.

LyImages

public LyImages(LyEnvironment environment,
                java.lang.String name,
                java.lang.String skin)
Constructor with a given environment and name. Calls LyImages(environment, name, environment.getLocale()).

Parameters:
environment - The environment of the images bundle.
name - The name of the images bundle.
skin - The name of the skin
Method Detail

free

public void free()
Clears all resources of this bundle. Overriden to free all parameters used for optimizations in this class.

Overrides:
free in class LyResourceBundle

getDefaultImage

public java.lang.Object getDefaultImage()
Gets the current environment view manager default image.

Returns:
the default image

getImage

public java.lang.Object getImage(java.lang.String key,
                                 java.lang.String sizeCode,
                                 boolean defaultImage)
Retrieves an image corresponding to a given key and size.

Parameters:
key - The resource name (key) of the image
sizeCode - The size code of the image (see LyImages.loadImage())
defaultImage - If true, return default image if not found.
Returns:
a reference to the image object, or null if it could not be found.
See Also:
loadImage(Object,String), LyEnvironment.getImageSizeInfo(int,int)

getScaledInstance

public java.lang.Object getScaledInstance(java.lang.Object image,
                                          int width,
                                          int height)
Creates a scaled version of the given image.

Parameters:
image - The image to scale.
width - The width to which to scale the image.
height - The height to which to scale the image.
Returns:
A scaled version of the image.
See Also:
LyViewManagerInterface.getScaledInstance(Object, int, int)

getImageSizeInfo

public java.lang.String getImageSizeInfo(int width,
                                         int height)
Builds the image size description [VISIBLE_SEP3 + width + VISIBLE_SEP2 + height + VISIBLE_SEP3_BIS].

Parameters:
width - requested width or -1 if only the size is specified (keeping aspect ratio)
height - requested height (mandatory)
Returns:
The image size description.

isImageAnimated

public boolean isImageAnimated(java.lang.String path)
Indicates if an image is animated or not.

Parameters:
path - The relative path of the image file.
Returns:
True if the image is animated, false otherwise.

loadImage

public java.lang.Object loadImage(java.lang.Object component,
                                  java.lang.String path,
                                  boolean newImage,
                                  boolean raiseError)
Loads an image. Path may contain information about the image size. The syntax is : [path + VISIBLE_SEP3 + width + VISIBLE_SEP2 + height + VISIBLE_SEP3_BIS]. The path of the image must be relative : the image is searched in the classpath of the application.

Parameters:
path - The relative path of the image file.
component - The client of the image creation.
newImage - Indicates whether a new Image must be created.
newImage - Indicates whether an error message should be displayed if an exception was thrown while loading image.
Returns:
The created or found in cache image, null otherwise.
See Also:
getImageSizeInfo(int, int)

loadImage

public final java.lang.Object loadImage(java.lang.Object component,
                                        java.lang.String path)
Loads an image. This methods only calls loadImage(component, path, false)

Parameters:
component - The client of the image creation.
path - The relative path of the image file.
Returns:
The image created.
See Also:
loadImage(Object, String, boolean)

loadImage

public java.lang.Object loadImage(java.lang.Object component,
                                  java.lang.String path,
                                  boolean newImage)
Loads an image. Path may contain information about the image size. The syntax is : [path + VISIBLE_SEP3 + width + VISIBLE_SEP2 + height + VISIBLE_SEP3_BIS]. The path of the image must be relative : the image is searched in the classpath of the application.

Parameters:
path - The relative path of the image file.
component - The client of the image creation.
newImage - Indicates wheter a new Image must be created.
Returns:
The created or found in cache image, null otherwise.
See Also:
getImageSizeInfo(int, int)

clearCache

public void clearCache()
Clears application images (reset the cache).

Overrides:
clearCache in class LyResourceBundle

isInCache

public boolean isInCache(java.lang.Object image)
Indicates whether given image is contained in the images cache.

Parameters:
image - The image that may be cached.
Returns:
true if image is cached, false otherwise

putCache

public void putCache(java.lang.String path,
                     java.lang.Object image)
Adds the specified pair (path/image) to the image cache.

Parameters:
path - The image path that must be added to the cache.
image - The image that must be added to the cache.

removeCache

public void removeCache(java.lang.String path)
Removes the image associated to given key from the cache.

Parameters:
path - The image path that must be removed from the cache.

getImageSize

public int[] getImageSize(java.lang.String path,
                          boolean enableLoadImage)
This method retrieves information about an image size. If this information is given in the path the result is an array of two integers describing the image dimension.

Parameters:
path - The path to check.
enableLoadImage - indicates wether the application is allowed to load the image
Returns:
An array of two integers (width, height) describing the size of the image or null if no size is given in the path.
See Also:
getImageSizeInfo(int, int)

getImagePath

public java.lang.String getImagePath(java.lang.String key)
Gets the image path corresponding to the given key.

Parameters:
key - the image resource key
Returns:
The image path corresponding to the given key if found, null otherwise

getPath

public java.lang.String getPath(java.lang.String imageName)
Gets path corresponding to given image name for associated environment.


getPathWithoutSize

public java.lang.String getPathWithoutSize(java.lang.String path)
Retrieves the path of an image without the information about its size.

Parameters:
path - The path of the image.
Returns:
The path of the image without the size information.

getImageUrl

public final java.lang.String getImageUrl(java.lang.String key)
Gets the image URL corresponding to the given key. Calls getImageUrl(key, false).

Parameters:
key - the image resource key
Returns:
The image url corresponding to the given key if found, null otherwise

getDisabledImageUrl

public final java.lang.String getDisabledImageUrl(java.lang.String key)
Gets the disable image URL corresponding to the given key. Calls getImageUrl(key, true).

Parameters:
key - the image resource key
Returns:
The disable image URL corresponding to the given key if found, null otherwise

getImageUrl

public final java.lang.String getImageUrl(java.lang.String key,
                                          boolean disabled)
Return the image url corresponding to the key passed. Calls getImageUrl(key, disabled, true).

Parameters:
key - the image resource key
disabled - Indicates if disabled image should be searched.
Returns:
The image url corresponding to the key passed or the default image url if not found.

getImageUrl

public java.lang.String getImageUrl(java.lang.String key,
                                    boolean disabled,
                                    boolean defaultImage)
Gets the image url corresponding to the given key.

Parameters:
key - the image resource key
disabled - Indicates if disabled image should be searched.
defaultImage - If true, return default image if the URL is not found.
Returns:
The image url corresponding to the given key, the default image url if not found and defaultImage parameter is set to true, null otherwise.

getImageFileName

public java.lang.String getImageFileName(java.lang.String key)
Gets the image file name corresponding to the given key.

Parameters:
key - the image resource key
Returns:
The image file name corresponding to the given key if found, null otherwise

getDisableImageFileName

public static java.lang.String getDisableImageFileName(java.lang.String imageFileName)
Gets the disable image file name from the given image file name.

Parameters:
imageFileName - the image file name whose associated disable image file name nned to be retreive
Returns:
the disable image file name

put

public void put(java.lang.String key,
                java.lang.String value)
Adds a resource in this resource bundle. Key and value must not be null.

Overrides:
put in class LyResourceBundle
Parameters:
key - Key of the resource.
value - Value of this new resource.

checkImage

public boolean checkImage(java.lang.String key)
Checks if given key image corresponds to a known image.

Parameters:
key - The resource name (key) of the image
Returns:
True if found, false otherwise.

(c) January 2013 - W4 S.A.

Website: W4 S.A., contact us: support@w4global.com