edu.umd.cs.jazz
Class ZStickyGroup

java.lang.Object
  |
  +--edu.umd.cs.jazz.ZSceneGraphObject
        |
        +--edu.umd.cs.jazz.ZNode
              |
              +--edu.umd.cs.jazz.ZGroup
                    |
                    +--edu.umd.cs.jazz.ZTransformGroup
                          |
                          +--edu.umd.cs.jazz.ZConstraintGroup
                                |
                                +--edu.umd.cs.jazz.ZStickyGroup
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable, ZSerializable, ZTransformable

public class ZStickyGroup
extends ZConstraintGroup
implements java.io.Serializable

ZStickyGroup is a constraint group that moves its children inversely to the camera view, so that the children stay visually on the same place on the screen, even as the camera view changes. There are two types of sticky constraints:

The simplest way to make an object sticky is to use the static makeSticky() method. Alternatively, an application can make one manually by creating a constraint group over a sub-tree that should be sticky. The following code creates a sticky rectangle using this node.

     ZRectangle rect;
     ZVisualLeaf leaf;
     ZStickyGroup sticky;

     rect = new ZRectangle(0, 0, 50, 50);
     leaf = new ZVisualLeaf(rect);
     sticky = new ZStickyGroup(camera, leaf);
     layer.addChild(sticky);
 

ZSceneGraphEditor provides a convenience mechanism to locate, create and manage nodes of this type.

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
static int constraintType_DEFAULT
           
static int STICKY
          The type for a Sticky constraint
static double stickyPointX_DEFAULT
           
static double stickyPointY_DEFAULT
           
static int STICKYZ
          The type for a Sticky Z constraint
 
Fields inherited from class edu.umd.cs.jazz.ZConstraintGroup
camera
 
Fields inherited from class edu.umd.cs.jazz.ZTransformGroup
ANIMATE_METHODS_USE_ANIMATION_FRAMEWORK
 
Fields inherited from class edu.umd.cs.jazz.ZGroup
children, childrenFindable_DEFAULT, childrenPickable_DEFAULT, childrenVolatileBoundsCache, hasOneChild_DEFAULT
 
Fields inherited from class edu.umd.cs.jazz.ZNode
editorFactory, findable_DEFAULT, parent, pickable_DEFAULT, savable_DEFAULT, selectable_DEFAULT
 
Fields inherited from class edu.umd.cs.jazz.ZSceneGraphObject
bounds, inTransaction, invalidBounds, invalidVolatileBounds, listenerList, volatileBounds, volatileBounds_DEFAULT
 
Constructor Summary
ZStickyGroup()
          Constructs a new sticky group.
ZStickyGroup(ZCamera camera)
          Constructs a new sticky group with a specified camera.
ZStickyGroup(ZCamera camera, ZNode child)
          Constructs a new sticky group with a specified camera that decorates the specified child.
ZStickyGroup(ZNode child)
          Constructs a new sticky group that decorates the specified child.
 
Method Summary
 java.awt.geom.AffineTransform computeStickyTransform()
          Computes the Sticky constraint that defines the child to not move even as the camera view changes.
protected  java.awt.geom.AffineTransform computeStickyZTransform()
          Computes the Sticky Z constraint that defines the child to keep a constant magnification even as the camera magnification changes.
 java.awt.geom.AffineTransform computeTransform()
          Computes the constraint that defines the child to not move even as the camera view changes.
 java.lang.String dump()
          Generate a string that represents this object for debugging.
 int getConstraintType()
          Determine the type of constraint that this node implements.
 java.awt.Dimension getStickyPoint()
          Returns a Dimension specifying a point on the sticky object that remains fixed as the scene is zoomed (for StickyZ only).
static ZStickyGroup makeSticky(ZNode node, ZCamera camera, int constraintType)
          Make the specified node sticky by adding a sticky node above the specified node.
static void makeUnSticky(ZNode node)
          Make the specified node unsticky.
 void setConstraintType(int constraintType)
          Set the type of constraint that this node implements.
 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 setStickyPoint(double x, double y)
          Specifies a point on the unit square of the sticky object that will remain fixed when the scene is zoomed (for StickyZ only).
 void writeObject(ZObjectOutputStream out)
          Write out all of this object's state.
 
Methods inherited from class edu.umd.cs.jazz.ZConstraintGroup
finalize, getCamera, init, setCamera, updateObjectReferences, updateTransform, writeObjectRecurse
 
Methods inherited from class edu.umd.cs.jazz.ZTransformGroup
addTransformListener, animate, animate, animate, animate, computeBounds, computeInverseTransform, computeScale, concatenate, duplicateObject, getInverseTransform, getLocalToGlobalTransform, getMatrix, getRotation, getScale, getTransform, getTransformReference, getTranslateX, getTranslateY, getTranslation, lerp, pick, position, position, preConcatenate, removeTransformListener, render, repaint, reshape, rotate, rotate, rotate, rotate, scale, scale, scale, scale, setRotation, setRotation, setRotation, setRotation, setScale, setScale, setScale, setScale, setTransform, setTransform, setTransformReference, setTranslateX, setTranslateY, setTranslation, setTranslation, transform, transform, translate, translate
 
Methods inherited from class edu.umd.cs.jazz.ZGroup
addChild, addChildImpl, addChildren, addChildren, addGroupListener, childAddedNotification, childRemovedNotification, computeVolatileBounds, extract, findNodes, getChild, getChildren, getChildrenFindable, getChildrenIterator, getChildrenPickable, getChildrenReference, getNumChildren, getShallowBounds, getVolatileBounds, hasOneChild, indexOf, insertAbove, iterator, lower, lowerTo, markInTransaction, markNotInTransaction, raise, raiseTo, removeAllChildren, removeAllChildren, removeChild, removeChild, removeChild, removeChildImpl, removeGroupListener, removeNodeListener, setChildrenFindable, setChildrenPickable, setHasOneChild, trimToSize, updateHasNodeListener
 
Methods inherited from class edu.umd.cs.jazz.ZNode
addNodeListener, editor, getGlobalBounds, getGlobalToLocalTransform, getParent, getRoot, globalToLocal, globalToLocal, globalToLocal, hasNodeListener, isAncestorOf, isDescendentOf, isFindable, isPickable, isSavable, isSelectable, localToGlobal, localToGlobal, localToGlobal, lower, lowerTo, percolateEventUpSceneGraph, raise, raiseTo, remove, repaint, reparent, replaceWith, setEditorFactory, setFindable, setParent, setPickable, setSavable, setSelectable, setVolatileBounds, updateBounds, updateVolatility, writeReplace
 
Methods inherited from class edu.umd.cs.jazz.ZSceneGraphObject
addClientProperty, addMouseListener, addMouseMotionListener, clone, endTransaction, fireEvent, fireMouseEvent, getBounds, getBoundsReference, getClientProperty, getHandles, getListenerList, hasLisenerOfType, hasListenerOfType, hasMouseListener, processMouseEvent, putClientProperty, removeEventListener, removeMouseListener, removeMouseMotionListener, setBounds, startTransaction
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STICKY

public static final int STICKY
The type for a Sticky constraint

See Also:
Constant Field Values

STICKYZ

public static final int STICKYZ
The type for a Sticky Z constraint

See Also:
Constant Field Values

stickyPointX_DEFAULT

public static double stickyPointX_DEFAULT

stickyPointY_DEFAULT

public static double stickyPointY_DEFAULT

constraintType_DEFAULT

public static int constraintType_DEFAULT
Constructor Detail

ZStickyGroup

public ZStickyGroup()
Constructs a new sticky group.


ZStickyGroup

public ZStickyGroup(ZCamera camera)
Constructs a new sticky group with a specified camera.

Parameters:
camera - The camera the node is related to.

ZStickyGroup

public ZStickyGroup(ZNode child)
Constructs a new sticky group that decorates the specified child.

Parameters:
child - The child that should go directly below this node.

ZStickyGroup

public ZStickyGroup(ZCamera camera,
                    ZNode child)
Constructs a new sticky group with a specified camera that decorates the specified child.

Parameters:
camera - The camera the node is related to.
child - The child that should go directly below this node.
Method Detail

makeSticky

public static ZStickyGroup makeSticky(ZNode node,
                                      ZCamera camera,
                                      int constraintType)
Make the specified node sticky by adding a sticky node above the specified node. It also inserts a transform node between the primary node and the sticky node, since a sticky node's transform needs to be under the sticky node. If the node is already sticky, then do nothing. This manages the sticky node as a decorator as described in ZGroup.setHasOneChild(boolean).

If the node has a transform decorator, then the sticky node is added above the transform node.

Parameters:
node - The node to make sticky
camera - The camera that the node is sticky relative to
constraintType - The constraint type for this node (STICKY or STICKYZ).
Returns:
The ZStickyGroup that represents the sticky constraint

makeUnSticky

public static void makeUnSticky(ZNode node)
Make the specified node unsticky. If the node is not already sticky, then do nothing. This manages the sticky node as a decorator as described in ZNode.

Parameters:
node - The node to make unsticky

setStickyPoint

public void setStickyPoint(double x,
                           double y)
Specifies a point on the unit square of the sticky object that will remain fixed when the scene is zoomed (for StickyZ only). The coordinates range from upper left hand corner (0,0) of the sticky object, to bottom right hand corner (1,1).

Parameters:
x - X coordinate of the sticky point of the sticky object.
y - Y coordinate of the sticky point of the sticky object.

getStickyPoint

public java.awt.Dimension getStickyPoint()
Returns a Dimension specifying a point on the sticky object that remains fixed as the scene is zoomed (for StickyZ only).

Returns:
the coordinates of the fixed point of the sticky object.

setConstraintType

public void setConstraintType(int constraintType)
Set the type of constraint that this node implements. Must be STICKY or STICKYZ.

Parameters:
constraintType - The constraint type for this node.

getConstraintType

public int getConstraintType()
Determine the type of constraint that this node implements.

Returns:
They constraint type.

computeTransform

public java.awt.geom.AffineTransform computeTransform()
Computes the constraint that defines the child to not move even as the camera view changes. This is called whenever the camera view changes. This should be overrided by sub-classes defining constraints.

Overrides:
computeTransform in class ZConstraintGroup
Returns:
The new transform

computeStickyTransform

public java.awt.geom.AffineTransform computeStickyTransform()
Computes the Sticky constraint that defines the child to not move even as the camera view changes. This is called whenever the camera view changes. This should be overrided by sub-classes defining constraints.

Returns:
The new transform

computeStickyZTransform

protected java.awt.geom.AffineTransform computeStickyZTransform()
Computes the Sticky Z constraint that defines the child to keep a constant magnification even as the camera magnification changes.

Returns:
the affine transform the defines the constraint.

dump

public java.lang.String dump()
Generate a string that represents this object for debugging.

Overrides:
dump in class ZTransformGroup
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.

Specified by:
writeObject in interface ZSerializable
Overrides:
writeObject in class ZConstraintGroup
Parameters:
out - The stream that this object writes into
java.io.IOException

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 ZConstraintGroup
Parameters:
fieldType - The fully qualified type of the field
fieldName - The name of the field
fieldValue - The value of the field


Copyright � 2003 by University of Maryland, College Park, MD 20742, USA All rights reserved.