Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public class TreeNode
- Object
- TreeNode
A node of hierarchical data for treemaps and sunbursts.
A leaf carries a value; a branch’s value is the sum of its children.
TreeNode root = new TreeNode("Portfolio");
TreeNode tech = root.add(new TreeNode("Tech"));
tech.add(new TreeNode("ACME", 120));
tech.add(new TreeNode("Globex", 80));
root.add(new TreeNode("Energy", 60));Nested types
interface TreeNode.ChangeListener | Told about every change to the tree under the node it is set on: setValue and add on that node or any node below it. |
Constructors
public TreeNode(String label) | Creates a branch. |
public TreeNode(String label, double value) | Creates a leaf. |
Methods
Inherited methods
Constructor details
TreeNode
public TreeNode(String label)Creates a branch.
Parameters
labelString- the node name
TreeNode
public TreeNode(String label, double value)Creates a leaf.
Parameters
labelString- the node name
valuedouble- the leaf value
Method details
add
public TreeNode add(TreeNode child)Adds a child.
Parameters
childTreeNode- the child node
Returns
the child, for chaining further adds onto it
getLabel
public String getLabel()The node name.
getValue
public double getValue()The leaf value, or the sum of the children’s values for a branch.
setValue
public TreeNode setValue(double v)Changes a leaf’s value.
Parameters
vdouble- the new value
Returns
this node
getIndexInParent
public int getIndexInParent()This node’s position among its parent’s children, or 0 for a node without a parent.
Returns
the child index
addChangeListener
public void addChangeListener(TreeNode.ChangeListener l)Adds a listener told about changes to this node and every node below it. Any number of
listeners can watch one node: each
HierarchySeries showing a tree adds one to its
root so changes to the tree animate.Parameters
lTreeNode.ChangeListener- the listener
removeChangeListener
public void removeChangeListener(TreeNode.ChangeListener l)Removes a listener added by
addChangeListener; nothing happens if it was not added.Parameters
lTreeNode.ChangeListener- the listener
getColor
public Integer getColor()The colour fixed for this node, or null to derive it from the palette.
setColor
public TreeNode setColor(int rgb)Fixes this node’s colour; its descendants use shades of it.
Parameters
rgbint- the colour
Returns
this node
getParent
public TreeNode getParent()The parent, or null for the root.
getChildCount
public int getChildCount()The number of children.
getChild
public TreeNode getChild(int i)Child
i.getDepth
public int getDepth()The node’s depth below the root, 0 for the root.
getPath
public String getPath()The path from the root, names joined with " / “.