Class Tree<N extends Tree.Node,V>

Type Parameters:
N - The type of nodes in the tree.
V - The type of values for each node.
All Implemented Interfaces:
Cullable, Layout

public class Tree<N extends Tree.Node,V> extends WidgetGroup
A tree widget where each node has an icon, actor, and child nodes.

The preferred size of the tree is determined by the preferred size of the actors for the expanded nodes.

ChangeListener.ChangeEvent is fired when the selected node changes.

Author:
Nathan Sweet
  • Constructor Details

  • Method Details

    • setStyle

      public void setStyle(Tree.TreeStyle style)
    • add

      public void add(N node)
    • insert

      public void insert(int index, N node)
    • remove

      public void remove(N node)
    • clearChildren

      public void clearChildren(boolean unfocus)
      Removes all tree nodes.
      Overrides:
      clearChildren in class Group
    • invalidate

      public void invalidate()
      Description copied from interface: Layout
      Invalidates this actor's layout, causing Layout.layout() to happen the next time Layout.validate() is called. This method should be called when state changes in the actor that requires a layout but does not change the minimum, preferred, maximum, or actual size of the actor (meaning it does not affect the parent actor's layout).
      Specified by:
      invalidate in interface Layout
      Overrides:
      invalidate in class WidgetGroup
    • layout

      public void layout()
      Description copied from interface: Layout
      Computes and caches any information needed for drawing and, if this actor has children, positions and sizes each child, calls Layout.invalidate() on any each child whose width or height has changed, and calls Layout.validate() on each child. This method should almost never be called directly, instead Layout.validate() should be used.
      Specified by:
      layout in interface Layout
      Overrides:
      layout in class WidgetGroup
    • draw

      public void draw(Batch batch, float parentAlpha)
      Description copied from class: WidgetGroup
      If this method is overridden, the super method or WidgetGroup.validate() should be called to ensure the widget group is laid out.
      Overrides:
      draw in class WidgetGroup
      parentAlpha - The parent alpha, to be multiplied with this actor's alpha, allowing the parent's alpha to affect all children.
    • getNodeAt

      @Null public N getNodeAt(float y)
      Returns:
      May be null.
    • getSelection

      public Selection<N> getSelection()
    • getSelectedNode

      @Null public N getSelectedNode()
      Returns the first selected node, or null.
    • getSelectedValue

      @Null public V getSelectedValue()
      Returns the first selected value, or null.
    • getStyle

      public Tree.TreeStyle getStyle()
    • getRootNodes

      public Array<N> getRootNodes()
      If the order of the root nodes is changed, updateRootNodes() must be called to ensure the nodes' actors are in the correct order.
    • getNodes

      @Deprecated public Array<N> getNodes()
      Deprecated.
    • updateRootNodes

      public void updateRootNodes()
      Updates the order of the actors in the tree for all root nodes and all child nodes. This is useful after changing the order of getRootNodes().
      See Also:
    • getOverNode

      @Null public N getOverNode()
      Returns:
      May be null.
    • getOverValue

      @Null public V getOverValue()
      Returns:
      May be null.
    • setOverNode

      public void setOverNode(@Null N overNode)
      Parameters:
      overNode - May be null.
    • setPadding

      public void setPadding(float padding)
      Sets the amount of horizontal space between the nodes and the left/right edges of the tree.
    • setPadding

      public void setPadding(float left, float right)
      Sets the amount of horizontal space between the nodes and the left/right edges of the tree.
    • setIndentSpacing

      public void setIndentSpacing(float indentSpacing)
    • getIndentSpacing

      public float getIndentSpacing()
      Returns the amount of horizontal space for indentation level.
    • setYSpacing

      public void setYSpacing(float ySpacing)
      Sets the amount of vertical space between nodes.
    • getYSpacing

      public float getYSpacing()
    • setIconSpacing

      public void setIconSpacing(float left, float right)
      Sets the amount of horizontal space left and right of the node's icon. If a node has no icon, the left spacing is used between the plus/minus drawable and the node's actor.
    • getPrefWidth

      public float getPrefWidth()
      Specified by:
      getPrefWidth in interface Layout
      Overrides:
      getPrefWidth in class WidgetGroup
    • getPrefHeight

      public float getPrefHeight()
      Specified by:
      getPrefHeight in interface Layout
      Overrides:
      getPrefHeight in class WidgetGroup
    • findExpandedValues

      public void findExpandedValues(Array<V> values)
    • restoreExpandedValues

      public void restoreExpandedValues(Array<V> values)
    • findNode

      @Null public N findNode(V value)
      Returns the node with the specified value, or null.
    • collapseAll

      public void collapseAll()
    • expandAll

      public void expandAll()
    • getClickListener

      public ClickListener getClickListener()
      Returns the click listener the tree uses for clicking on nodes and the over node.