edu.umd.cs.jazz.component
Class ZStickyDecorator

java.lang.Object
  |
  +--edu.umd.cs.jazz.scenegraph.ZVisualComponent
        |
        +--edu.umd.cs.jazz.scenegraph.ZVisualComponentDecorator
              |
              +--edu.umd.cs.jazz.component.ZConstraintDecorator
                    |
                    +--edu.umd.cs.jazz.component.ZStickyDecorator

public class ZStickyDecorator
extends ZConstraintDecorator

ZStickyDecorator is a decorator that forces the child to always be rendered at the same place and size, independent of the camera view. Thus, as a particular camera that looks at the component changes its magnification, the component changes its transform by the inverse of the camera's transform so it's position is not changed.

A basic way to use this is to create a constraint decorator that wraps a simple visual component. The following code creates a rectangle, decorates it with a constraint, and then creates a node with the decorator chain. The result is that the rectangle will not move as the camera changes its view.

	ZRectangle rect;
	ZNode node;
	ZStickyDecorator sticky;

	rect = new ZRectangle(0, 0, 50, 50);
	sticky = new ZStickyDecorator(camera, rect);
	node = new ZNode(sticky);
	layer.addChild(node);
      surface.restore();
 


Field Summary
protected  boolean inTransformEventListener
           
protected  ZNodeListener nodeListener
           
 
Fields inherited from class edu.umd.cs.jazz.component.ZConstraintDecorator
camera
 
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
ZStickyDecorator()
          Constructs a new sticky decorator.
ZStickyDecorator(ZCamera camera)
          Constructs a new sticky decorator with a specified camera.
ZStickyDecorator(ZCamera camera, ZVisualComponent child)
          Constructs a new sticky decorator with a specified camera that decorates the specified child.
ZStickyDecorator(ZStickyDecorator sticky)
          Constructs a new ZStickyDecorator that is a duplicate of the reference one, i.e., a "copy constructor"
 
Method Summary
 void addNodeTransformListener()
           
 java.lang.Object clone()
          Duplicates the current ZStickyDecorator by using the copy constructor.
protected  java.awt.geom.AffineTransform computeTransform()
          Computes the constraint that defines the child to not move even as the camera view changes.
 void insertAbove(ZVisualComponent c)
          Override method so that we can trap transform changes in the node above this sticky decorator to make sticky objects transform like other nodes.
 void paint(ZRenderContext renderContext)
          Paints the child, but applies the sticky so that it appears in a fixed place independent of the camera.
 void remove()
          We need to stop trapping transform changes in the node above this sticky decorator since it is being removed from a node.
 void setParent(ZScenegraphObject aParent)
          Override method so that we can trap transform changes in the node above this sticky decorator to make sticky objects transform like other nodes.
 
Methods inherited from class edu.umd.cs.jazz.component.ZConstraintDecorator
applyInverseTransform, applyTransform, computeLocalBounds, getCamera, isVolatile, pick, setCamera, setState, writeObject, writeObjectRecurse
 
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

nodeListener

protected ZNodeListener nodeListener

inTransformEventListener

protected boolean inTransformEventListener
Constructor Detail

ZStickyDecorator

public ZStickyDecorator()
Constructs a new sticky decorator.

ZStickyDecorator

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

ZStickyDecorator

public ZStickyDecorator(ZCamera camera,
                        ZVisualComponent child)
Constructs a new sticky 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.

ZStickyDecorator

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

clone

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

insertAbove

public void insertAbove(ZVisualComponent c)
Override method so that we can trap transform changes in the node above this sticky decorator to make sticky objects transform like other nodes.
Overrides:
insertAbove in class ZConstraintDecorator

setParent

public void setParent(ZScenegraphObject aParent)
Override method so that we can trap transform changes in the node above this sticky decorator to make sticky objects transform like other nodes.
Overrides:
setParent in class ZConstraintDecorator

addNodeTransformListener

public void addNodeTransformListener()

remove

public void remove()
We need to stop trapping transform changes in the node above this sticky decorator since it is being removed from a node.
Overrides:
remove in class ZConstraintDecorator

paint

public void paint(ZRenderContext renderContext)
Paints the child, but applies the sticky so that it appears in a fixed place independent of the camera. This method overrides the ZConstraintDecorator paint method in order to implement sticky objects in a special way to avoid the "jitter" that results from rounding errors otherwise.
Parameters:
renderContext - The render context to paint into.
Overrides:
paint in class ZConstraintDecorator

computeTransform

protected java.awt.geom.AffineTransform computeTransform()
Computes the constraint that defines the child to not move even as the camera view changes.
Returns:
the affine transform the defines the constraint.
Overrides:
computeTransform in class ZConstraintDecorator