edu.umd.cs.jazz.component
Class ZConstraintDecorator

java.lang.Object
  |
  +--edu.umd.cs.jazz.scenegraph.ZVisualComponent
        |
        +--edu.umd.cs.jazz.scenegraph.ZVisualComponentDecorator
              |
              +--edu.umd.cs.jazz.component.ZConstraintDecorator
Direct Known Subclasses:
ZStickyDecorator, ZStickyZDecorator

public class ZConstraintDecorator
extends ZVisualComponentDecorator

ZConstraintDecorator is a ZVisualComponent decorator that applies a simple constraint to the child that modifies the transform, effectively controlling where it is in space. The constraint can be dependent on the camera so that the child moves whenever the camera view changes. A subclass must define the constraint that specifies the relationship between the child and the camera.

See Also:
computeTransform()

Field Summary
protected  ZCamera camera
          The camera the child is related to
 
Fields inherited from class edu.umd.cs.jazz.scenegraph.ZVisualComponentDecorator
child
 
Fields inherited from class edu.umd.cs.jazz.scenegraph.ZVisualComponent
cacheVolatile, findable, findable_DEFAULT, isVolatile, localBounds, localBoundsDirty, parent, pickable, pickable_DEFAULT, selected
 
Constructor Summary
ZConstraintDecorator()
          Constructs a new constraint decorator This constructor does not specify a camera to be used in calculating the constraint.
ZConstraintDecorator(ZCamera camera)
          Constructs a new constraint decorator with a specified camera.
ZConstraintDecorator(ZCamera camera, ZVisualComponent child)
          Constructs a new constraint decorator with a specified camera that decorates the specified child.
ZConstraintDecorator(ZConstraintDecorator constraint)
          Constructs a new ZConstraintDecorator that is a duplicate of the reference one, i.e., a "copy constructor"
 
Method Summary
 void applyInverseTransform()
          Applies the inverse of the constraint transform to the associated node of this decorator.
 void applyTransform()
          Applies the constraint transform to the associated node of this decorator.
 java.lang.Object clone()
          Duplicates the current ZConstraintDecorator by using the copy constructor.
protected  void computeLocalBounds()
          Compute the bounds based on the child's bounds - but modified according to the constraint.
protected  java.awt.geom.AffineTransform computeTransform()
          This defines the constraint that specifies where the child gets rendered.
 ZCamera getCamera()
          Get the camera that this component is related to.
 void insertAbove(ZVisualComponent c)
          Overrides the method to insert this decorator into the decorator chain so that the volatility of the component will be updated.
 boolean isVolatile()
          All constrained objects are volatile - their bounds change depending on the particular constraint, and thus must not be cached.
 void paint(ZRenderContext renderContext)
          Paints the child, but applies the constraint so that it appears in the right place.
 boolean pick(java.awt.geom.Rectangle2D rect)
          Returns true if the child is picked.
 void remove()
          Overrides the method to remove this decorator from the decorator chain so that the volatility of the component will be updated.
 void setCamera(ZCamera camera)
          Get the camera that this component is related to
 void setParent(ZScenegraphObject aParent)
          Overrides the method to remove this decorator from the decorator chain so that the volatility of the component will be updated.
 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 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.scenegraph.ZVisualComponentDecorator
getChild, setChild, setVisualComponent, toString
 
Methods inherited from class edu.umd.cs.jazz.scenegraph.ZVisualComponent
damage, damage, findNode, findVisualComponent, getLocalBounds, getParent, isFindable, isPickable, isSelected, pickBounds, select, select, setFindable, setPickable, setSelected, setVolatile, transformChanged, unselect, updateBounds, updateChildBounds, updateLocalBounds, updateVolatility
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

camera

protected ZCamera camera
The camera the child is related to
Constructor Detail

ZConstraintDecorator

public ZConstraintDecorator()
Constructs a new constraint decorator This constructor does not specify a camera to be used in calculating the constraint. Set the camera separately to make the component behave properly.
See Also:
setCamera(edu.umd.cs.jazz.scenegraph.ZCamera)

ZConstraintDecorator

public ZConstraintDecorator(ZCamera camera)
Constructs a new constraint decorator with a specified camera.
Parameters:
camera - The camera the component is related to.

ZConstraintDecorator

public ZConstraintDecorator(ZCamera camera,
                            ZVisualComponent child)
Constructs a new constraint decorator with a specified camera that decorates the specified child.
Parameters:
camera - The camera the component is related to.
child - The child that should go directly below this decorator.

ZConstraintDecorator

public ZConstraintDecorator(ZConstraintDecorator constraint)
Constructs a new ZConstraintDecorator that is a duplicate of the reference one, i.e., a "copy constructor"
Parameters:
constraint - Reference constraint decorator
Method Detail

clone

public java.lang.Object clone()
Duplicates the current ZConstraintDecorator by using the copy constructor. See the copy constructor comments for complete information about what is duplicated.
Overrides:
clone in class ZVisualComponentDecorator
See Also:
ZConstraintDecorator(ZConstraintDecorator)

getCamera

public ZCamera getCamera()
Get the camera that this component is related to.
Returns:
the camera

setCamera

public void setCamera(ZCamera camera)
Get the camera that this component is related to
Parameters:
camera - The new camera

isVolatile

public boolean isVolatile()
All constrained objects are volatile - their bounds change depending on the particular constraint, and thus must not be cached.
Overrides:
isVolatile in class ZVisualComponent

insertAbove

public void insertAbove(ZVisualComponent c)
Overrides the method to insert this decorator into the decorator chain so that the volatility of the component will be updated.
Overrides:
insertAbove in class ZVisualComponentDecorator

remove

public void remove()
Overrides the method to remove this decorator from the decorator chain so that the volatility of the component will be updated.
Overrides:
remove in class ZVisualComponentDecorator

setParent

public void setParent(ZScenegraphObject aParent)
Overrides the method to remove this decorator from the decorator chain so that the volatility of the component will be updated.
Overrides:
setParent in class ZVisualComponent

pick

public boolean pick(java.awt.geom.Rectangle2D rect)
Returns true if the child is picked. Does so by applying the constraint so that the pick rectangle is mapped in the same way that the child is painted.
Parameters:
renderContext - The render context to paint into.
Overrides:
pick in class ZVisualComponentDecorator

paint

public void paint(ZRenderContext renderContext)
Paints the child, but applies the constraint so that it appears in the right place.
Parameters:
renderContext - The render context to paint into.
Overrides:
paint in class ZVisualComponentDecorator

computeLocalBounds

protected void computeLocalBounds()
Compute the bounds based on the child's bounds - but modified according to the constraint.
Overrides:
computeLocalBounds in class ZVisualComponentDecorator

computeTransform

protected java.awt.geom.AffineTransform computeTransform()
This defines the constraint that specifies where the child gets rendered. By default, it returns an identity transform, but a sub-class can override this method to compute the transform based on various kinds of state, such as the current camera view. This transform gets applied to the graphics context before the child gets rendered, and is used to compute the bounds.

When sub-classes define this, they must carefully consider the chain of transforms that may have been applied to the current graphics. The transform that this method returns is concatenated to the current graphics transform. The current graphics transform typically contains a sequence of transforms (camera transform, node 1 transform, node 2 transform, ...).

For example, if the current transform is: [C T1 T2], and you want to create a sticky object by undoing the camera transform, you must concatenate [T2inv T1inv Cinv T1 T2] because concatenating that onto the current transform results in [T1 T2].

Returns:
The transform that specifies the constraint.

applyInverseTransform

public void applyInverseTransform()
Applies the inverse of the constraint transform to the associated node of this decorator. This is designed to be applied when the constraint is added so the object won't move as a result of this decorator being added. This method must be called by the application after the constraint decorator is added.

applyTransform

public void applyTransform()
Applies the constraint transform to the associated node of this decorator. This is designed to be applied when the constraint is removed so the object won't move as a result of this decorator being removed. This method must be called by the application just before the constraint decorator is removed.

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.
Parameters:
fieldType - The fully qualified type of the field
fieldName - The name of the field
fieldValue - The value of the field
Overrides:
setState in class ZVisualComponentDecorator

writeObject

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

writeObjectRecurse

public void writeObjectRecurse(ZObjectOutputStream out)
                        throws java.io.IOException
Specify which objects this object references in order to write out the scenegraph properly
Parameters:
out - The stream that this object writes into
Overrides:
writeObjectRecurse in class ZVisualComponentDecorator