info.bioinfweb.treegraph.document
Class Node

java.lang.Object
  extended by info.bioinfweb.treegraph.document.ConcretePaintableElement
      extended by info.bioinfweb.treegraph.document.TextElement
          extended by info.bioinfweb.treegraph.document.Node
All Implemented Interfaces:
EdgeRadiusElement, HiddenDataElement, LineElement, PaintableElement, java.lang.Cloneable

public class Node
extends TextElement
implements LineElement, EdgeRadiusElement, HiddenDataElement, java.lang.Cloneable

This class represents a node of a tree in the TreeGraph data structure.

Author:
Ben Stöver

Field Summary
private  Branch afferentBranch
           
private  java.util.HashMap<java.lang.String,java.lang.Object> attributeMap
           
private  java.util.ArrayList<Node> children
           
private  NodeFormats formats
           
private  HiddenDataMap hiddenDataMap
           
private  Node parent
           
private  java.lang.String uniqueName
           
 
Fields inherited from class info.bioinfweb.treegraph.document.ConcretePaintableElement
positions
 
Constructor Summary
Node()
           
 
Method Summary
 Node clone()
          Returns a deep copy of this node not including the subtrees.
 Node clone(boolean keepUniqheNames)
          Returns a deep copy of this node not including the subtrees.
 Node cloneWithSubtree(boolean keepUniqueNames)
          Clones this object and all objects in this subtree and its afferent branch.
 boolean containedInSubtree(ConcretePaintableElement element)
          Tests whether an element is contained in the subtree of this node including all of its Nodes, Branches and Labels.
 Branch getAfferentBranch()
           
 java.util.HashMap<java.lang.String,java.lang.Object> getAttributeMap()
          The attribute map can store data that is specific to special tasks like ladderizing or tree merging.
 int getChildIndex(Node child)
           
 java.util.List<Node> getChildren()
           
 NodeFormats getFormats()
           
 HiddenDataMap getHiddenDataMap()
           
 Node getHighestChild()
          Returns the upper most subnode of this node (e.g. needed for legend positioning).
static Node getInstanceWithBranch()
           
 Node getLowestChild()
          Returns the lowest subnode of this node (e.g. needed for legend positioning).
 Node getNext()
           
 Node getParent()
           
 NodePositionData getPosition(PositionPaintType type)
          Returns the stored DataPosition-object of an for an positioner- identifier.
 Node getPrevious()
           
 java.lang.String getUniqueName()
          The unique name is used to identify nodes in the XML-file which are associated with legends.
 boolean hasAfferentBranch()
           
 boolean hasParent()
           
 boolean hasUniqueName()
          Test if this node has a unique name specified
 boolean isFirst()
           
 boolean isLast()
           
 boolean isLeaf()
          Tests if this Node is at the deepest level of the tree (has no subnodes).
 boolean isOnlySubelement()
          Tests if this element is the only Node under the parent node.
 java.util.Vector<java.lang.String> leafNames()
           
private  void searchLeafNames(Node root, java.util.Vector<java.lang.String> names)
           
 void setAfferentBranch(Branch afferentBranch)
          Sets the specified branch as the afferent branch of this node and additionally sets this node as the target node of the specified branch.
 void setFormats(ElementFormats formats)
           
 void setParent(Node node)
           
 void setUniqueName(java.lang.String uniqueName)
          The unique name is used to identify nodes in the XML-file which are associated with legends.
 
Methods inherited from class info.bioinfweb.treegraph.document.TextElement
getData, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

parent

private Node parent

children

private java.util.ArrayList<Node> children

afferentBranch

private Branch afferentBranch

formats

private NodeFormats formats

uniqueName

private java.lang.String uniqueName

hiddenDataMap

private HiddenDataMap hiddenDataMap

attributeMap

private java.util.HashMap<java.lang.String,java.lang.Object> attributeMap
Constructor Detail

Node

public Node()
Method Detail

getInstanceWithBranch

public static Node getInstanceWithBranch()

getPosition

public NodePositionData getPosition(PositionPaintType type)
Description copied from interface: PaintableElement
Returns the stored DataPosition-object of an for an positioner- identifier. If no position-object has been stored for this identifier, one will be created.

Specified by:
getPosition in interface PaintableElement
Overrides:
getPosition in class ConcretePaintableElement
Returns:
the stored position

getParent

public Node getParent()

setParent

public void setParent(Node node)

getChildren

public java.util.List<Node> getChildren()

getChildIndex

public int getChildIndex(Node child)

getAfferentBranch

public Branch getAfferentBranch()

setAfferentBranch

public void setAfferentBranch(Branch afferentBranch)
Sets the specified branch as the afferent branch of this node and additionally sets this node as the target node of the specified branch.

Parameters:
afferentBranch - - the new afferent branch

getAttributeMap

public java.util.HashMap<java.lang.String,java.lang.Object> getAttributeMap()
The attribute map can store data that is specific to special tasks like ladderizing or tree merging. Several special routines can store custom objects under their own key here.

Returns:
the attribute map

isLeaf

public boolean isLeaf()
Tests if this Node is at the deepest level of the tree (has no subnodes).

Returns:
true if there are no subnodes or branches.

hasParent

public boolean hasParent()

hasAfferentBranch

public boolean hasAfferentBranch()

isOnlySubelement

public boolean isOnlySubelement()
Tests if this element is the only Node under the parent node.

Returns:
true, if the given element is the only element in the parent node

isFirst

public boolean isFirst()
Returns:
true, if this element is the fist

isLast

public boolean isLast()
Returns:
true, if this element is the last in its parent node

getPrevious

public Node getPrevious()

getNext

public Node getNext()

containedInSubtree

public boolean containedInSubtree(ConcretePaintableElement element)
Tests whether an element is contained in the subtree of this node including all of its Nodes, Branches and Labels.

Parameters:
element - the element to search for (either a Node, Branch or Label)
Returns:
true, if the element is found

getFormats

public NodeFormats getFormats()
Specified by:
getFormats in interface EdgeRadiusElement
Specified by:
getFormats in interface LineElement
Specified by:
getFormats in interface PaintableElement
Specified by:
getFormats in class TextElement

setFormats

public void setFormats(ElementFormats formats)
Specified by:
setFormats in interface PaintableElement

getUniqueName

public java.lang.String getUniqueName()
The unique name is used to identify nodes in the XML-file which are associated with legends.

Returns:
the unique name or null if none is assigned

setUniqueName

public void setUniqueName(java.lang.String uniqueName)
The unique name is used to identify nodes in the XML-file which are associated with legends.

Parameters:
uniqueName - - the new unique name or null if it shall be deleted

hasUniqueName

public boolean hasUniqueName()
Test if this node has a unique name specified

Returns:
true if a unique name has been specified, false if the unique name is null

getHiddenDataMap

public HiddenDataMap getHiddenDataMap()
Specified by:
getHiddenDataMap in interface HiddenDataElement

getHighestChild

public Node getHighestChild()
Returns the upper most subnode of this node (e.g. needed for legend positioning).

Returns:
the upper most subnode

getLowestChild

public Node getLowestChild()
Returns the lowest subnode of this node (e.g. needed for legend positioning).

Returns:
the lowest subnode

searchLeafNames

private void searchLeafNames(Node root,
                             java.util.Vector<java.lang.String> names)

leafNames

public java.util.Vector<java.lang.String> leafNames()

clone

public Node clone()
Returns a deep copy of this node not including the subtrees. The attribute map and the unique names are not copied. Calling this method is equivalent to clone(false).

Overrides:
clone in class TextElement

clone

public Node clone(boolean keepUniqheNames)
Returns a deep copy of this node not including the subtrees. The attribute map is not copied.

Parameters:
keepUniqheNames - - defines wheather the copy should have the same unique name as the original.
Returns:
the copy

cloneWithSubtree

public Node cloneWithSubtree(boolean keepUniqueNames)
Clones this object and all objects in this subtree and its afferent branch. The parent node will be set to null.

Parameters:
keepUniqueNames - - defines wheather the copied nodes should have the same unique names as the originals.
Returns:
the root of the cloned tree