org.apache.wicket.markup.html.image.resource
Class DynamicImageResource

java.lang.Object
  extended by org.apache.wicket.Resource
      extended by org.apache.wicket.markup.html.WebResource
          extended by org.apache.wicket.markup.html.DynamicWebResource
              extended by org.apache.wicket.markup.html.image.resource.DynamicImageResource
All Implemented Interfaces:
java.io.Serializable, IClusterable, IRequestListener, IResourceListener
Direct Known Subclasses:
BlobImageResource, BufferedDynamicImageResource, CaptchaImageResource, RenderedDynamicImageResource, ThumbnailImageResource

public abstract class DynamicImageResource
extends DynamicWebResource

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, Gili Tzabari, Johan Compagner
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.wicket.markup.html.DynamicWebResource
DynamicWebResource.ResourceState
 
Field Summary
 
Fields inherited from interface org.apache.wicket.IResourceListener
INTERFACE
 
Constructor Summary
DynamicImageResource()
          Creates a dynamic image resource.
DynamicImageResource(java.util.Locale locale)
          Creates a dynamic resource from for the given locale
DynamicImageResource(java.lang.String format)
          Creates a dynamic resource from for the given locale
DynamicImageResource(java.lang.String format, java.util.Locale locale)
          Creates a dynamic resource from for the given locale
 
Method Summary
 java.lang.String getFormat()
           
protected abstract  byte[] getImageData()
          Get image data for our dynamic image resource.
protected  DynamicWebResource.ResourceState getResourceState()
          Gets the byte array for our dynamic resource.
 void setFormat(java.lang.String format)
          Sets the format of this resource
protected  void setLastModifiedTime(Time time)
          set the last modified time for this resource.
protected  byte[] toImageData(java.awt.image.BufferedImage image)
           
 
Methods inherited from class org.apache.wicket.markup.html.DynamicWebResource
getLocale, getResourceStream, setHeaders
 
Methods inherited from class org.apache.wicket.markup.html.WebResource
configureResponse, getCacheDuration
 
Methods inherited from class org.apache.wicket.Resource
getParameters, invalidate, isCacheable, onResourceRequested, setCacheable, setParameters
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DynamicImageResource

public DynamicImageResource()
Creates a dynamic image resource.


DynamicImageResource

public DynamicImageResource(java.util.Locale locale)
Creates a dynamic resource from for the given locale

Parameters:
locale - The locale of this resource

DynamicImageResource

public DynamicImageResource(java.lang.String format)
Creates a dynamic resource from for the given locale

Parameters:
format - The image format ("png", "jpeg", etc)

DynamicImageResource

public DynamicImageResource(java.lang.String format,
                            java.util.Locale locale)
Creates a dynamic resource from for the given locale

Parameters:
format - The image format ("png", "jpeg", etc)
locale - The locale of this resource
Method Detail

getFormat

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

setFormat

public final void setFormat(java.lang.String format)
Sets the format of this resource

Parameters:
format - The format (jpg, png or gif..)

setLastModifiedTime

protected void setLastModifiedTime(Time time)
set the last modified time for this resource.

Parameters:
time -

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

getResourceState

protected DynamicWebResource.ResourceState getResourceState()
Description copied from class: DynamicWebResource
Gets the byte array for our dynamic resource. If the subclass regenerates the data, it should set the lastModifiedTime too. This ensures that resource caching works correctly.

Specified by:
getResourceState in class DynamicWebResource
Returns:
The byte array for this dynamic resource.
See Also:
DynamicWebResource.getResourceState()

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


Copyright © 2004-2010 Apache Software Foundation. All Rights Reserved.