edu.umd.cs.jazz
Class ZTreeLayoutManager

java.lang.Object
  |
  +--edu.umd.cs.jazz.ZTreeLayoutManager
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable, ZLayoutManager, ZSerializable

public class ZTreeLayoutManager
extends java.lang.Object
implements ZLayoutManager, ZSerializable, java.io.Serializable, java.lang.Cloneable

ZTreeLayoutManager implements a generic tree layout manager that can layout hierarchical Jazz objects, ie. a scenegraph. This layout does not give each child subtree in the scenegraph enough room for the bounding box of the entire subtree, rather it tries to minimize the total space used while maintaining no overlap among child subtrees.

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:
Jin Tong
, Ben Bederson , Lance Good
See Also:
Serialized Form

Field Summary
protected  java.util.Hashtable areaManager
          A hashtable to store the areas for nodes using this manager.
protected  int currentHeadStyle
          The Current Heading Style.
protected  int currentLinkStyle
          The Current Link Style.
protected  int currentOrientation
          The Current Orientation.
protected  double currentXSpacing
          The Current X Spacing.
protected  double currentYSpacing
          The Current Y Spacing.
protected static double DEFAULT_SPACING
          The Default Spacing.
static int HEAD_IN
          Heading style that puts current node at the middle of its immediate children
static int HEAD_OUT
          Heading style that puts current node at the middle of all its children
static int HEAD_SIDE
          Heading style that puts current node at one side of all its children (ie.
static int LINK_ANGLEDLINE
          This option connects parent nodes to child nodes with vertical and horizontal lines only
static int LINK_STRAIGHTLINE
          This option connects parent nodes to child nodes with a straight line
protected  boolean linkVisible
          Are links visible?
static int ORIENT_HORIZONTAL
          Horizontal Tree Layout - a left to right layout
static int ORIENT_VERTICAL
          Vertical Tree Layout - a top to bottom layout
protected static java.awt.geom.Point2D ORIGIN
          A Permanent holder for an Origin point.
protected  int recurseLevel
          The current level of recursion in this layout manager.
protected  java.util.ArrayList transformNodes
          A hashtable to store nodes that need transforming in the current set of recursive calls to doLayout.
protected  java.util.Hashtable transformTable
          A hashtable to store the transforms for nodes in the current set of recursive calls to doLayout
 
Constructor Summary
ZTreeLayoutManager()
          The default constructor - uses all default values
ZTreeLayoutManager(int orientation, int headingStyle, boolean showLink, int linkStyle)
          Fully qualified constructor
 
Method Summary
protected  void calculateChildrenLayout(ZGroup aPrimaryGroup)
          Appropriately Lays out the children of the provided node
 java.lang.Object clone()
          Return a clone of this object.
protected  void computeNodeArea(ZNode aPrimaryNode)
          Computes the given nodes area - this includes the bounds of its visual component and the stored areas for its immediate children
protected  java.awt.geom.Point2D computeOverlap(java.awt.geom.Area a, java.awt.geom.Area b)
          Returns the overlap of the two given areas
 void doLayout(ZGroup aLayoutGroup)
          Method from the ZLayoutManager interface Called to layout the layout group
 void doLayout(ZGroup node, int millis)
          Apply this manager's layout algorithm to the specified node's children, and animate the changes over time.
 int getCurrentHeadStyle()
          Get the current heading style
 int getCurrentOrientation()
          Get the current orientation.
 double getCurrentXSpacing()
          Get the current x spacing
 double getCurrentYSpacing()
          Get the current y spacing
protected  ZBounds getFrontVisualComponentBounds(ZNode aVisualNode)
          Convenience method to get the bounds of the front visual component of the given node
 int getLinkStyle()
          Get the value of linkStyle.
protected  java.awt.geom.Area getNodeArea(ZNode aPrimaryNode)
          Gets the stored area for the given node
protected  ZBounds padBounds(ZBounds bounds)
          Convenience method to pad the given bounds with the current spacing
 void postLayout(ZGroup aLayoutGroup)
          Method from the ZLayoutManager interface Called after doLayout
 void preLayout(ZGroup aLayoutGroup)
          Method from the ZLayoutManager interface Called before doLayout
protected  void resetTransformVariables()
          Resets the transformTable and the transformNodes
 boolean setCurrentHeadingStyle(ZLayoutGroup layout, int h)
          Set the current heading style.
 boolean setCurrentOrientation(ZLayoutGroup layout, int orientation)
          Set the current orientation.
 boolean setCurrentXSpacing(double x)
          Set the current vertical spacing.
 boolean setCurrentYSpacing(double y)
          Set the current horizontal spacing.
protected  java.awt.geom.Point2D setDestinationPoint(ZNode aPrimaryNode, java.awt.geom.Point2D dest)
          Sets the bounds location for the given node to the specified point.
 boolean setLinkStyle(ZLayoutGroup layout, int v)
          Set the value of linkStyle.
 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.
protected  void translateDestinationPoint(ZNode aPrimaryNode, java.awt.geom.Point2D trans)
          Translates the transform corresponding to the given node in the transformTable.
protected  java.awt.geom.Area updateChildArea(ZNode aPrimaryNode, java.awt.geom.Point2D trans)
          Translates the child nodes area, potentially stored in the area manager, by the specified translation
protected static void updateInvalidLinks(ZNode top)
          Updates all links, in depth-first order, below the supplied ZNode
protected  void updateTree()
          Actually transforms all nodes that have a stored transform in the transformTable
 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 java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ORIENT_VERTICAL

public static final int ORIENT_VERTICAL
Vertical Tree Layout - a top to bottom layout

See Also:
Constant Field Values

ORIENT_HORIZONTAL

public static final int ORIENT_HORIZONTAL
Horizontal Tree Layout - a left to right layout

See Also:
Constant Field Values

HEAD_IN

public static final int HEAD_IN
Heading style that puts current node at the middle of its immediate children

See Also:
Constant Field Values

HEAD_OUT

public static final int HEAD_OUT
Heading style that puts current node at the middle of all its children

See Also:
Constant Field Values

HEAD_SIDE

public static final int HEAD_SIDE
Heading style that puts current node at one side of all its children (ie. left-most or top-most)

See Also:
Constant Field Values

LINK_STRAIGHTLINE

public static final int LINK_STRAIGHTLINE
This option connects parent nodes to child nodes with a straight line

See Also:
Constant Field Values

LINK_ANGLEDLINE

public static final int LINK_ANGLEDLINE
This option connects parent nodes to child nodes with vertical and horizontal lines only

See Also:
Constant Field Values

DEFAULT_SPACING

protected static double DEFAULT_SPACING
The Default Spacing.


ORIGIN

protected static final java.awt.geom.Point2D ORIGIN
A Permanent holder for an Origin point.


currentHeadStyle

protected int currentHeadStyle
The Current Heading Style.


currentOrientation

protected int currentOrientation
The Current Orientation.


currentXSpacing

protected double currentXSpacing
The Current X Spacing.


currentYSpacing

protected double currentYSpacing
The Current Y Spacing.


currentLinkStyle

protected int currentLinkStyle
The Current Link Style.


linkVisible

protected boolean linkVisible
Are links visible?


areaManager

protected java.util.Hashtable areaManager
A hashtable to store the areas for nodes using this manager.


transformTable

protected java.util.Hashtable transformTable
A hashtable to store the transforms for nodes in the current set of recursive calls to doLayout


transformNodes

protected java.util.ArrayList transformNodes
A hashtable to store nodes that need transforming in the current set of recursive calls to doLayout.


recurseLevel

protected int recurseLevel
The current level of recursion in this layout manager.

Constructor Detail

ZTreeLayoutManager

public ZTreeLayoutManager()
The default constructor - uses all default values


ZTreeLayoutManager

public ZTreeLayoutManager(int orientation,
                          int headingStyle,
                          boolean showLink,
                          int linkStyle)
Fully qualified constructor

Parameters:
orientation - The desired tree layout orientation - ORIENT_VERTICAL or ORIENT_HORIZONTAL
headingStyle - The desired head style - HEAD_IN, HEAD_OUT, or HEAD_SIDE
showLink - Should links be displayed
linkStyle - If links are displayed, the style of links - LINK_STRAIGHTLINE or LINK_ANGLEDLINE
Method Detail

clone

public java.lang.Object clone()
Return a clone of this object.

Specified by:
clone in interface ZLayoutManager
Overrides:
clone in class java.lang.Object

setCurrentOrientation

public boolean setCurrentOrientation(ZLayoutGroup layout,
                                     int orientation)
Set the current orientation. If the orientation is not supported, nothing will happen.

Parameters:
orientation - the desired orientation - ORIENT_VERTICAL or ORIENT_HORIZONTAL
Returns:
true if orientation set, false if orientation not supported.

getCurrentOrientation

public int getCurrentOrientation()
Get the current orientation.

Returns:
the current orientation for this tree.

setCurrentHeadingStyle

public boolean setCurrentHeadingStyle(ZLayoutGroup layout,
                                      int h)
Set the current heading style.

Parameters:
h - the desired heading style - HEAD_IN, HEAD_OUT, or HEAD_SIDE
Returns:
true if set successfuly, false otherwise

getCurrentHeadStyle

public int getCurrentHeadStyle()
Get the current heading style

Returns:
the current heading style

setCurrentXSpacing

public boolean setCurrentXSpacing(double x)
Set the current vertical spacing.

Parameters:
x - the value for x spacing -- horizontal spacing
Returns:
true if set successfuly, false otherwise

setCurrentYSpacing

public boolean setCurrentYSpacing(double y)
Set the current horizontal spacing.

Parameters:
y - the value for y spacing -- horizontal spacing
Returns:
true if set successfuly, false otherwise

getCurrentXSpacing

public double getCurrentXSpacing()
Get the current x spacing

Returns:
current x spacing

getCurrentYSpacing

public double getCurrentYSpacing()
Get the current y spacing

Returns:
current y spacing

getLinkStyle

public int getLinkStyle()
Get the value of linkStyle.

Returns:
Value of linkStyle.

setLinkStyle

public boolean setLinkStyle(ZLayoutGroup layout,
                            int v)
Set the value of linkStyle.

Parameters:
v - Value to assign to linkStyle - LINK_STRAIGHTLINE or LINK_ANGLEDLINE
Returns:
true if set successfuly

preLayout

public void preLayout(ZGroup aLayoutGroup)
Method from the ZLayoutManager interface Called before doLayout

Specified by:
preLayout in interface ZLayoutManager
Parameters:
aLayoutGroup - The layout group currently under consideration

doLayout

public void doLayout(ZGroup node,
                     int millis)
Apply this manager's layout algorithm to the specified node's children, and animate the changes over time.

Specified by:
doLayout in interface ZLayoutManager
Parameters:
node - The node to apply this layout algorithm to.
millis - The number of milliseconds over which to animate layout changes.

doLayout

public void doLayout(ZGroup aLayoutGroup)
Method from the ZLayoutManager interface Called to layout the layout group

Specified by:
doLayout in interface ZLayoutManager
Parameters:
aLayoutGroup - The layout group currently under consideration

postLayout

public void postLayout(ZGroup aLayoutGroup)
Method from the ZLayoutManager interface Called after doLayout

Specified by:
postLayout in interface ZLayoutManager
Parameters:
aLayoutGroup - The layout group currently under consideration

calculateChildrenLayout

protected void calculateChildrenLayout(ZGroup aPrimaryGroup)
Appropriately Lays out the children of the provided node

Parameters:
aPrimaryGroup - The primary group for which the children should be laid out

updateTree

protected void updateTree()
Actually transforms all nodes that have a stored transform in the transformTable


translateDestinationPoint

protected void translateDestinationPoint(ZNode aPrimaryNode,
                                         java.awt.geom.Point2D trans)
Translates the transform corresponding to the given node in the transformTable. This is meant to be a pure translation that will not depend on any scaling in this node's transform - ie. this resulting transform will be preConcatenated with the node's current transform

Parameters:
aPrimaryNode - the primary node to transform
trans - the amount to translate

setDestinationPoint

protected java.awt.geom.Point2D setDestinationPoint(ZNode aPrimaryNode,
                                                    java.awt.geom.Point2D dest)
Sets the bounds location for the given node to the specified point. The resulting translation is meant to be a pure translation that will not depend on any scaling in this node's transform - ie. this resulting will be preConcatenated with the node's current transform

Parameters:
aPrimaryNode - the primary node to transform
Returns:
The translation needed to set the destination point to dest

updateChildArea

protected java.awt.geom.Area updateChildArea(ZNode aPrimaryNode,
                                             java.awt.geom.Point2D trans)
Translates the child nodes area, potentially stored in the area manager, by the specified translation

Parameters:
aPrimaryNode - the primary child node whose area is to be updated
trans - the translation by which the area is to be updated
Returns:
The currently stored area for the given node

computeNodeArea

protected void computeNodeArea(ZNode aPrimaryNode)
Computes the given nodes area - this includes the bounds of its visual component and the stored areas for its immediate children

Parameters:
aPrimaryNode - the node for which the area is computed

getNodeArea

protected java.awt.geom.Area getNodeArea(ZNode aPrimaryNode)
                                  throws java.util.ConcurrentModificationException
Gets the stored area for the given node

Parameters:
aPrimaryNode - The node for which the area is desired
java.util.ConcurrentModificationException

getFrontVisualComponentBounds

protected ZBounds getFrontVisualComponentBounds(ZNode aVisualNode)
Convenience method to get the bounds of the front visual component of the given node

Parameters:
aVisualNode - The node for which the visual component bounds are desired

padBounds

protected ZBounds padBounds(ZBounds bounds)
Convenience method to pad the given bounds with the current spacing

Parameters:
bounds - the bounds to be padded
Returns:
Convenience return of the padded bounds

computeOverlap

protected java.awt.geom.Point2D computeOverlap(java.awt.geom.Area a,
                                               java.awt.geom.Area b)
Returns the overlap of the two given areas

Parameters:
a - one area for which overlap is computed
b - one area for which overlap is computed
Returns:
The current amount to translate to reduce overlap

resetTransformVariables

protected void resetTransformVariables()
Resets the transformTable and the transformNodes


updateInvalidLinks

protected static void updateInvalidLinks(ZNode top)
Updates all links, in depth-first order, below the supplied ZNode

Parameters:
top - The node below which all links should be updated

writeObject

public void writeObject(ZObjectOutputStream out)
                 throws java.io.IOException
Write out all of this object's state.

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

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
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
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.