Jazz API Documentation

edu.umd.cs.jazz
Class ZVisualComponent

java.lang.Object
  |
  +--edu.umd.cs.jazz.ZSceneGraphObject
        |
        +--edu.umd.cs.jazz.ZVisualComponent
All Implemented Interfaces:
java.io.Serializable, ZSerializable
Direct Known Subclasses:
ZCamera, ZCoordList, ZImage, ZRectangle, ZSwing, ZText

public class ZVisualComponent
extends ZSceneGraphObject
implements ZSerializable, java.io.Serializable

ZVisualComponent is the base class for objects that actually get rendered. A visual component primarily implements three methods: paint(), pick(), and computeBounds(). New sub-classes must override at least paint() and computeBounds(), and will often choose to override pick() as well.

See Also:
Serialized Form

Fields inherited from class edu.umd.cs.jazz.ZSceneGraphObject
bounds, objRefTable, volatileBounds_DEFAULT
 
Constructor Summary
ZVisualComponent()
          Default constructor for visual component.
 
Method Summary
protected  void boundsUpdated()
          Internal method to notify the visual component that its bounds have been updated, and its parents should now update their bounds
 java.lang.Object clone()
          Duplicates the current object by using the copy constructor.
 void duplicateObject(ZVisualComponent refVC)
          Copies all object information from the reference object into the current object.
 ZNode[] getParents()
          Return a copy of the array of parents of this node.
 void paint(java.awt.Graphics2D g2)
          Renders this visual component.
 boolean pick(java.awt.geom.Rectangle2D rect, ZSceneGraphPath path)
          Determines whether the specified rectangle (in local coordinates) should "pick" this visual component.
 boolean pickBounds(java.awt.geom.Rectangle2D rect)
          This is a utility function to determine if the specified rectangle intersects the bounds of this visual component.
 void render(ZRenderContext renderContext)
          Renders this visual component.
 void repaint()
          Repaint causes the portions of the surfaces that this object appears in to be marked as needing painting, and queues events to cause those areas to be painted.
 void repaint(ZBounds repaintBounds)
          This causes just the specified bounds of this visual component to be repainted.
 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 trimToSize()
          Trims the capacity of the array that stores the parents list points to the actual number of points.
protected  void updateBounds()
          Internal method that causes this node and all of its ancestors to recompute their bounds.
protected  void updateVolatility()
          Internal method to compute and cache the volatility of a component, to recursively call the parents to compute volatility.
 void writeObject(ZObjectOutputStream out)
          Write out all of this object's state.
 void writeObjectRecurse(ZObjectOutputStream out)
          Specify which objects this object references in order to write out the scenegraph properly
 
Methods inherited from class edu.umd.cs.jazz.ZSceneGraphObject
computeBounds, dump, duplicateObject, getBounds, getVolatileBounds, reshape, setVolatileBounds, updateObjectReferences
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ZVisualComponent

public ZVisualComponent()
Default constructor for visual component.
Method Detail

duplicateObject

public void duplicateObject(ZVisualComponent refVC)
Copies all object information from the reference object into the current object. This method is called from the clone method. All ZSceneGraphObjects objects contained by the object being duplicated are duplicated, except parents which are set to null. This results in the sub-tree rooted at this object being duplicated.
Parameters:
refVC - The reference visual component to copy

clone

public java.lang.Object clone()
Duplicates the current object by using the copy constructor. The portion of the reference object that is duplicated is that necessary to reuse the object in a new place within the scenegraph, but the new object is not inserted into any scenegraph. The object must be attached to a live scenegraph (a scenegraph that is currently visible) or be registered with a camera directly in order for it to be visible.
Overrides:
clone in class java.lang.Object
Returns:
A copy of this visual component.
See Also:
ZSceneGraphObject.updateObjectReferences(edu.umd.cs.jazz.util.ZObjectReferenceTable)

trimToSize

public void trimToSize()
Trims the capacity of the array that stores the parents list points to the actual number of points. Normally, the parents list arrays can be slightly larger than the number of points in the parents list. An application can use this operation to minimize the storage of a parents list.

updateVolatility

protected void updateVolatility()
Internal method to compute and cache the volatility of a component, to recursively call the parents to compute volatility. All parents of this component are also volatile when this is volatile.
Overrides:
updateVolatility in class ZSceneGraphObject
See Also:
ZSceneGraphObject.setVolatileBounds(boolean), ZSceneGraphObject.getVolatileBounds()

getParents

public ZNode[] getParents()
Return a copy of the array of parents of this node. This method always returns an array, even when there are no children.
Returns:
the parents of this node.

pickBounds

public boolean pickBounds(java.awt.geom.Rectangle2D rect)
This is a utility function to determine if the specified rectangle intersects the bounds of this visual component.
Parameters:
rect - the rectangle that this method tests for intersection with
Returns:
true if this component's local bounds intersects the specified rectangle

pick

public boolean pick(java.awt.geom.Rectangle2D rect,
                    ZSceneGraphPath path)
Determines whether the specified rectangle (in local coordinates) should "pick" this visual component. Picking is typically used to determine if a pointer is over an object, and thus pick should be implemented to retur true if the rectangle intersects the object.

The implementation of this pick method for the base visual component returns true if the rectangle intersects the bounds of the component. If a sub-class wants more detailed picking, then it must extend this class. For example, a circle may only consider itself to be picked if the pointer is within the circle - rather than within the rectangular bounds.

Parameters:
rect - The rectangle that is picking this visual component in local coordinates.
Returns:
true if the rectangle picks this visual component
See Also:
ZDrawingSurface.pick(int, int)

render

public void render(ZRenderContext renderContext)
Renders this visual component. The rendercontext contains various aspects of the rendering state including the Graphics2D and the camera being rendered within.

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.

Note that a subclass can either extend this directly, or can just extend paint if it does not access to the render context.

Parameters:
renderContext - The graphics context to use for rendering.
See Also:
paint(Graphics2D)

paint

public void paint(java.awt.Graphics2D g2)
Renders this visual component.

It is guaranteed that the transform, clip, and composite of the Graphics2D will be set properly for this component. However, the color, font, and stroke are unset, and the visual component must set those things as needed. The visual component is not obligated to restore any aspect of the Graphics2D state.

Note that a subclass can either extend this directly, or can just render if it needs access to the render context for a more complex object.

Parameters:
Graphics2D - The graphics to render with
See Also:
render(ZRenderContext)

repaint

public void repaint()
Description copied from class: ZSceneGraphObject
Repaint causes the portions of the surfaces that this object appears in to be marked as needing painting, and queues events to cause those areas to be painted. The painting does not actually occur until those events are handled. If this object is visible in multiple places because more than one camera can see this object, then all of those places are marked as needing painting.

Scenegraph objects should call repaint when their internal state has changed and they need to be redrawn on the screen.

Important note : Scenegraph objects should call reshape() instead of repaint() if the internal state change effects the bounds of the shape in any way (e.g. changing penwidth, selection, transform, adding points to a line, etc.)

Overrides:
repaint in class ZSceneGraphObject
Tags copied from class: ZSceneGraphObject
See Also:
ZSceneGraphObject.reshape()

repaint

public void repaint(ZBounds repaintBounds)
This causes just the specified bounds of this visual component to be repainted. Note that the input parameter may be modified as a result of this call.
Parameters:
repaintBounds - The bounds to repaint
See Also:
repaint()

updateBounds

protected void updateBounds()
Internal method that causes this node and all of its ancestors to recompute their bounds.
Overrides:
updateBounds in class ZSceneGraphObject

boundsUpdated

protected void boundsUpdated()
Internal method to notify the visual component that its bounds have been updated, and its parents should now update their bounds

writeObject

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

writeObjectRecurse

public void writeObjectRecurse(ZObjectOutputStream out)
                        throws java.io.IOException
Specify which objects this object references in order to write out the scenegraph properly
Specified by:
writeObjectRecurse in interface ZSerializable
Overrides:
writeObjectRecurse in class ZSceneGraphObject
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.
Specified by:
setState in interface ZSerializable
Overrides:
setState in class ZSceneGraphObject
Parameters:
fieldType - The fully qualified type of the field
fieldName - The name of the field
fieldValue - The value of the field

Jazz API Documentation