echopointng.ui.util
Class ImageManager

java.lang.Object
  extended by echopointng.ui.util.ImageManager
All Implemented Interfaces:
java.io.Serializable, RenderState

public class ImageManager
extends java.lang.Object
implements RenderState

ImageManager is used to manage ImageReference 's within the EPNG code.

The base nextapp.echo2.webcontainer.image.ImageRenderSupport does not do a simple enough job of managing images as it uses a component based lookup in a callback to implement image serving.

This ImageManager class will allow URI's for images to be generated as well as IMG HTML tag elements to be created without needing the component as the lookup context.

All that is needed is the ImageReference itself.

And instance of this class can be used to store images against a logical name via the setImage() and getImage() methods. ImageManager implements RenderState and hence can be stored against a given renderer per component.

See Also:
Serialized Form

Nested Class Summary
static interface ImageManager.ImageReferenceURIHandler
           
 
Constructor Summary
ImageManager()
          Constructs a ImageManager
 
Method Summary
 void addImage(ImageReference imageReference)
          Adds the ImageReference to the ImageManager via its renderId.
static org.w3c.dom.Element createImgE(RenderContext rc, CssStyle cssStyle, ImageReference imageRef)
          This will create an 'img' element for the specified ImageReference.
static org.w3c.dom.Element createImgE(RenderContext rc, ImageReference imageRef)
          This will create an 'img' element for the specified ImageReference.
static org.w3c.dom.Element createImgEFromProperty(RenderContext rc, Component component, java.lang.String propertyName)
           
static org.w3c.dom.Element createImgEFromProperty(RenderContext rc, CssStyle cssStyle, Component component, java.lang.String propertyName)
          Creates an IMG tag by using extracting the value of the named property from the component.
static void deregisterURIHandler(ImageManager.ImageReferenceURIHandler handler)
          Deregisters a ImageReferenceURIHandler from the static set of handlers
 ImageReference getImage(java.lang.String imageId)
          Returns an ImageReference from the ImageManager by imageId
static java.lang.String getURI(RenderContext rc, Component component, java.lang.String propertyName)
          This returns the URI that can be used to serve up the specified property if its an ImageReference or FillImage value.
static java.lang.String getURI(RenderContext rc, ImageReference imageReference)
          This returns the URI that can be used to serve up the specified ImageReference.
static void registerURIHandler(ImageManager.ImageReferenceURIHandler handler)
          Registers a ImageReferenceURIHandler to the static set of handlers
 void removeAllImages()
          Removes all ImageReferences from the ImageManager
 void removeImage(ImageReference imageReference)
          Removes the ImageReference from the ImageManager via its renderId.
 void setImage(java.lang.String imageId, ImageReference imageReference)
          Stores an ImageReference into the ImageManager using a given imageId.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImageManager

public ImageManager()
Constructs a ImageManager

Method Detail

registerURIHandler

public static void registerURIHandler(ImageManager.ImageReferenceURIHandler handler)
Registers a ImageReferenceURIHandler to the static set of handlers

Parameters:
handler - - the handler to add

deregisterURIHandler

public static void deregisterURIHandler(ImageManager.ImageReferenceURIHandler handler)
Deregisters a ImageReferenceURIHandler from the static set of handlers

Parameters:
handler - - the handler to deregister

getURI

public static java.lang.String getURI(RenderContext rc,
                                      ImageReference imageReference)
This returns the URI that can be used to serve up the specified ImageReference.

Parameters:
rc - - the RenderContext to use
imageReference - - the ImageReference in question
Returns:
an URI for the ImageReference

getURI

public static java.lang.String getURI(RenderContext rc,
                                      Component component,
                                      java.lang.String propertyName)
This returns the URI that can be used to serve up the specified property if its an ImageReference or FillImage value.

Parameters:
rc - the RenderContext to use
component - - the component to look up render properties in
propertyName - - the name of the property
Returns:
an URI or null

createImgE

public static org.w3c.dom.Element createImgE(RenderContext rc,
                                             ImageReference imageRef)
This will create an 'img' element for the specified ImageReference.

This assumes that the image URI is based on the ImageReference.getRenderId().

Parameters:
rc - - the RenderContext to use
imageRef - - the ImageReference in question. This must not be null.
Returns:
an 'img' element

createImgE

public static org.w3c.dom.Element createImgE(RenderContext rc,
                                             CssStyle cssStyle,
                                             ImageReference imageRef)
This will create an 'img' element for the specified ImageReference.

This assumes that the image URI is based on the ImageReference.getRenderId().

If the CssStyle passsed in is non null, then it will be used to set extra 'img' tag styles such a "border:none;width:x;height:y". It will only set these properties if they are not already set in the style.

Parameters:
rc - - the RenderContext to use
cssStyle - - a CssStyle to use on the 'img' tag. Can be null
imageRef - - the ImageReference in question. This must not be null.
Returns:
an 'img' element

createImgEFromProperty

public static org.w3c.dom.Element createImgEFromProperty(RenderContext rc,
                                                         CssStyle cssStyle,
                                                         Component component,
                                                         java.lang.String propertyName)
Creates an IMG tag by using extracting the value of the named property from the component. It can handle ImageReference properties as well as FillImage properties.

Parameters:
rc - - the RenderingContext to use
cssStyle - - the CssStyle to use if applicable.
component - - the component whose property will be looked up
propertyName - - the name of the property
Returns:

createImgEFromProperty

public static org.w3c.dom.Element createImgEFromProperty(RenderContext rc,
                                                         Component component,
                                                         java.lang.String propertyName)
See Also:
createImgEFromProperty(RenderContext, CssStyle, Component, String)

setImage

public void setImage(java.lang.String imageId,
                     ImageReference imageReference)
Stores an ImageReference into the ImageManager using a given imageId.

Parameters:
imageId - - the id to use to store the ImageReference
imageReference - - the ImageReference to store

getImage

public ImageReference getImage(java.lang.String imageId)
Returns an ImageReference from the ImageManager by imageId

Parameters:
imageId - - the id used to store the ImageReference in the ImageManager.
Returns:
- the ImageReference or null

addImage

public void addImage(ImageReference imageReference)
Adds the ImageReference to the ImageManager via its renderId.

Parameters:
imageReference - - the ImageReference to add. If this is null then nothing happens.

removeImage

public void removeImage(ImageReference imageReference)
Removes the ImageReference from the ImageManager via its renderId.

Parameters:
imageReference - - the ImageReference to remove

removeAllImages

public void removeAllImages()
Removes all ImageReferences from the ImageManager