Class RenderedDynamicImageResource
- java.lang.Object
-
- org.apache.wicket.request.resource.AbstractResource
-
- org.apache.wicket.request.resource.DynamicImageResource
-
- org.apache.wicket.markup.html.image.resource.RenderedDynamicImageResource
-
- All Implemented Interfaces:
java.io.Serializable,IResource,org.apache.wicket.util.io.IClusterable
- Direct Known Subclasses:
DefaultButtonImageResource
public abstract class RenderedDynamicImageResource extends DynamicImageResource
A DynamicImageResource subclass that allows easy rendering of regeneratable (unbuffered) dynamic images. A RenderedDynamicImageResource implements the abstract method render(Graphics2D) to create/re-create a given image on-the-fly. When a RenderedDynamicImageResource is serialized, the image state is transient, which means it will disappear when the resource is sent over the wire and then will be recreated when required.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:
DefaultButtonImageResource,DefaultButtonImageResourceFactory, Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.wicket.request.resource.AbstractResource
AbstractResource.ContentRangeType, AbstractResource.ResourceResponse, AbstractResource.WriteCallback
-
Nested classes/interfaces inherited from interface org.apache.wicket.request.resource.IResource
IResource.Attributes
-
-
Field Summary
-
Fields inherited from class org.apache.wicket.request.resource.AbstractResource
CONTENT_DISPOSITION_HEADER_NAME, CONTENT_RANGE_ENDBYTE, CONTENT_RANGE_STARTBYTE, INTERNAL_HEADERS
-
-
Constructor Summary
Constructors Constructor Description RenderedDynamicImageResource(int width, int height)Constructor.RenderedDynamicImageResource(int width, int height, java.lang.String format)Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description intgetHeight()protected byte[]getImageData(IResource.Attributes attributes)Get image data for our dynamic image resource.intgetType()intgetWidth()voidinvalidate()Causes the image to be redrawn the next time its requested.protected abstract booleanrender(java.awt.Graphics2D graphics, IResource.Attributes attributes)Override this method to provide your rendering code.protected byte[]render(IResource.Attributes attributes)Renders this imagevoidsetHeight(int height)voidsetType(int type)voidsetWidth(int width)-
Methods inherited from class org.apache.wicket.request.resource.DynamicImageResource
configureResponse, getFormat, newResourceResponse, setFormat, setLastModifiedTime, toImageData
-
Methods inherited from class org.apache.wicket.request.resource.AbstractResource
configureCache, getCachingStrategy, respond, setRequestMetaData, setRequestRangeMetaData, setResponseContentRangeHeaderFields, setResponseHeaders
-
-
-
-
Constructor Detail
-
RenderedDynamicImageResource
public RenderedDynamicImageResource(int width, int height)Constructor.- Parameters:
width- Width of imageheight- Height of image
-
RenderedDynamicImageResource
public RenderedDynamicImageResource(int width, int height, java.lang.String format)Constructor.- Parameters:
width- Width of imageheight- Height of imageformat- The format of the image (jpg, png or gif)
-
-
Method Detail
-
getHeight
public int getHeight()
- Returns:
- Returns the height.
-
getType
public int getType()
- Returns:
- Returns the type (one of BufferedImage.TYPE_*).
-
getWidth
public int getWidth()
- Returns:
- Returns the width.
-
invalidate
public void invalidate()
Causes the image to be redrawn the next time its requested.
-
setHeight
public void setHeight(int height)
- Parameters:
height- The height to set.
-
setType
public void setType(int type)
- Parameters:
type- The type to set (one of BufferedImage.TYPE_*).
-
setWidth
public void setWidth(int width)
- Parameters:
width- The width to set.
-
getImageData
protected byte[] getImageData(IResource.Attributes attributes)
Description copied from class:DynamicImageResourceGet image data for our dynamic image resource. If the subclass regenerates the data, it should set theDynamicImageResource.setLastModifiedTime(Time)when it does so. This ensures that image caching works correctly.- Specified by:
getImageDatain classDynamicImageResource- Parameters:
attributes- the context bringing the request, response and the parameters- Returns:
- The image data for this dynamic image.
nullmeans there is no image and 404 (Not found) response will be return.
-
render
protected byte[] render(IResource.Attributes attributes)
Renders this image- Parameters:
attributes- the current request attributes- Returns:
- The image data
-
render
protected abstract boolean render(java.awt.Graphics2D graphics, IResource.Attributes attributes)Override this method to provide your rendering code.- Parameters:
graphics- The graphics context to render on.attributes- the current request attributes- Returns:
trueif the image was rendered.falseif the image size was changed by the rendering implementation and the image should be re-rendered at the new size.
-
-