|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sourceforge.olduvai.treejuxtaposer.drawer.TreeNode
public class TreeNode
A class representing a node of a (phylognenetic) tree. The tree that this node belongs to is of type Tree. Nodes have fields that store a pre- and post-ordering. A TreeNode has a list of children, a unique key, a leftmostleaf and a rightmost leaf
Tree
,
GridCell
Field Summary | |
---|---|
private java.lang.Double |
bcnScore
Score for a node in [0,1] that corresponds to the topological similarity between two tree drawers. |
GridCell |
cell
The GridCell that this node is attached to. |
protected java.util.ArrayList |
children
Array of child nodes that are attached below this internal node. |
protected int |
computedFrame
The last frame that had a computed midYPosition , for caching. |
private int |
fontSize
Height of font in font points used to draw the label. |
protected int |
height
Distance from this node to the root node. |
int |
key
key is unique for nodes in one tree. |
java.lang.String |
label
The text that appears when the node is highlighted or has a name displayed. |
TreeNode |
leftmostLeaf
Leftmost (minimum) leaf node under this internal node (or this node for leaves). |
private double |
midYPosition
Cached location (world-space) of the mid point in the vertical of a cell where the horizontal tree edge is drawn. |
protected java.lang.String |
name
Node name with default "". |
int |
numberLeaves
The number of leaves under this internal node (or 1 for leaves). |
TreeNode |
parent
The parent of this node. |
TreeNode |
posorderNext
The next postorder node. |
TreeNode |
preorderNext
The next preorder node. |
TreeNode |
rightmostLeaf
Rightmost (maximum) leaf node under this internal node (or this node for leaves). |
float |
weight
Weight is the horizontal edge length for the edge immediately above the node. |
Constructor Summary | |
---|---|
TreeNode()
Default tree node constructor. |
Method Summary | |
---|---|
void |
addChild(TreeNode n)
Add a child to the end of the list of children. |
void |
close()
Clean this node of children. |
int |
compareTo(java.lang.Object o)
Implements Comparable interface - sorts on key field. |
void |
drawAscend(int frameNum,
float plane)
Don't draw self, just call this on parents after calling drawDescend ascend drawing until the root is drawn or the node drew in the frame already. |
void |
drawDescend(int frameNum,
float plane,
int min,
int max,
Tree tree)
Descend from this node and draw children down to leaves. |
void |
drawInCell(java.util.ArrayList col,
double plane)
The color and drawing depth determining function that calls down to drawInCell(Color, double) , for edge splitting (horizontal and vertical) |
void |
drawInCell(java.awt.Color col,
double plane)
Draws this node inside cell, the GridCell that it is attached to. |
private void |
drawInCell(java.awt.Color col,
double plane,
boolean horiz)
Main drawing function for tree nodes, draws one edge. |
void |
drawLabelBig(int fontheight,
boolean horiz)
Draw label of this TreeEdge at maximum size (intended for mouseover highlighting). |
private void |
drawLabelBox(LabelBox lb,
int fontheight,
boolean drawBig)
Draw a LabelBox. |
boolean |
equals(TreeNode n)
Tests nodes for equality, based on the name of the node. |
protected void |
finalize()
Destroy this node. |
protected TreeNode |
firstChild()
Get the first child of this node. |
private LabelBox |
fitLabelBox(java.lang.String label,
float[] posStart,
float[] posEnd,
AccordionTreeDrawer atd)
Fitting function for labels given a range of label sizes, first, check smallest font, to see if anything at all can fit. |
java.lang.Double |
getBcnScore()
Get the BCN score for this treenode. |
GridCell |
getCell()
Gets the grid cell that surrounds this node. |
TreeNode |
getChild(int i)
Get a given child for this node, with range checking and casting. |
protected boolean |
getEdge(int xy)
Tests to see if this node has a vertical or horizontal edge component. |
int |
getKey()
Returns the key for this node. |
int |
getLindex()
Assuming this is a leaf, return the leaf index (the split position in Y direction, actually) |
int |
getMax()
Returns the maximum key value of nodes in the subtree rooted but this node. |
SplitLine |
getMaxLine(int xy)
Stub function. |
double |
getMaxY()
Get the vertical endpoint (world-space) for the vertical tree edge for this node. |
double |
getMidY()
Get the position of the vertical world-space position of the horizontal tree edge for this node. |
int |
getMin()
Returns the minimum key value of nodes in the subtree rooted by this node. |
SplitLine |
getMinLine(int xy)
Stub function. |
private double |
getMinY()
Get the vertical starting point (world-space) for the vertical tree edge for this node. |
java.lang.String |
getName()
Returns the label for this node, which is name . |
private double |
getSize(int xy)
Gets the cell world-space size (max - min) for this node's cell in the given direction. |
float |
getWeight()
Get the weight of this treenode, which encodes the length of the horizontal edge. |
private java.util.ArrayList |
intersectLabelBox(LabelBox lb,
java.util.ArrayList checkLabels)
Occlusion check of LabelBox against array of all drawn labels. |
boolean |
isAncestorOf(TreeNode that)
Test function for determining if one node is an ancestor of another. |
boolean |
isLeaf()
Tests to determine if this node is a leaf. |
boolean |
isNodePicked(double x,
double y,
double xFuzz,
double yFuzz)
Test function to determine if this tree node is picked. |
boolean |
isRoot()
Tests to determine if this node is the root of its tree. |
TreeNode |
lastChild()
Get the last child of this node. |
TreeNode |
lca(TreeNode that)
Compute the lowest common ancestor between this node and that. |
TreeNode |
leafLca(TreeNode that)
Compute the lowest common ancestor between this leaf and "that" The two nodes must belong to the same tree and must be leaves |
void |
linkNodesInPostorder()
Leaf->root traversal, starting at leftmost leaf of tree. |
void |
linkNodesInPreorder()
root->leaf traversal, depth first in direction of leftmost leaf. |
protected LabelBox |
makeLabelBox(int fontheight,
int x,
int y,
float[] start,
float[] end,
boolean labelAtLeaves)
Create a LabelBox for the given fontheight and positioning information. |
int |
numberChildren()
Get the number of children under this node. |
TreeNode |
parent()
Get the parent for this node. |
TreeNode |
pickDescend(double x,
double y,
double xFuzz,
double yFuzz)
Non-recursion method used to descend the tree structure, finding the node close enough to the given cursor position. |
void |
print()
Long form printing for a single node. |
private void |
printSubtree()
For debugging, prints the subtree contents, recursive. |
void |
setBcnScore(float n)
Set the bcnScore for this node. |
protected void |
setCell(GridCell c)
Sets the grid cell for this node to the given value. |
void |
setExtremeLeaves()
Set the extreme leaves for this node. |
private java.awt.Color |
setGLColor(AccordionTreeDrawer atd,
java.awt.Color col)
Draws this TreeEdge inside the GridCell to which it is attached, and its label if appropriate. |
void |
setName(java.lang.String s)
Set the name for this node, the name is usually the label drawn with this node. |
int |
setNumberLeaves()
Sets the number of leaves, must be run on leaves first (pre-order) |
protected void |
setPositions(float[] start,
float[] end,
boolean horiz)
Sets positions for a tree edge, starting and ending points for the lines that make a single edge. |
void |
setWeight(double w)
Set the weight of this treenode, which encodes the length of the horizontal edge. |
java.lang.String |
toString()
String value of this node, name + key + tree height information. |
private boolean |
xyInRange(double value,
double fuzz,
int xy)
Test function for cursor proximity to a given world-space position. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected java.util.ArrayList children
public int key
public GridCell cell
private int fontSize
private java.lang.Double bcnScore
TreePairs.getBestCorrNodeScore(Tree, TreeNode, Tree, int)
protected int computedFrame
midYPosition
, for caching.
private double midYPosition
public TreeNode parent
protected java.lang.String name
public java.lang.String label
protected int height
public float weight
public TreeNode leftmostLeaf
public TreeNode rightmostLeaf
public int numberLeaves
public TreeNode preorderNext
public TreeNode posorderNext
Constructor Detail |
---|
public TreeNode()
Method Detail |
---|
public int getMin()
public int getMax()
public int getKey()
getKey
in interface CellGeom
key
for this node.public java.lang.String getName()
name
.
getName
in interface CellGeom
name
for this node.public void drawInCell(java.awt.Color col, double plane)
drawInCell(Color, double, boolean)
,
the edge drawing drawInCell. This function gets input from drawInCell(ArrayList, double)
,
the color and drawing depth function.
drawInCell
in interface CellGeom
col
- The color to draw this node, determined by the calls
from drawInCell(ArrayList, double)
, which is responsible
for picking color and plane.plane
- The plane to draw this node in, determined by drawInCell(ArrayList, double)
.GridCell
,
drawInCell(ArrayList, double)
,
drawInCell(Color, double, boolean)
public void drawInCell(java.util.ArrayList col, double plane)
drawInCell(Color, double)
, for edge splitting (horizontal and vertical)
col
- An array of colors from AccordionDrawer.getColorsForCellGeom(CellGeom)
plane
- The drawing plane for this cellprotected void setCell(GridCell c)
c
- The cell for this node.public GridCell getCell()
getCell
in interface CellGeom
protected boolean getEdge(int xy)
xy
- 0/X for horizontal, 1/Y for vertical nodes.
public int compareTo(java.lang.Object o)
compareTo
in interface java.lang.Comparable
o
- The other object to compare this node to.
public void drawLabelBig(int fontheight, boolean horiz)
fontheight
- Size of text to draw label.horiz
- Label is only drawn if the current edge being drawn is horizontal, this must be true.private void drawInCell(java.awt.Color col, double plane, boolean horiz)
col
- Color to draw edge.plane
- Plane in which to draw edges.horiz
- True for horizontal edges, false for vertical.private LabelBox fitLabelBox(java.lang.String label, float[] posStart, float[] posEnd, AccordionTreeDrawer atd)
label
- String to place in label.posStart
- starting location for label, in world-space.posEnd
- ending location for label, in world-space.atd
- Drawer for this tree node.
public void close()
protected void finalize() throws java.lang.Throwable
close()
.
finalize
in class java.lang.Object
java.lang.Throwable
public void setName(java.lang.String s)
s
- The new value of name
, the name for this node.public int numberChildren()
children
.public TreeNode getChild(int i)
i
- The child index to get.
public boolean isLeaf()
public boolean isRoot()
public boolean equals(TreeNode n)
n
- Second node to test vs. this node.
public void addChild(TreeNode n)
n
- New child node for this node.public TreeNode parent()
parent
.public void setWeight(double w)
w
- New edge weight for this node, weight
.public float getWeight()
weight
.protected TreeNode firstChild()
public TreeNode lastChild()
public boolean isAncestorOf(TreeNode that)
that
- Another TreeNode object
true
if this is an ancestor of that
public TreeNode lca(TreeNode that)
that.
The two nodes must belong to the same tree.
- Parameters:
that
- A TreeNode in the Tree that this TreeNode belongs to
- Returns:
- the lowest common ancestor between this node and "that"
public TreeNode leafLca(TreeNode that)
that
- A TreeNode in the Tree that this TreeNode belongs to
that
, null if one of the nodes is not a leafpublic void print()
printSubtree()
to display a whole subtree.
private void printSubtree()
public void setExtremeLeaves()
public void linkNodesInPreorder()
public void linkNodesInPostorder()
public int setNumberLeaves()
numberLeaves
) including the
current node (leaves = 1)public java.lang.String toString()
toString
in class java.lang.Object
public void setBcnScore(float n)
bcnScore
for this node.
n
- New value of bcnScore
.public java.lang.Double getBcnScore()
bcnScore
for this node.public double getMidY()
private double getMinY()
public double getMaxY()
private double getSize(int xy)
xy
- Direction for getting size.
public boolean isNodePicked(double x, double y, double xFuzz, double yFuzz)
x
- Horizontal cursor world-space position.y
- Vertical cursor world-space position.xFuzz
- World-space maximum horizontal distance for cursor to this node's cell.yFuzz
- World-space maximum vertical distance for cursor to this node's cell.
private boolean xyInRange(double value, double fuzz, int xy)
value
- World-space cursor position to check.fuzz
- World-space maximum distance for cursor to this node's cell.xy
- 0/1 value for X/Y
public TreeNode pickDescend(double x, double y, double xFuzz, double yFuzz)
x
- Cursor horizontal position.y
- Cursor vertical position.xFuzz
- Horizontal threshold for picking.yFuzz
- Vertical threshold for picking.
public int getLindex()
public void drawAscend(int frameNum, float plane)
frameNum
- Current frame number.plane
- Plane to draw nodes in.public void drawDescend(int frameNum, float plane, int min, int max, Tree tree)
frameNum
- Current frame number.plane
- Drawing plane for this node.min
- Index of leaf with minimum node key.max
- Index of leaf with maximum node key.tree
- Tree that this node belongs to.private java.awt.Color setGLColor(AccordionTreeDrawer atd, java.awt.Color col)
atd
- Tree drawer for this node/treecol
- The color to draw this node inGridCell
protected void setPositions(float[] start, float[] end, boolean horiz)
getMidY()
function to compute links to a viable location between
the min and max child.
start
- Set by this function, a starting X/Y position in
world-coordinatesend
- Set by this function, an ending X/Y position in
world-coordinateshoriz
- Passed in parameter, horizontal true for edges that do not
change in Y from start to end, false=vertical, X doesn't
changeprotected LabelBox makeLabelBox(int fontheight, int x, int y, float[] start, float[] end, boolean labelAtLeaves)
fontheight
- Size of the font in pixels.x
- horizontal base location in screen/pixel coordinatesy
- vertical base location in screen/pixel coordinatesstart
- starting position for the tree node (horizontal edge), in world-space coordinatesend
- ending position for the tree ndoe (horizontal edge), in world-space coordinateslabelAtLeaves
- if true, we label at the leaves after the edge of the max stuck line, unlike the internal drawing that starts on the horizontal edgeLabelBox
private java.util.ArrayList intersectLabelBox(LabelBox lb, java.util.ArrayList checkLabels)
AccordionDrawer.getDrawnLabels()
. Returns a list of all
overlapping labels, when the label box intersects with an existing label
box. 2007/02 added check for labeling leaves The list is no longer
sorted. We now pass in an array of placed labels to examine, which may be
all visible labels initally, and a subset as the possible overlaps are
reduced in our font downsizing in
fitLabelBox(String, float[], float[], AccordionTreeDrawer)
Since
the number of labels tends to be small (100 concurrent labels would be
very difficult to read) we can search the list of existing labels with a
linear scan.)
lb
- LabelBox to check for overlapscheckLabels
- Array of labels that we may check against for overlaps.
LabelBox
private void drawLabelBox(LabelBox lb, int fontheight, boolean drawBig)
lb
- LabelBox to use, which includes the string for the label and bounding box information.fontheight
- Size of font to use, in points/pixels.drawBig
- whether to draw maximum size ignoring occlusionspublic SplitLine getMinLine(int xy)
getMinLine
in interface CellGeom
xy
- Direction.
public SplitLine getMaxLine(int xy)
getMaxLine
in interface CellGeom
xy
- Direction.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |