org.pentaho.reporting.engine.classic.core
Class DefaultImageReference

java.lang.Object
  extended by org.pentaho.reporting.engine.classic.core.DefaultImageReference
All Implemented Interfaces:
Serializable, Cloneable, ImageContainer, LocalImageContainer, URLImageContainer

public class DefaultImageReference
extends Object
implements Serializable, URLImageContainer, LocalImageContainer

An DefaultImageReference encapsulates the source of an image together with a java.awt.Image. The source is used to create a higher resolution version if needed. The source file/URL may also be inlined into the output target, to create better results.

This implementation provides a reasonable default implementation to encapsualte local AWT-images into reports.

The given image might specify a fixed scale factor for the given image. The scaling will be applied before any layout computations will be performed.

Author:
Thomas Morgner
See Also:
Serialized Form

Constructor Summary
DefaultImageReference(DefaultImageReference parent)
          Copies the contents of the given DefaultImageReference.
DefaultImageReference(Image img)
          Creates a new ImageReference without an assigned URL for the Image.
DefaultImageReference(int w, int h)
          Creates a new image reference without assigning either an Image or an URL.
DefaultImageReference(org.pentaho.reporting.libraries.resourceloader.Resource imageResource)
           
DefaultImageReference(URL url)
          Deprecated. This method auto-creates a new resource-manager for each image and therefore possibly prevents effective caching. Use the Resource-accepting constructor instead.
 
Method Summary
 Object clone()
          Clones this Element.
 boolean equals(Object obj)
          Checks for equality.
 Object getIdentity()
          Returns the identity information.
 Image getImage()
          Returns the original image if available.
 int getImageHeight()
          Returns the (unscaled) image height.
 int getImageWidth()
          Returns the (unscaled) image width.
 String getName()
          Returns the name of this image reference.
 org.pentaho.reporting.libraries.resourceloader.ResourceKey getResourceKey()
          Returns the resourcekey that was used to load the image.
 float getScaleX()
          Returns a predefined scaling factor.
 float getScaleY()
          Returns a predefined scaling factor.
 URL getSourceURL()
          Returns the source URL for the image.
 String getSourceURLString()
          Returns the a string version of the source URL.
 int hashCode()
          Compute a hashcode for this imageReference.
 boolean isIdentifiable()
          Checks whether this image has a assigned identity.
 boolean isLoadable()
          Checks whether this image reference is loadable.
 void setScale(float sx, float sy)
          Defines a predefined scaling factor.
 String toString()
          Returns a String representing this object.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultImageReference

public DefaultImageReference(URL url)
                      throws IOException
Deprecated. This method auto-creates a new resource-manager for each image and therefore possibly prevents effective caching. Use the Resource-accepting constructor instead.

Creates a new ImageReference with an origin of 0,0 and the desired width. The image data is read from the given URL.

Parameters:
url - the source url. The url must be readable during the report generation.
Throws:
IOException - if the url could not be read.
NullPointerException - if the given URL is null.

DefaultImageReference

public DefaultImageReference(Image img)
                      throws IOException
Creates a new ImageReference without an assigned URL for the Image. This image reference will not be loadable and cannot be used to embedd the original rawdata of the image into the generated content.

Parameters:
img - the image for this reference.
Throws:
NullPointerException - if the image is null.
IOException - if an IOError occured while loading the image.

DefaultImageReference

public DefaultImageReference(org.pentaho.reporting.libraries.resourceloader.Resource imageResource)
                      throws org.pentaho.reporting.libraries.resourceloader.ResourceException
Throws:
org.pentaho.reporting.libraries.resourceloader.ResourceException

DefaultImageReference

public DefaultImageReference(int w,
                             int h)
Creates a new image reference without assigning either an Image or an URL. This DefaultImageReference will act as place holder to reserve space during the layouting, no content will be generated.

Parameters:
w - the width of the unscaled image.
h - the height of the unscaled image.

DefaultImageReference

public DefaultImageReference(DefaultImageReference parent)
Copies the contents of the given DefaultImageReference.

Parameters:
parent - the parent.
Method Detail

getImage

public Image getImage()
Returns the original image if available.

Specified by:
getImage in interface LocalImageContainer
Returns:
The current image instance, or null, if no image has been assigned.

getSourceURL

public URL getSourceURL()
Returns the source URL for the image.

Specified by:
getSourceURL in interface URLImageContainer
Returns:
The URL from where the image has been loaded, or null, if the source URL is not known.

getSourceURLString

public String getSourceURLString()
Returns the a string version of the source URL. If no URL has been assigned, this method will return null.

Specified by:
getSourceURLString in interface URLImageContainer
Returns:
a String representing the assigned URL.

toString

public String toString()
Returns a String representing this object. Useful for debugging.

Overrides:
toString in class Object
Returns:
The string.

getResourceKey

public org.pentaho.reporting.libraries.resourceloader.ResourceKey getResourceKey()
Description copied from interface: URLImageContainer
Returns the resourcekey that was used to load the image.

Specified by:
getResourceKey in interface URLImageContainer
Returns:
the resource key.

equals

public boolean equals(Object obj)
Checks for equality.

Overrides:
equals in class Object
Parameters:
obj - the object to test.
Returns:
true if the specified object is equal to this one.

hashCode

public int hashCode()
Compute a hashcode for this imageReference.

Overrides:
hashCode in class Object
Returns:
the hashcode

clone

public Object clone()
             throws CloneNotSupportedException
Clones this Element.

Overrides:
clone in class Object
Returns:
a clone of this element.
Throws:
CloneNotSupportedException - this should never be thrown.

getImageWidth

public int getImageWidth()
Returns the (unscaled) image width.

Specified by:
getImageWidth in interface ImageContainer
Returns:
the image width.

getImageHeight

public int getImageHeight()
Returns the (unscaled) image height.

Specified by:
getImageHeight in interface ImageContainer
Returns:
the image height.

isLoadable

public boolean isLoadable()
Checks whether this image reference is loadable. A default image reference is loadable, if a valid URL has been set.

Specified by:
isLoadable in interface URLImageContainer
Returns:
true, if it is loadable, false otherwise.

getIdentity

public Object getIdentity()
Returns the identity information. This instance returns the URL of the image, if any.

Specified by:
getIdentity in interface LocalImageContainer
Returns:
the image identifier.

getName

public String getName()
Returns the name of this image reference. If an URL has been set, this will return the URL of the image, else null is returned.

Specified by:
getName in interface LocalImageContainer
Returns:
the name.

isIdentifiable

public boolean isIdentifiable()
Checks whether this image has a assigned identity. Two identities should be equal, if the image contents are equal.

Specified by:
isIdentifiable in interface LocalImageContainer
Returns:
true, if that image contains contains identity information, false otherwise.

getScaleX

public float getScaleX()
Returns a predefined scaling factor. That scaling will be applied before any layout specific scaling is done.

Specified by:
getScaleX in interface ImageContainer
Returns:
the scale factor.

getScaleY

public float getScaleY()
Returns a predefined scaling factor. That scaling will be applied before any layout specific scaling is done.

Specified by:
getScaleY in interface ImageContainer
Returns:
the scale factor.

setScale

public void setScale(float sx,
                     float sy)
Defines a predefined scaling factor. That scaling will be applied before any layout specific scaling is done.

If your image has a higher resolution than 72dpi, this factor should be a value lower than 1 (the image will be scaled down).

Parameters:
sx - the scale factor.
sy - the scale factor.