Class Tree.Node<N extends Tree.Node,​V,​A extends Actor>

  • Type Parameters:
    N - The type for the node's parent and child nodes.
    V - The type for the node's value.
    A - The type for the node's actor.
    Enclosing class:
    Tree<N extends Tree.Node,​V>

    public abstract static class Tree.Node<N extends Tree.Node,​V,​A extends Actor>
    extends java.lang.Object
    A Tree node which has an actor and value.

    A subclass can be used so the generic type parameters don't need to be specified repeatedly.

    • Constructor Summary

      Constructors 
      Constructor Description
      Node()
      Creates a node without an actor.
      Node​(A actor)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(N node)  
      void addAll​(Array<N> nodes)  
      protected int addToTree​(Tree<N,​V> tree, int actorIndex)
      Called to add the actor to the tree when the node's parent is expanded.
      void clearChildren()
      Removes all children from this node.
      void collapseAll()
      Collapses all nodes under and including this node.
      void expandAll()
      Expands all nodes under and including this node.
      void expandTo()
      Expands all parent nodes of this node.
      void findExpandedValues​(Array<V> values)  
      N findNode​(V value)
      Returns this node or the child node with the specified value, or null.
      A getActor()  
      Array<N> getChildren()
      If the children order is changed, updateChildren() must be called to ensure the node's actors are in the correct order.
      float getHeight()
      Returns the height of the node as calculated for layout.
      Drawable getIcon()  
      int getLevel()  
      N getParent()  
      Tree<N,​V> getTree()
      Returns the tree this node's actor is currently in, or null.
      V getValue()  
      boolean hasChildren()  
      void insert​(int childIndex, N node)  
      boolean isAscendantOf​(N node)
      Returns true if the specified node is this node or an ascendant of this node.
      boolean isDescendantOf​(N node)
      Returns true if the specified node is this node or an descendant of this node.
      boolean isExpanded()  
      boolean isSelectable()  
      void remove()
      Remove this node from its parent.
      void remove​(N node)
      Remove the specified child node from this node.
      protected void removeFromTree​(Tree<N,​V> tree, int actorIndex)
      Called to remove the actor from the tree, eg when the node is removed or the node's parent is collapsed.
      void restoreExpandedValues​(Array<V> values)  
      void setActor​(A newActor)  
      void setExpanded​(boolean expanded)  
      void setIcon​(Drawable icon)
      Sets an icon that will be drawn to the left of the actor.
      void setSelectable​(boolean selectable)  
      void setValue​(V value)
      Sets an application specific value for this node.
      void updateChildren()
      Updates the order of the actors in the tree for this node and all child nodes.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Node

        public Node​(A actor)
      • Node

        public Node()
        Creates a node without an actor. An actor must be set using setActor(Actor) before this node can be used.
    • Method Detail

      • setExpanded

        public void setExpanded​(boolean expanded)
      • addToTree

        protected int addToTree​(Tree<N,​V> tree,
                                int actorIndex)
        Called to add the actor to the tree when the node's parent is expanded.
        Returns:
        The number of node actors added to the tree.
      • removeFromTree

        protected void removeFromTree​(Tree<N,​V> tree,
                                      int actorIndex)
        Called to remove the actor from the tree, eg when the node is removed or the node's parent is collapsed.
      • add

        public void add​(N node)
      • addAll

        public void addAll​(Array<N> nodes)
      • insert

        public void insert​(int childIndex,
                           N node)
      • remove

        public void remove()
        Remove this node from its parent.
      • remove

        public void remove​(N node)
        Remove the specified child node from this node. Does nothing if the node is not a child of this node.
      • clearChildren

        public void clearChildren()
        Removes all children from this node.
      • getTree

        @Null
        public Tree<N,​V> getTree()
        Returns the tree this node's actor is currently in, or null. The actor is only in the tree when all of its parent nodes are expanded.
      • setActor

        public void setActor​(A newActor)
      • getActor

        public A getActor()
      • isExpanded

        public boolean isExpanded()
      • getChildren

        public Array<N> getChildren()
        If the children order is changed, updateChildren() must be called to ensure the node's actors are in the correct order. That is not necessary if this node is not in the tree or is not expanded, because then the child node's actors are not in the tree.
      • hasChildren

        public boolean hasChildren()
      • updateChildren

        public void updateChildren()
        Updates the order of the actors in the tree for this node and all child nodes. This is useful after changing the order of getChildren().
        See Also:
        Tree.updateRootNodes()
      • getParent

        @Null
        public N getParent()
        Returns:
        May be null.
      • setIcon

        public void setIcon​(@Null
                            Drawable icon)
        Sets an icon that will be drawn to the left of the actor.
      • getValue

        @Null
        public V getValue()
      • setValue

        public void setValue​(@Null
                             V value)
        Sets an application specific value for this node.
      • getLevel

        public int getLevel()
      • findNode

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

        public void collapseAll()
        Collapses all nodes under and including this node.
      • expandAll

        public void expandAll()
        Expands all nodes under and including this node.
      • expandTo

        public void expandTo()
        Expands all parent nodes of this node.
      • isSelectable

        public boolean isSelectable()
      • setSelectable

        public void setSelectable​(boolean selectable)
      • findExpandedValues

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

        public void restoreExpandedValues​(Array<V> values)
      • getHeight

        public float getHeight()
        Returns the height of the node as calculated for layout. A subclass may override and increase the returned height to create a blank space in the tree above the node, eg for a separator.
      • isAscendantOf

        public boolean isAscendantOf​(N node)
        Returns true if the specified node is this node or an ascendant of this node.
      • isDescendantOf

        public boolean isDescendantOf​(N node)
        Returns true if the specified node is this node or an descendant of this node.