Class AbstractImagePrototype

public class AbstractImagePrototype
extends Object
An opaque representation of a particular image such that the image can be accessed either as an HTML fragment or as an Image object. An image prototype can be thought of as an abstract image factory with additional capabilities.

The applyTo(Image) method provides an efficient way to replace the contents of an existing Image. This is useful in cases where an image changes its appearance based on a user's action. Instead of creating two Image objects then alternately hiding/showing them, one can use the applyTo(Image) method of two AbstractImagePrototype objects to transform a single Image object between two (or more) visual representations. The use of AbstractImagePrototypes results in an cleaner and more efficient implementation.

This class is also a useful way to encapsulate complex HTML that represents an image without actually instantiating Image objects. When constructing large HTML fragments, especially those that contain many images, getHTML() can be much more efficient.

Methods

applyTo(Image)Transforms an existing Image into the image represented by this prototype.
createImage()Creates a new Image instance based on the image represented by this prototype.
getHTML()Gets an HTML fragment that displays the image represented by this prototype.

Method Detail

applyTo

public abstract void applyTo(Image image)
Transforms an existing Image into the image represented by this prototype.

Parameters

image
the instance to be transformed to match this prototype

createImage

public abstract Image createImage()
Creates a new Image instance based on the image represented by this prototype.

Return Value

a new Image based on this prototype

getHTML

public abstract String getHTML()
Gets an HTML fragment that displays the image represented by this prototype. The HTML returned is not necessarily a simple <img> element. It may be a more complex structure that should be treated opaquely.

Return Value

the HTML representation of this prototype