org.jgraph.graph
Class DefaultGraphCell

java.lang.Object
  extended by javax.swing.tree.DefaultMutableTreeNode
      extended by org.jgraph.graph.DefaultGraphCell
All Implemented Interfaces:
Serializable, Cloneable, MutableTreeNode, TreeNode, GraphCell
Direct Known Subclasses:
DefaultEdge, DefaultPort

public class DefaultGraphCell
extends DefaultMutableTreeNode
implements GraphCell, Cloneable

The default implementation for the GraphCell interface.

Version:
1.0 1/1/02
Author:
Gaudenz Alder
See Also:
Serialized Form

Nested Class Summary
static interface DefaultGraphCell.ValueChangeHandler
           
 
Field Summary
protected  Map attributes
          Hashtable for properties.
static Rectangle defaultBounds
           
 
Fields inherited from class javax.swing.tree.DefaultMutableTreeNode
allowsChildren, children, EMPTY_ENUMERATION, parent, userObject
 
Constructor Summary
DefaultGraphCell()
          Creates an empty cell.
DefaultGraphCell(Object userObject)
          Creates a graph cell and initializes it with the specified user object.
DefaultGraphCell(Object userObject, boolean allowsChildren)
          Creates a graph cell and initializes it with the specified user object.
DefaultGraphCell(Object userObject, MutableTreeNode[] children)
          Constructs a cell that holds a reference to the specified user object and contains the specified array of children and sets default values for the bounds attribute.
 
Method Summary
 Map changeAttributes(Map change)
          Apply change to the cell and sync userObject.
 Object clone()
          Create a clone of the cell.
protected  Object cloneUserObject()
          Create a clone of the user object.
 Map getAttributes()
          Returns the properies of the cell.
 List getChildren()
          Provides access to the children list to change ordering.
 void setAttributes(Map attributes)
          Sets the attributes.
 void setUserObject(Object obj)
          Override parent method to synchronize value property and userObject.
 
Methods inherited from class javax.swing.tree.DefaultMutableTreeNode
add, breadthFirstEnumeration, children, depthFirstEnumeration, getAllowsChildren, getChildAfter, getChildAt, getChildBefore, getChildCount, getDepth, getFirstChild, getFirstLeaf, getIndex, getLastChild, getLastLeaf, getLeafCount, getLevel, getNextLeaf, getNextNode, getNextSibling, getParent, getPath, getPathToRoot, getPreviousLeaf, getPreviousNode, getPreviousSibling, getRoot, getSharedAncestor, getSiblingCount, getUserObject, getUserObjectPath, insert, isLeaf, isNodeAncestor, isNodeChild, isNodeDescendant, isNodeRelated, isNodeSibling, isRoot, pathFromAncestorEnumeration, postorderEnumeration, preorderEnumeration, remove, remove, removeAllChildren, removeFromParent, setAllowsChildren, setParent, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

defaultBounds

public static final Rectangle defaultBounds

attributes

protected Map attributes
Hashtable for properties. Initially empty

Constructor Detail

DefaultGraphCell

public DefaultGraphCell()
Creates an empty cell.


DefaultGraphCell

public DefaultGraphCell(Object userObject)
Creates a graph cell and initializes it with the specified user object.

Parameters:
userObject - an Object provided by the user that constitutes the cell's data

DefaultGraphCell

public DefaultGraphCell(Object userObject,
                        MutableTreeNode[] children)
Constructs a cell that holds a reference to the specified user object and contains the specified array of children and sets default values for the bounds attribute.

Parameters:
userObject - reference to the user object
children - array of children

DefaultGraphCell

public DefaultGraphCell(Object userObject,
                        boolean allowsChildren)
Creates a graph cell and initializes it with the specified user object. The GraphCell allows children only if specified.

Parameters:
userObject - an Object provided by the user that constitutes the cell's data
Method Detail

setUserObject

public void setUserObject(Object obj)
Override parent method to synchronize value property and userObject. The following holds for each GraphCell c:

GraphConstants.getValue(c.getAttributes()) == c.getUserObject()

Note: A cell's userObject can be set using GraphModel.edit() with a propertyMap that carries a value entry for that cell.

Specified by:
setUserObject in interface MutableTreeNode
Overrides:
setUserObject in class DefaultMutableTreeNode

getChildren

public List getChildren()
Provides access to the children list to change ordering. This method returns a Collections.EMPTY_LIST if the list of childrenpoints to null.


getAttributes

public Map getAttributes()
Returns the properies of the cell.

Specified by:
getAttributes in interface GraphCell

changeAttributes

public Map changeAttributes(Map change)
Apply change to the cell and sync userObject.

Specified by:
changeAttributes in interface GraphCell

setAttributes

public void setAttributes(Map attributes)
Sets the attributes.

Specified by:
setAttributes in interface GraphCell
Parameters:
attributes - The attributes to set

clone

public Object clone()
Create a clone of the cell. The cloning of the user object is deferred to the cloneUserObject() method.

Overrides:
clone in class DefaultMutableTreeNode
Returns:
Object a clone of this object.

cloneUserObject

protected Object cloneUserObject()
Create a clone of the user object. This is provided for subclassers who need special cloning. This implementation simply returns a reference to the original user object.

Returns:
Object a clone of this cells user object.