wicket.markup.html.image.resource
Class DynamicImageResource

java.lang.Object
  extended bywicket.Resource
      extended bywicket.markup.html.WebResource
          extended bywicket.markup.html.image.resource.DynamicImageResource
All Implemented Interfaces:
IRequestListener, IResourceListener, java.io.Serializable
Direct Known Subclasses:
BufferedDynamicImageResource, RenderedDynamicImageResource

public abstract class DynamicImageResource
extends WebResource

An ImageResource subclass for dynamic images (images created programmatically). Subclasses override getImageData() to provide the image data to send back to the user. A given subclass may decide how to produce this data and whether/how to buffer it.

The RenderedDynamicImageResource subclass is designed for images that can be regenerated when the component is deserialized (the image data is transient). A good example of a RenderedDynamicImageResource is the DefaultButtonImageResource class, which can regenerate a given button image at any time. This makes it very lightweight when clustered. The BufferedDynamicImageResource class, on the other hand, is designed for images that cannot be regenerated on demand. It buffers its image data in a non-transient way, which means that the entire image will be serialized and copied when the resource is replicated in a cluster!

The helper method toImageData(BufferedImage) is provided so that subclasses can easily turn a BufferedImage into a suitable return value when implementing getImageData().

The format of the image (and therefore the resource's extension) can be specified with setFormat(String). The default format is "PNG" because JPEG is lossy and makes generated images look bad and GIF has patent issues.

Author:
Jonathan Locke
See Also:
Serialized Form

Field Summary
protected  Time lastModifiedTime
          The time this image resource was last modified
 
Fields inherited from class wicket.Resource
resourceStream
 
Constructor Summary
DynamicImageResource()
           
 
Method Summary
 java.lang.String getFormat()
           
protected abstract  byte[] getImageData()
          Get image data for our dynamic image resource.
 IResourceStream getResourceStream()
           
 Time lastModifiedTime()
           
 void setFormat(java.lang.String format)
          Sets the format of this dynamic image, such as "jpeg" or "gif"
protected  byte[] toImageData(java.awt.image.BufferedImage image)
           
 
Methods inherited from class wicket.Resource
invalidate, isCacheable, onResourceRequested, setCacheable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lastModifiedTime

protected Time lastModifiedTime
The time this image resource was last modified

Constructor Detail

DynamicImageResource

public DynamicImageResource()
Method Detail

getFormat

public final java.lang.String getFormat()
Returns:
Returns the image format.

getResourceStream

public IResourceStream getResourceStream()
Specified by:
getResourceStream in class Resource
Returns:
Gets the image resource to attach to the component.

lastModifiedTime

public Time lastModifiedTime()
Returns:
The last time this image resource was modified

setFormat

public void setFormat(java.lang.String format)
Sets the format of this dynamic image, such as "jpeg" or "gif"

Parameters:
format - The image format to set.

getImageData

protected abstract byte[] getImageData()
Get image data for our dynamic image resource. If the subclass regenerates the data, it should set the lastModifiedTime when it does so. This ensures that image caching works correctly.

Returns:
The image data for this dynamic image

toImageData

protected byte[] toImageData(java.awt.image.BufferedImage image)
Parameters:
image - The image to turn into data
Returns:
The image data for this dynamic image


Copyright © 2004-2005 Wicket developers. All Rights Reserved.