Class AbstractImagePrototype
- java.lang.Object
-
- com.google.gwt.user.client.ui.AbstractImagePrototype
-
public abstract class AbstractImagePrototype extends java.lang.Object
An opaque representation of a particular image such that the image can be accessed either as an HTML fragment or as anImage
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 existingImage
. This is useful in cases where an image changes its appearance based on a user's action. Instead of creating twoImage
objects then alternately hiding/showing them, one can use theapplyTo(Image)
method of twoAbstractImagePrototype
objects to transform a singleImage
object between two (or more) visual representations. The use ofAbstractImagePrototypes
results in an cleaner and more efficient implementation.This class also provide methods for working with raw elements, using
createElement()
andapplyTo(ImagePrototypeElement)
.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractImagePrototype.ImagePrototypeElement
This corresponds to the top Element of the DOM structure created bycreateElement()
.
-
Constructor Summary
Constructors Constructor Description AbstractImagePrototype()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
applyTo(AbstractImagePrototype.ImagePrototypeElement imageElement)
Transforms an existingAbstractImagePrototype.ImagePrototypeElement
into the image represented by this prototype.abstract void
applyTo(Image image)
Transforms an existingImage
into the image represented by this prototype.static AbstractImagePrototype
create(ImageResource resource)
Create an AbstractImagePrototype backed by a ClientBundle ImageResource.AbstractImagePrototype.ImagePrototypeElement
createElement()
Creates a newElement
based on the image represented by this prototype.abstract Image
createImage()
Creates a newImage
instance based on the image represented by this prototype.java.lang.String
getHTML()
Gets an HTML fragment that displays the image represented by this prototype.SafeHtml
getSafeHtml()
Gets an HTML fragment that displays the image represented by this prototype.
-
-
-
Method Detail
-
create
public static AbstractImagePrototype create(ImageResource resource)
Create an AbstractImagePrototype backed by a ClientBundle ImageResource. This method provides an API compatibility mapping for the new ImageResource API.- Parameters:
resource
- an ImageResource produced by a ClientBundle- Returns:
- an AbstractImagePrototype that displays the contents of the ImageResource
-
applyTo
public abstract void applyTo(Image image)
Transforms an existingImage
into the image represented by this prototype.- Parameters:
image
- the instance to be transformed to match this prototype
-
applyTo
public void applyTo(AbstractImagePrototype.ImagePrototypeElement imageElement)
Transforms an existingAbstractImagePrototype.ImagePrototypeElement
into the image represented by this prototype.- Parameters:
imageElement
- anImagePrototypeElement
created bycreateElement()
-
createElement
public AbstractImagePrototype.ImagePrototypeElement createElement()
Creates a newElement
based on the image represented by this prototype. The DOM structure may not necessarily a simple<img>
element. It may be a more complex structure that should be treated opaquely.- Returns:
- the
ImagePrototypeElement
corresponding to the image represented by this prototype
-
createImage
public abstract Image createImage()
Creates a newImage
instance based on the image represented by this prototype.- Returns:
- a new
Image
based on this prototype
-
getHTML
public java.lang.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.The default implementation calls
getSafeHtml()
.- Returns:
- the HTML representation of this prototype
-
getSafeHtml
public SafeHtml getSafeHtml()
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.The default implementation throws an
UnsupportedOperationException
.- Returns:
- the HTML representation of this prototype
-
-