Class DefaultImageReference
- java.lang.Object
-
- 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 ajava.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
Constructors Constructor Description DefaultImageReference(int w, int h)
Creates a new image reference without assigning either an Image or an URL.DefaultImageReference(Image img)
Creates a new ImageReference without an assigned URL for the Image.DefaultImageReference(DefaultImageReference parent)
Copies the contents of the given DefaultImageReference.DefaultImageReference(org.pentaho.reporting.libraries.resourceloader.Resource imageResource)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.
-
-
-
Constructor Detail
-
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 interfaceLocalImageContainer
- 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 interfaceURLImageContainer
- 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 interfaceURLImageContainer
- Returns:
- a String representing the assigned URL.
-
toString
public String toString()
Returns a String representing this object. Useful for debugging.
-
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 interfaceURLImageContainer
- Returns:
- the resource key.
-
equals
public boolean equals(Object obj)
Checks for equality.
-
hashCode
public int hashCode()
Compute a hashcode for this imageReference.
-
clone
public Object clone() throws CloneNotSupportedException
Clones this Element.- Overrides:
clone
in classObject
- 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 interfaceImageContainer
- Returns:
- the image width.
-
getImageHeight
public int getImageHeight()
Returns the (unscaled) image height.- Specified by:
getImageHeight
in interfaceImageContainer
- 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 interfaceURLImageContainer
- 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 interfaceLocalImageContainer
- 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 interfaceLocalImageContainer
- 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 interfaceLocalImageContainer
- 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 interfaceImageContainer
- 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 interfaceImageContainer
- 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.
-
-