Class 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.

    Thomas Morgner
    See Also:
    Serialized Form
    • 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.
        img - the image for this reference.
        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
      • 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.
        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.
        parent - the parent.
    • Method Detail

      • getImage

        public Image getImage()
        Returns the original image if available.
        Specified by:
        getImage in interface LocalImageContainer
        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
        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
        a String representing the assigned URL.
      • toString

        public String toString()
        Returns a String representing this object. Useful for debugging.
        toString in class Object
        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
        the resource key.
      • equals

        public boolean equals​(Object obj)
        Checks for equality.
        equals in class Object
        obj - the object to test.
        true if the specified object is equal to this one.
      • hashCode

        public int hashCode()
        Compute a hashcode for this imageReference.
        hashCode in class Object
        the hashcode
      • getImageWidth

        public int getImageWidth()
        Returns the (unscaled) image width.
        Specified by:
        getImageWidth in interface ImageContainer
        the image width.
      • getImageHeight

        public int getImageHeight()
        Returns the (unscaled) image height.
        Specified by:
        getImageHeight in interface ImageContainer
        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
        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
        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
        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
        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
        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
        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).

        sx - the scale factor.
        sy - the scale factor.