Class TreeNode

java.lang.Object
com.codename1.ui.chart.TreeNode

public class TreeNode extends Object

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));
  • Constructor Details

    • TreeNode

      public TreeNode(String label)

      Creates a branch.

      Parameters
      • label: the node name
    • TreeNode

      public TreeNode(String label, double value)

      Creates a leaf.

      Parameters
      • label: the node name

      • value: the leaf value

  • Method Details

    • add

      public TreeNode add(TreeNode child)

      Adds a child.

      Parameters
      • child: 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: 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: the listener
    • removeChangeListener

      public void removeChangeListener(TreeNode.ChangeListener l)

      Removes a listener added by addChangeListener; nothing happens if it was not added.

      Parameters
      • l: 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: 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 " / ".