Class TreeLayoutHelper.TreeNode
- java.lang.Object
-
- org.eclipse.gef.layout.algorithms.TreeLayoutHelper.TreeNode
-
- Enclosing class:
- TreeLayoutHelper
public static class TreeLayoutHelper.TreeNode extends java.lang.ObjectRepresents a node in a tree structure and stores all information related to it. May be subclassed if additional data and behavior is necessary.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<TreeLayoutHelper.TreeNode>childrenThe children of this node.protected intdepthThe depth of the node.protected booleanfirstChildtrueif this node is the first child, otherwisefalse.protected intheightThe height of the node.protected booleanlastChildtrueif this node is the last child, otherwisefalse.protected org.eclipse.gef.graph.NodenodeThe wrappedNode.protected intnumOfDescendantsThe number of descendants.protected intnumOfLeavesThe number of leaves.protected intorderThe order of this node.protected TreeLayoutHelperownerTheTreeLayoutHelperthat controls thisTreeLayoutHelper.TreeNode.protected TreeLayoutHelper.TreeNodeparentThe parent of this node.
-
Constructor Summary
Constructors Modifier Constructor Description protectedTreeNode(org.eclipse.gef.graph.Node node, TreeLayoutHelper owner)Creates a tree node related to given layout node
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddChild(TreeLayoutHelper.TreeNode child)Adds given node to the list of this node's children and set its parent to this node.protected voidfindNewParent()Finds a node that is the best parent for this node.java.util.List<TreeLayoutHelper.TreeNode>getChildren()intgetDepth()intgetHeight()org.eclipse.gef.graph.NodegetNode()intgetNumOfDescendants()intgetNumOfLeaves()intgetOrder()Returns order in which nodes are visited during Deep First Search.TreeLayoutHelpergetOwner()TreeLayoutHelper.TreeNodegetParent()booleanisAncestorOf(TreeLayoutHelper.TreeNode descendant)protected booleanisBetterParent(TreeLayoutHelper.TreeNode potentialParent)Checks if a potential parent would be better for this node than its current parent.booleanisFirstChild()booleanisLastChild()protected voidprecomputeTree()Performs a DFS on the tree structure and calculates all parameters of its nodes.
-
-
-
Field Detail
-
node
protected final org.eclipse.gef.graph.Node node
The wrappedNode.
-
owner
protected final TreeLayoutHelper owner
TheTreeLayoutHelperthat controls thisTreeLayoutHelper.TreeNode.
-
height
protected int height
The height of the node.
-
depth
protected int depth
The depth of the node.
-
numOfLeaves
protected int numOfLeaves
The number of leaves.
-
numOfDescendants
protected int numOfDescendants
The number of descendants.
-
order
protected int order
The order of this node.
-
children
protected final java.util.List<TreeLayoutHelper.TreeNode> children
The children of this node.
-
parent
protected TreeLayoutHelper.TreeNode parent
The parent of this node.
-
firstChild
protected boolean firstChild
trueif this node is the first child, otherwisefalse.
-
lastChild
protected boolean lastChild
trueif this node is the last child, otherwisefalse.
-
-
Constructor Detail
-
TreeNode
protected TreeNode(org.eclipse.gef.graph.Node node, TreeLayoutHelper owner)Creates a tree node related to given layout node- Parameters:
node- the layout nodeowner-TreeLayoutObserverowning created node
-
-
Method Detail
-
getNode
public org.eclipse.gef.graph.Node getNode()
- Returns:
- node layout related to this tree node (null for
Super Root)
-
getOwner
public TreeLayoutHelper getOwner()
- Returns:
TreeLayoutObserverowning this tree node
-
getHeight
public int getHeight()
- Returns:
- height of this node in the tree (the longest distance to a leaf, 0 for a leaf itself)
-
getDepth
public int getDepth()
- Returns:
- depth of this node in the tree (distance from root, 0 for a
root and -1 for
Super Root
-
getNumOfLeaves
public int getNumOfLeaves()
- Returns:
- number of all leaves descending from this node (1 for a leaf itself)
-
getNumOfDescendants
public int getNumOfDescendants()
- Returns:
- total number of descendants of this node (0 for leafs)
-
getOrder
public int getOrder()
Returns order in which nodes are visited during Deep First Search. Children are visited in the same order as they were added to their layout context, unlessTreeLayoutHelper.computeTree(Node[])was called after the nodes were added. In that case the order is determined by order of nodes returned byNode.getAllSuccessorNodes(). Leaves are assigned successive numbers starting from 0, other nodes have order equal to the smallest order of their children.- Returns:
- order of this node
-
getChildren
public java.util.List<TreeLayoutHelper.TreeNode> getChildren()
- Returns:
- an unmodifiable list of this node's children
-
getParent
public TreeLayoutHelper.TreeNode getParent()
- Returns:
- this node's parent
-
isFirstChild
public boolean isFirstChild()
- Returns:
- true if this node is the first child of its parent (has the smallest order)
-
isLastChild
public boolean isLastChild()
- Returns:
- true if this node is the last child of its parent (has the highest order)
-
addChild
protected void addChild(TreeLayoutHelper.TreeNode child)
Adds given node to the list of this node's children and set its parent to this node.- Parameters:
child- node to add
-
precomputeTree
protected void precomputeTree()
Performs a DFS on the tree structure and calculates all parameters of its nodes. Should be called onSuper Root. Uses recurrence to go through all the nodes.
-
findNewParent
protected void findNewParent()
Finds a node that is the best parent for this node. Add this node as a child of the found node.
-
isBetterParent
protected boolean isBetterParent(TreeLayoutHelper.TreeNode potentialParent)
Checks if a potential parent would be better for this node than its current parent. A better parent has smaller depth (with exception toSuper Root, which has depth equal to -1 but is never a better parent than any other node).- Parameters:
potentialParent- potential parent to check- Returns:
- true if potentialParent can be a parent of this node and is better than its current parent
-
isAncestorOf
public boolean isAncestorOf(TreeLayoutHelper.TreeNode descendant)
- Parameters:
descendant- TheTreeLayoutHelper.TreeNodein question.- Returns:
- true if this node is an ancestor if given descendant node
-
-