edu.umd.cs.jazz.component
Class ZImage

java.lang.Object
  |
  +--edu.umd.cs.jazz.ZSceneGraphObject
        |
        +--edu.umd.cs.jazz.ZVisualComponent
              |
              +--edu.umd.cs.jazz.component.ZImage
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable, ZSerializable

public class ZImage
extends ZVisualComponent
implements java.io.Serializable

ZImage is a graphic object that represents a raster image.

Warning: Serialized and ZSerialized objects of this class will not be compatible with future Jazz releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Jazz. A future release of Jazz will provide support for long term persistence.

Author:
Benjamin B. Bederson
See Also:
Serialized Form

Field Summary
protected  java.lang.String fileName
          FileName of the image, if it came from a file.
protected  int height
          The dimensions of the image.
protected  java.awt.Image image
           
protected  edu.umd.cs.jazz.component.ZImage.ZImageObserver observer
           
protected static java.awt.Frame staticFrame
           
protected  double translateX
          Translation offset X.
protected  double translateY
          Translation offset Y.
protected  java.net.URL url
          URL of the image, if it came from a URL.
protected  int width
          The dimensions of the image.
protected  boolean writeEmbeddedImage
          Embed image in save file, or just it's filename.
static boolean writeEmbeddedImage_DEFAULT
           
 
Fields inherited from class edu.umd.cs.jazz.ZSceneGraphObject
bounds, listenerList, volatileBounds, volatileBounds_DEFAULT
 
Constructor Summary
ZImage()
          Constructs a new ZImage.
ZImage(byte[] bytes)
          Constructs a new ZImage from a byte array.
ZImage(java.awt.Image i)
          Constructs a new ZImage from an Image.
ZImage(java.lang.String aFileName)
          Constructs a new ZImage from a file.
ZImage(java.net.URL aUrl)
          Constructs a new ZImage from a URL.
 
Method Summary
protected  void computeBounds()
          Notifies this object that it has changed and that it should update its notion of its bounding box.
 java.lang.String dump()
          Generate a string that represents this object for debugging.
protected  java.lang.Object duplicateObject()
          Returns a clone of this object.
 java.lang.String getAbsolutePath(java.lang.String path)
          Given a directory path plus some path relative to it, return a direct absolute path.
 java.lang.String getFileName()
          Return the filename associated with this image object.
 int getHeight()
          Return height of image.
 java.awt.Image getImage()
          Return the AWT image associated with this image object.
 java.lang.String getRelativePath(java.lang.String fileName, java.lang.String basePath)
          Returns the directory path of a file name, relative to another absolute path basePath.
 double getTranslateX()
          Get the X offset translation.
 double getTranslateY()
          Get the Y offset translation.
 java.awt.geom.Point2D getTranslation()
          Get the image translation offset.
 java.net.URL getUrl()
          Return the URL associated with this image object.
 int getWidth()
          Return width of image.
 boolean getWriteEmbeddedImage()
          Determine if this image gets saved by writing the binary image into the file.
 boolean isLoaded()
          Determines if the image has been loaded yet or not.
protected  void loadImage(java.awt.Image im)
          Utility method to wait until the specified image is loaded, and then return.
static java.awt.image.BufferedImage makeBufferedImage(java.awt.Image image)
          Creates a BufferedImage from an Image.
 void render(ZRenderContext renderContext)
          Paints this object.
 void setFileName(java.lang.String aFileName)
          Sets the filename of the image.
 boolean setImage(byte[] bytes)
          Set the image to the one consisting of the specified bytes.
 boolean setImage(java.awt.Image im)
          Set the image to the one consisting of the specified image.
 boolean setImage(java.lang.String aFileName)
          Set the image to the one at the specified URL or filename.
 boolean setImage(java.net.URL aUrl)
          Set the image to the one at the specified URL.
protected  void setLoaded(boolean l)
          Called when the image has been loaded.
 void setState(java.lang.String fieldType, java.lang.String fieldName, java.lang.Object fieldValue)
          Set some state of this object as it gets read back in.
 void setTranslateX(double x)
          Set image translation offset X.
 void setTranslateY(double y)
          Set image translation offset Y.
 void setTranslation(double x, double y)
          Set the image translation offset to the specified position.
 void setTranslation(java.awt.geom.Point2D p)
          Set the image translation offset to point p.
 void setUrl(java.net.URL aUrl)
          Sets the URL of the image.
 void setWriteEmbeddedImage(boolean value)
          Specify if this image gets saved by writing the binary image into the file, or if it instead writes the filename of the image, and thus requires that the external image file exists in the same place to reload.
static boolean waitForImage(java.awt.Image image)
          Wait while image is loaded.
 void writeObject(ZObjectOutputStream out)
          Write out all of this object's state.
 
Methods inherited from class edu.umd.cs.jazz.ZVisualComponent
addParent, getNumParents, getParents, getParentsReference, getRoot, paint, pick, pickBounds, removeParent, repaint, repaint, trimToSize, updateBounds, updateObjectReferences, updateParentBounds, updateVolatility, writeObjectRecurse
 
Methods inherited from class edu.umd.cs.jazz.ZSceneGraphObject
addMouseListener, addMouseMotionListener, clone, fireEvent, fireMouseEvent, getBounds, getBoundsReference, getListenerList, getVolatileBounds, hasLisenerOfType, hasMouseListener, processMouseEvent, removeEventListener, removeMouseListener, removeMouseMotionListener, reshape, setBounds, setVolatileBounds
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

writeEmbeddedImage_DEFAULT

public static final boolean writeEmbeddedImage_DEFAULT

staticFrame

protected static final java.awt.Frame staticFrame

width

protected int width
The dimensions of the image. -1 if not known yet.

height

protected int height
The dimensions of the image. -1 if not known yet.

image

protected transient java.awt.Image image

observer

protected edu.umd.cs.jazz.component.ZImage.ZImageObserver observer

writeEmbeddedImage

protected boolean writeEmbeddedImage
Embed image in save file, or just it's filename.

fileName

protected transient java.lang.String fileName
FileName of the image, if it came from a file.

url

protected java.net.URL url
URL of the image, if it came from a URL.

translateX

protected double translateX
Translation offset X.

translateY

protected double translateY
Translation offset Y.
Constructor Detail

ZImage

public ZImage()
Constructs a new ZImage.

ZImage

public ZImage(java.awt.Image i)
Constructs a new ZImage from an Image.

ZImage

public ZImage(java.lang.String aFileName)
Constructs a new ZImage from a file.

ZImage

public ZImage(java.net.URL aUrl)
Constructs a new ZImage from a URL.

ZImage

public ZImage(byte[] bytes)
Constructs a new ZImage from a byte array.
Method Detail

duplicateObject

protected java.lang.Object duplicateObject()
Returns a clone of this object.
Overrides:
duplicateObject in class ZVisualComponent
See Also:
ZSceneGraphObject.duplicateObject()

getAbsolutePath

public java.lang.String getAbsolutePath(java.lang.String path)
Given a directory path plus some path relative to it, return a direct absolute path. eg "/a/b/c/" + "../../e/f/g.ext" yields: /a/e/f/g.ext

getRelativePath

public java.lang.String getRelativePath(java.lang.String fileName,
                                        java.lang.String basePath)
Returns the directory path of a file name, relative to another absolute path basePath.
Parameters:
fileName - absolute path of a file.
baseName - absolute base path.

setTranslateX

public void setTranslateX(double x)
Set image translation offset X.
Parameters:
x - the X translation.

getTranslateX

public double getTranslateX()
Get the X offset translation.
Returns:
the X translation.

setTranslateY

public void setTranslateY(double y)
Set image translation offset Y.
Parameters:
y - the Y translation.

getTranslateY

public double getTranslateY()
Get the Y offset translation.
Returns:
the Y translation.

setTranslation

public void setTranslation(double x,
                           double y)
Set the image translation offset to the specified position.
Parameters:
x - the X-coord of translation
y - the Y-coord of translation

setTranslation

public void setTranslation(java.awt.geom.Point2D p)
Set the image translation offset to point p.
Parameters:
p - The translation offset.

getTranslation

public java.awt.geom.Point2D getTranslation()
Get the image translation offset.
Returns:
The translation offset.

setImage

public boolean setImage(java.awt.Image im)
Set the image to the one consisting of the specified image. Wait until the image is loaded before returning.
Parameters:
i - the image.

setImage

public boolean setImage(byte[] bytes)
Set the image to the one consisting of the specified bytes. Wait until the image is loaded before returning.
Parameters:
bytes - the bytes of the image.

setImage

public boolean setImage(java.lang.String aFileName)
Set the image to the one at the specified URL or filename. Wait until the image is loaded before returning.
Parameters:
aFileName - the URL or file name of the image.

setImage

public boolean setImage(java.net.URL aUrl)
Set the image to the one at the specified URL. Wait until the image is loaded before returning.
Parameters:
aURL - the URL of the image.

loadImage

protected void loadImage(java.awt.Image im)
Utility method to wait until the specified image is loaded, and then return.

getImage

public java.awt.Image getImage()
Return the AWT image associated with this image object.
Returns:
the AWT image.

setFileName

public void setFileName(java.lang.String aFileName)
Sets the filename of the image. This does not change the image, but rather just stores the filename for future access.
Parameters:
aFileName - the file name.

getFileName

public java.lang.String getFileName()
Return the filename associated with this image object.
Returns:
the filename.

setUrl

public void setUrl(java.net.URL aUrl)
Sets the URL of the image. This does not change the image, but rather just stores the URL for future access.
Parameters:
aURL - the file name.

getUrl

public java.net.URL getUrl()
Return the URL associated with this image object.
Returns:
the URL.

setWriteEmbeddedImage

public void setWriteEmbeddedImage(boolean value)
Specify if this image gets saved by writing the binary image into the file, or if it instead writes the filename of the image, and thus requires that the external image file exists in the same place to reload.
Parameters:
value - true to embed image in file, and false to store a link

getWriteEmbeddedImage

public boolean getWriteEmbeddedImage()
Determine if this image gets saved by writing the binary image into the file. Return false if it stores the name of the file that contains the image.
Returns:
true to embed image in file

computeBounds

protected void computeBounds()
Notifies this object that it has changed and that it should update its notion of its bounding box. Note that this should not be called directly. Instead, it is called by updateBounds when needed.
Overrides:
computeBounds in class ZSceneGraphObject

render

public void render(ZRenderContext renderContext)
Paints this object.

The transform, clip, and composite will be set appropriately when this object is rendered. It is up to this object to restore the transform, clip, and composite of the Graphics2D if this node changes any of them. However, the color, font, and stroke are unspecified by Jazz. This object should set those things if they are used, but they do not need to be restored.

Overrides:
render in class ZVisualComponent
Parameters:
renderContext - The graphics context to paint into.

getWidth

public int getWidth()
Return width of image. If the width is not yet available, this will return -1, and the observer will be notified of the dimensions later.
Returns:
width.

getHeight

public int getHeight()
Return height of image. If the height is not yet available, this will return -1, and the observer will be notified of the dimensions later.
Returns:
height.

isLoaded

public boolean isLoaded()
Determines if the image has been loaded yet or not.
Returns:
true if loaded

setLoaded

protected void setLoaded(boolean l)
Called when the image has been loaded.

dump

public java.lang.String dump()
Generate a string that represents this object for debugging.
Overrides:
dump in class ZSceneGraphObject
Returns:
the string that represents this object for debugging
See Also:
ZDebug.dump(edu.umd.cs.jazz.ZNode)

writeObject

public void writeObject(ZObjectOutputStream out)
                 throws java.io.IOException
Write out all of this object's state.
Overrides:
writeObject in class ZVisualComponent
Parameters:
out - The stream that this object writes into

setState

public void setState(java.lang.String fieldType,
                     java.lang.String fieldName,
                     java.lang.Object fieldValue)
Set some state of this object as it gets read back in. After the object is created with its default no-arg constructor, this method will be called on the object once for each bit of state that was written out through calls to ZObjectOutputStream.writeState() within the writeObject method.
Overrides:
setState in class ZVisualComponent
Parameters:
fieldType - The fully qualified type of the field
fieldName - The name of the field
fieldValue - The value of the field

waitForImage

public static boolean waitForImage(java.awt.Image image)
Wait while image is loaded.
Parameters:
image - The image.

makeBufferedImage

public static java.awt.image.BufferedImage makeBufferedImage(java.awt.Image image)
Creates a BufferedImage from an Image.
Parameters:
image - The image.


Copyright © 2001 by University of Maryland, College Park, MD 20742, USA All rights reserved.