org.jfree.report
Class DefaultImageReference

java.lang.Object
  |
  +--org.jfree.report.DefaultImageReference

public class DefaultImageReference
extends java.lang.Object
implements java.io.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.

An DefaultImageReference is always used in conjunction with an ImageElement.

This implementation provides a reasonable default implementation to encapsualte local 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(java.awt.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(java.net.URL url)
          Creates a new ImageReference with an origin of 0,0 and the desired width.
 
Method Summary
 java.lang.Object clone()
          Clones this Element.
 boolean equals(java.lang.Object o)
          Checks for equality.
 java.lang.Object getIdentity()
          Returns the identity information.
 java.awt.Image getImage()
          Returns the original image if available.
 int getImageHeight()
          Returns the (unscaled) image height.
 int getImageWidth()
          Returns the (unscaled) image width.
 java.lang.String getName()
          Returns the name of this image reference.
 float getScaleX()
          Returns a predefined scaling factor.
 float getScaleY()
          Returns a predefined scaling factor.
 java.net.URL getSourceURL()
          Returns the source URL for the image.
 java.lang.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.
 java.lang.String toString()
          Returns a String representing this object.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultImageReference

public DefaultImageReference(java.net.URL url)
                      throws java.io.IOException
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:
java.io.IOException - if the url could not be read.
java.lang.NullPointerException - if the given URL is null.

DefaultImageReference

public DefaultImageReference(java.awt.Image img)
                      throws java.io.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:
java.lang.NullPointerException - if the image is null.

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 java.awt.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 java.net.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 java.lang.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 java.lang.String toString()
Returns a String representing this object. Useful for debugging.
Overrides:
toString in class java.lang.Object
Returns:
The string.

equals

public boolean equals(java.lang.Object o)
Checks for equality.
Overrides:
equals in class java.lang.Object
Parameters:
o - 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 java.lang.Object
Returns:
the hashcode

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Clones this Element.
Overrides:
clone in class java.lang.Object
Returns:
a clone of this element.
Throws:
java.lang.CloneNotSupportedException - this should never be thrown.

getImageWidth

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

getImageHeight

public int getImageHeight()
Returns the (unscaled) image height.
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 java.lang.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 java.lang.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.
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.
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.