Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public class TreeNode

  1. Object
  2. 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.ChangeListenerTold 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

public TreeNode add(TreeNode child)Adds a child.
public String getLabel()The node name.
public double getValue()The leaf value, or the sum of the children’s values for a branch.
public TreeNode setValue(double v)Changes a leaf’s value.
public int getIndexInParent()This node’s position among its parent’s children, or 0 for a node without a parent.
public void addChangeListener(TreeNode.ChangeListener l)Adds a listener told about changes to this node and every node below it.
public void removeChangeListener(TreeNode.ChangeListener l)Removes a listener added by addChangeListener; nothing happens if it was not added.
public Integer getColor()The colour fixed for this node, or null to derive it from the palette.
public TreeNode setColor(int rgb)Fixes this node’s colour; its descendants use shades of it.
public TreeNode getParent()The parent, or null for the root.
public int getChildCount()The number of children.
public TreeNode getChild(int i)Child i.
public int getDepth()The node’s depth below the root, 0 for the root.
public String getPath()The path from the root, names joined with " / “.

Inherited methods

Constructor details

TreeNode

public TreeNode(String label)
Creates a branch.

Parameters

label String
the node name

TreeNode

public TreeNode(String label, double value)
Creates a leaf.

Parameters

label String
the node name
value double
the leaf value

Method details

add

public TreeNode add(TreeNode child)
Adds a child.

Parameters

child TreeNode
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

v double
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

l TreeNode.ChangeListener
the listener

removeChangeListener

public void removeChangeListener(TreeNode.ChangeListener l)
Removes a listener added by addChangeListener; nothing happens if it was not added.

Parameters

l TreeNode.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

rgb int
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 " / “.