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.

    • Constructor Detail

      • Tree

        public Tree​(Skin skin)
      • Tree

        public Tree​(Skin skin,
                    java.lang.String styleName)
    • Method Detail

      • 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.
      • drawBackground

        protected void drawBackground​(Batch batch,
                                      float parentAlpha)
        Called to draw the background. Default implementation draws the style background drawable.
      • drawIcons

        protected float drawIcons​(Batch batch,
                                  float r,
                                  float g,
                                  float b,
                                  float a,
                                  @Null
                                  N parent,
                                  Array<N> nodes,
                                  float indent,
                                  float plusMinusWidth)
        Draws selection, icons, and expand icons.
        Parameters:
        parent - null for the root nodes.
        Returns:
        The Y position of the last visible actor for the nodes.
      • drawSelection

        protected void drawSelection​(N node,
                                     Drawable selection,
                                     Batch batch,
                                     float x,
                                     float y,
                                     float width,
                                     float height)
      • drawOver

        protected void drawOver​(N node,
                                Drawable over,
                                Batch batch,
                                float x,
                                float y,
                                float width,
                                float height)
      • drawExpandIcon

        protected void drawExpandIcon​(N node,
                                      Drawable expandIcon,
                                      Batch batch,
                                      float x,
                                      float y)
      • drawIcon

        protected void drawIcon​(N node,
                                Drawable icon,
                                Batch batch,
                                float x,
                                float y)
      • getExpandIcon

        protected Drawable getExpandIcon​(N node,
                                         float iconX)
        Returns the drawable for the expand icon. The default implementation returns Tree.TreeStyle.plusOver or Tree.TreeStyle.minusOver on the desktop if the node is the over node, the mouse is left of iconX, and clicking would expand the node.
        Parameters:
        iconX - The X coordinate of the over node's icon.
      • 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.
      • 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.
      • 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:
        Tree.Node.updateChildren()
      • 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.
      • 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.