EchoPoint
1.0

echopoint.image
Class EncodedImageReference

java.lang.Object
  extended bynextapp.echo.AbstractImageReference
      extended bynextapp.echo.StreamImageReference
          extended byechopoint.image.EncodedImageReference
All Implemented Interfaces:
nextapp.echo.ImageReference, java.io.Serializable
Direct Known Subclasses:
TextImageReference

public class EncodedImageReference
extends nextapp.echo.StreamImageReference
implements java.io.Serializable

The EncodedImageReference class is an ImageReference that can render java.awt.Image objects. The ImageEncoder used to encode the image data is pluggable.

This class allows you to balance memory usage versus processor usage.

By default the output of the encoding is not kept in memory, so the encoding runs every time the image needs to be rendered. However this can be changed so that the encoding results are kept in memory.

If the image data is cached, they are kept in a SoftReference so they may be reclaimed by the GC if memory gets low.

The AWT Image object that is renderered is by default kept in memory. You can change this by deriving a new class from EncodedImageReference and then drawing the AWT image on as needed basis during the call to getImage().

Author:
Brad Baker
See Also:
Serialized Form

Field Summary
 
Fields inherited from class nextapp.echo.AbstractImageReference
listenerList
 
Fields inherited from interface nextapp.echo.ImageReference
SIZE_UNKNOWN
 
Constructor Summary
EncodedImageReference()
          Constructs an EncodedImageReference without an image.
EncodedImageReference(java.awt.Image image)
          Constructs an EncodedImageReference with an image.
 
Method Summary
 java.lang.String getContentType()
           
 ImageEncoder getEncoder()
          Returns the ImageEncoder in use.
 int getHeight()
          This returns the height of the Image
 java.awt.Image getImage()
          Returns the Image in use.
 int getWidth()
          This returns the width of the Image
 boolean isKeptInMemory()
          Returns true if the encoded image is cached in memory.
 boolean isValid()
          This returns whether the AWT Image data is currently valid.
 void render(java.io.OutputStream out)
           
 void setEncoder(ImageEncoder encoder)
          Sets the ImageEncoder to use for encoding
 void setImage(java.awt.Image image)
          Sets the Image to encode.
 void setKeptInMemory(boolean b)
          If set to true, the image will be encoded only as necessary and then cached in memory, otherwise it will be encoded as required.
 void setValid(boolean valid)
          This controls whether the AWT Image data is currently valid.
 void update()
           
 
Methods inherited from class nextapp.echo.AbstractImageReference
addImageUpdateListener, removeImageUpdateListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EncodedImageReference

public EncodedImageReference()
Constructs an EncodedImageReference without an image. You must of course call setImage() before the image is rendered, otherwise there will be nothing to render.

Another alternative would be to derive a new class and override getImage() to provide the image as necessary. This will use a smallest amount of memory at the expense of more CPU processing.


EncodedImageReference

public EncodedImageReference(java.awt.Image image)
Constructs an EncodedImageReference with an image.

Parameters:
image - A java.awt.Image to be displayed. If you intend to extend this class and override the getImage() method to return images only as they are needed, then you may pass null to this parameter.
Method Detail

getContentType

public java.lang.String getContentType()
See Also:
StreamImageReference.getContentType()

getEncoder

public ImageEncoder getEncoder()
Returns the ImageEncoder in use.

Returns:
ImageEncoder

getHeight

public int getHeight()
This returns the height of the Image

Specified by:
getHeight in interface nextapp.echo.ImageReference
See Also:
ImageReference.getHeight()

getImage

public java.awt.Image getImage()
Returns the Image in use.

You may extend this class and override this method such that images are created only when they are needed, thereby reducing memory usage at the cost of increased processor workload.

Returns:
Image - the AWT image object

getWidth

public int getWidth()
This returns the width of the Image

Specified by:
getWidth in interface nextapp.echo.ImageReference
See Also:
ImageReference.getWidth()

isKeptInMemory

public boolean isKeptInMemory()
Returns true if the encoded image is cached in memory.

Returns:
boolean true if the image is kept in memory

isValid

public boolean isValid()
This returns whether the AWT Image data is currently valid.

Returns:
- true if the AWT image is valid

render

public void render(java.io.OutputStream out)
            throws java.io.IOException
Throws:
java.io.IOException
See Also:
StreamImageReference.render(java.io.OutputStream)

setEncoder

public void setEncoder(ImageEncoder encoder)
Sets the ImageEncoder to use for encoding

Parameters:
encoder -

setImage

public void setImage(java.awt.Image image)
Sets the Image to encode. This can be null.

Parameters:
image - - the AWT Image to encode.

setKeptInMemory

public void setKeptInMemory(boolean b)
If set to true, the image will be encoded only as necessary and then cached in memory, otherwise it will be encoded as required.

Parameters:
b -

setValid

public void setValid(boolean valid)
This controls whether the AWT Image data is currently valid.

This is used to determine whether a call to getImage() should be made. If the encoded image is kept in memory but the image is invalid, then it will be encoded again. If it valid, then the cached encoded image data can be re-used.

If you derive a new class and override the getImage() method, you should set this to false when the image needs to be re-painted.

Parameters:
valid - - true if the AWT image data is valid.

update

public void update()
Specified by:
update in interface nextapp.echo.ImageReference
See Also:
ImageReference.update()

EchoPoint
1.0