Author: ehillenius
Date: Thu Nov 30 10:14:33 2006
New Revision: 481024
URL: http://svn.apache.org/viewvc?view=rev&rev=481024
Log:
WICKET-130
Modified:
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/html/image/resource/RenderedDynamicImageResource.java
Modified:
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/html/image/resource/RenderedDynamicImageResource.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/html/image/resource/RenderedDynamicImageResource.java?view=diff&rev=481024&r1=481023&r2=481024
==============================================================================
---
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/html/image/resource/RenderedDynamicImageResource.java
(original)
+++
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/html/image/resource/RenderedDynamicImageResource.java
Thu Nov 30 10:14:33 2006
@@ -33,7 +33,7 @@
* 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.
- *
+ *
* @see wicket.markup.html.image.resource.DefaultButtonImageResource
* @see wicket.markup.html.image.resource.DefaultButtonImageResourceFactory
* @author Jonathan Locke
@@ -42,157 +42,157 @@
*/
public abstract class RenderedDynamicImageResource extends DynamicImageResource
{
- private static final long serialVersionUID = 1L;
-
- /** Height of image */
- private int height = 100;
-
- /** Transient image data so that image only needs to be generated once per
VM */
- private transient SoftReference imageData;
-
- /** Type of image (one of BufferedImage.TYPE_*) */
- private int type = BufferedImage.TYPE_INT_RGB;
-
- /** Width of image */
- private int width = 100;
-
- /**
- * Constructor.
- *
- * @param width
- * Width of image
- * @param height
- * Height of image
- */
- public RenderedDynamicImageResource(final int width, final int height)
- {
- this.width = width;
- this.height = height;
- }
-
- /**
- * Constructor.
- *
- * @param width
- * Width of image
- * @param height
- * Height of image
- * @param format
- * The format of the image (jpg, png or gif)
- */
- public RenderedDynamicImageResource(final int width, final int height,
String format)
- {
- super(format);
- this.width = width;
- this.height = height;
- }
-
- /**
- * @return Returns the height.
- */
- public synchronized int getHeight()
- {
- return height;
- }
-
- /**
- * @return Returns the type (one of BufferedImage.TYPE_*).
- */
- public synchronized int getType()
- {
- return type;
- }
-
- /**
- * @return Returns the width.
- */
- public synchronized int getWidth()
- {
- return width;
- }
-
- /**
- * Causes the image to be redrawn the next time its requested.
- *
- * @see wicket.Resource#invalidate()
- */
- public synchronized void invalidate()
- {
- imageData = null;
- }
-
- /**
- * @param height
- * The height to set.
- */
- public synchronized void setHeight(int height)
- {
- this.height = height;
- invalidate();
- }
-
- /**
- * @param type
- * The type to set (one of BufferedImage.TYPE_*).
- */
- public synchronized void setType(int type)
- {
- this.type = type;
- invalidate();
- }
-
- /**
- * @param width
- * The width to set.
- */
- public synchronized void setWidth(int width)
- {
- this.width = width;
- invalidate();
- }
-
- protected byte[] getImageData()
- {
- // get image data is always called in sync block
- byte[] data = null;
- if (imageData != null)
- {
- data = (byte[])imageData.get();
- }
- if (data == null)
- {
- data = render();
- imageData = new SoftReference(data);
- setLastModifiedTime(Time.now());
- }
- return data;
- }
-
- /**
- * Renders this image
- *
- * @return The image data
- */
- protected byte[] render()
- {
- while (true)
- {
- final BufferedImage image = new BufferedImage(width, height, type);
- if (render((Graphics2D)image.getGraphics()))
- {
- return toImageData(image);
- }
- }
- }
-
- /**
- * Override this method to provide your rendering code
- *
- * @param graphics
- * The graphics context to render on
- * @return True if the image was rendered. False if the image size was
- * changed by the rendering implementation and the image should be
- * re-rendered at the new size.
- */
- protected abstract boolean render(Graphics2D graphics);
+ private static final long serialVersionUID = 1L;
+
+ /** Height of image */
+ private int height = 100;
+
+ /** Transient image data so that image only needs to be generated once
per VM */
+ private transient SoftReference imageData;
+
+ /** Type of image (one of BufferedImage.TYPE_*) */
+ private int type = BufferedImage.TYPE_INT_RGB;
+
+ /** Width of image */
+ private int width = 100;
+
+ /**
+ * Constructor.
+ *
+ * @param width
+ * Width of image
+ * @param height
+ * Height of image
+ */
+ public RenderedDynamicImageResource(final int width, final int height)
+ {
+ this.width = width;
+ this.height = height;
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param width
+ * Width of image
+ * @param height
+ * Height of image
+ * @param format
+ * The format of the image (jpg, png or gif)
+ */
+ public RenderedDynamicImageResource(final int width, final int height,
String format)
+ {
+ super(format);
+ this.width = width;
+ this.height = height;
+ }
+
+ /**
+ * @return Returns the height.
+ */
+ public synchronized int getHeight()
+ {
+ return height;
+ }
+
+ /**
+ * @return Returns the type (one of BufferedImage.TYPE_*).
+ */
+ public synchronized int getType()
+ {
+ return type;
+ }
+
+ /**
+ * @return Returns the width.
+ */
+ public synchronized int getWidth()
+ {
+ return width;
+ }
+
+ /**
+ * Causes the image to be redrawn the next time its requested.
+ *
+ * @see wicket.Resource#invalidate()
+ */
+ public synchronized void invalidate()
+ {
+ imageData = null;
+ }
+
+ /**
+ * @param height
+ * The height to set.
+ */
+ public synchronized void setHeight(int height)
+ {
+ this.height = height;
+ invalidate();
+ }
+
+ /**
+ * @param type
+ * The type to set (one of BufferedImage.TYPE_*).
+ */
+ public synchronized void setType(int type)
+ {
+ this.type = type;
+ invalidate();
+ }
+
+ /**
+ * @param width
+ * The width to set.
+ */
+ public synchronized void setWidth(int width)
+ {
+ this.width = width;
+ invalidate();
+ }
+
+ protected byte[] getImageData()
+ {
+ // get image data is always called in sync block
+ byte[] data = null;
+ if (imageData != null)
+ {
+ data = (byte[])imageData.get();
+ }
+ if (data == null)
+ {
+ data = render();
+ imageData = new SoftReference(data);
+ setLastModifiedTime(Time.now());
+ }
+ return data;
+ }
+
+ /**
+ * Renders this image
+ *
+ * @return The image data
+ */
+ protected byte[] render()
+ {
+ while (true)
+ {
+ final BufferedImage image = new
BufferedImage(getWidth(), getHeight(), getType());
+ if (render((Graphics2D)image.getGraphics()))
+ {
+ return toImageData(image);
+ }
+ }
+ }
+
+ /**
+ * Override this method to provide your rendering code
+ *
+ * @param graphics
+ * The graphics context to render on
+ * @return True if the image was rendered. False if the image size was
+ * changed by the rendering implementation and the image should
be
+ * re-rendered at the new size.
+ */
+ protected abstract boolean render(Graphics2D graphics);
}