API Reference 0.3.24dart_web_toolkit_uiAbstractImagePrototype

AbstractImagePrototype abstract class

An opaque representation of a particular image such that the image can be accessed either as an HTML fragment or as an {@link Image} object. An image prototype can be thought of as an abstract image factory with additional capabilities.

The {@link #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 {@link #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 also provide methods for working with raw elements, using {@link #createElement()} and {@link #applyTo(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, {@link #getHTML()} can be much more efficient.

abstract class AbstractImagePrototype {

 /**
  * Create an AbstractImagePrototype backed by a ClientBundle ImageResource.
  * This method provides an API compatibility mapping for the new ImageResource
  * API.
  * 
  * @param resource an ImageResource produced by a ClientBundle
  * @return an AbstractImagePrototype that displays the contents of the
  *         ImageResource
  */
 static AbstractImagePrototype create(ImageResource resource) {
   return new ClippedImagePrototype(resource.url, resource.left, resource.top,
       resource.width, resource.height);
 }

 /**
  * Transforms an existing {@link Image} into the image represented by this
  * prototype.
  * 
  * @param image the instance to be transformed to match this prototype
  */
 void applyTo(Image image);

 /**
  * Transforms an existing {@link ImagePrototypeElement} into the image
  * represented by this prototype.
  * 
  * @param imageElement an <code>ImagePrototypeElement</code> created by
  *          {@link #createElement()}
  */
 void applyToImageElement(dart_html.ImageElement imageElement) {
   // Because this is a new method on an existing base class, we need to throw
   // UnsupportedOperationException to avoid static errors.
   throw new Exception("UnsupportedOperation");
 }

 /**
  * Creates a new {@link Element} based on the image represented by this
  * prototype. The DOM structure may not necessarily a simple
  * <code>&lt;img&gt;</code> element. It may be a more complex structure that
  * should be treated opaquely.
  * 
  * @return the <code>ImagePrototypeElement</code> corresponding to the image
  *         represented by this prototype
  */
 dart_html.ImageElement createElement() {
   // Because this is a new method on an existing base class, we need to throw
   // UnsupportedOperationException to avoid static errors.
   throw new Exception("UnsupportedOperation");
 }

 /**
  * Creates a new {@link Image} instance based on the image represented by this
  * prototype.
  * 
  * @return a new {@link Image} based on this prototype
  */
 Image createImage();

 /**
  * Gets an HTML fragment that displays the image represented by this
  * prototype. The HTML returned is not necessarily a simple
  * <code>&lt;img&gt;</code> element. It may be a more complex structure that
  * should be treated opaquely.
  * <p>
  * The default implementation calls {@link #getSafeHtml()}.
  * 
  * @return the HTML representation of this prototype
  */
 String getHtml() {
   return getSafeHtml().asString();
 }

 /**
  * Gets an HTML fragment that displays the image represented by this
  * prototype. The HTML returned is not necessarily a simple
  * <code>&lt;img&gt;</code> element. It may be a more complex structure that
  * should be treated opaquely.
  * <p>
  * The default implementation throws an {@link UnsupportedOperationException}.
  * 
  * @return the HTML representation of this prototype
  */
 SafeHtml getSafeHtml() {
   // Because this is a new method on an existing base class, we need to throw
   // UnsupportedOperationException to avoid static errors.
   throw new Exception("UnsupportedOperation");
 }
}

Subclasses

ClippedImagePrototype

Static Methods

AbstractImagePrototype create(ImageResource resource) #

Create an AbstractImagePrototype backed by a ClientBundle ImageResource. This method provides an API compatibility mapping for the new ImageResource API.

@param resource an ImageResource produced by a ClientBundle @return an AbstractImagePrototype that displays the contents of the

    ImageResource
static AbstractImagePrototype create(ImageResource resource) {
 return new ClippedImagePrototype(resource.url, resource.left, resource.top,
     resource.width, resource.height);
}

Methods

abstract void applyTo(Image image) #

Transforms an existing {@link Image} into the image represented by this prototype.

@param image the instance to be transformed to match this prototype

void applyToImageElement(ImageElement imageElement) #

Transforms an existing {@link ImagePrototypeElement} into the image represented by this prototype.

@param imageElement an <code>ImagePrototypeElement</code> created by

     {@link #createElement()}
void applyToImageElement(dart_html.ImageElement imageElement) {
 // Because this is a new method on an existing base class, we need to throw
 // UnsupportedOperationException to avoid static errors.
 throw new Exception("UnsupportedOperation");
}

ImageElement createElement() #

Creates a new {@link Element} based on the image represented by this prototype. The DOM structure may not necessarily a simple <code><img></code> element. It may be a more complex structure that should be treated opaquely.

@return the <code>ImagePrototypeElement</code> corresponding to the image

    represented by this prototype
dart_html.ImageElement createElement() {
 // Because this is a new method on an existing base class, we need to throw
 // UnsupportedOperationException to avoid static errors.
 throw new Exception("UnsupportedOperation");
}

abstract Image createImage() #

Creates a new {@link Image} instance based on the image represented by this prototype.

@return a new {@link Image} based on this prototype

String getHtml() #

Gets an HTML fragment that displays the image represented by this prototype. The HTML returned is not necessarily a simple <code><img></code> element. It may be a more complex structure that should be treated opaquely. <p> The default implementation calls {@link #getSafeHtml()}.

@return the HTML representation of this prototype

String getHtml() {
 return getSafeHtml().asString();
}

SafeHtml getSafeHtml() #

Gets an HTML fragment that displays the image represented by this prototype. The HTML returned is not necessarily a simple <code><img></code> element. It may be a more complex structure that should be treated opaquely. <p> The default implementation throws an {@link UnsupportedOperationException}.

@return the HTML representation of this prototype

SafeHtml getSafeHtml() {
 // Because this is a new method on an existing base class, we need to throw
 // UnsupportedOperationException to avoid static errors.
 throw new Exception("UnsupportedOperation");
}