Class TreeNode<T>

java.lang.Object
com.dlsc.gemsfx.treeview.TreeNode<T>
Type Parameters:
T - the type of the value stored in the node

public class TreeNode<T> extends Object
A model node used by TreeNodeView to describe a tree hierarchy.

Each node stores a value, parent-child relationships, optional additional linked nodes, expansion state, and optional dimensions used by the view when laying out cells.

  • Property Summary

    Properties
    Type
    Property
    Description
    final javafx.beans.property.BooleanProperty
    The expanded property.
    final javafx.beans.property.DoubleProperty
    The preferred height property.
    final javafx.beans.property.ReadOnlyObjectProperty<TreeNode<T>>
    The read-only parent property.
    final javafx.beans.property.ObjectProperty<T>
    The value property.
    final javafx.beans.property.DoubleProperty
    The preferred width property.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    Sentinel value indicating that the view's default cell width or height should be used.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an empty tree node.
    TreeNode(T value)
    Creates a tree node with the given value.
  • Method Summary

    Modifier and Type
    Method
    Description
    final javafx.beans.property.BooleanProperty
    The expanded property.
    javafx.collections.ObservableList<TreeNode<T>>
    Returns the observable list of child nodes.
    int
    Get the depth of the node in the tree.
    Returns the first child node.
    final double
    Gets the value of the height property.
    Returns the last child node.
    int
    Returns the level of this node in the tree.
    javafx.collections.ObservableList<TreeNode<T>>
    Returns the observable list of additional nodes linked to this node.
    Returns the optional name used for styling this node and its links.
    final TreeNode<T>
    Gets the value of the parent property.
    final T
    Gets the value of the value property.
    final double
    Gets the value of the width property.
    final javafx.beans.property.DoubleProperty
    The preferred height property.
    boolean
    Checks whether any ancestor of this node is collapsed.
    final boolean
    Gets the value of the expanded property.
    boolean
    Checks whether this node is the first child of its parent.
    boolean
    Checks whether this node is the last child of its parent.
    boolean
    Checks whether this node has no children.
    boolean
    If there is no parent node, it is the root node
    final javafx.beans.property.ReadOnlyObjectProperty<TreeNode<T>>
    The read-only parent property.
    final void
    setExpanded(boolean expanded)
    Sets the value of the expanded property.
    final void
    setHeight(double height)
    Sets the value of the height property.
    void
    Sets the optional name used for styling this node and its links.
    protected final void
    setParent(TreeNode<T> parent)
    Sets the value of the parent property.
    void
    setSize(double width, double height)
    Sets the preferred width and height of this node.
    final void
    setValue(T value)
    Sets the value of the value property.
    final void
    setWidth(double width)
    Sets the value of the width property.
    Creates a breadth-first stream starting with this node.
     
    final javafx.beans.property.ObjectProperty<T>
    The value property.
    final javafx.beans.property.DoubleProperty
    The preferred width property.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Property Details

  • Field Details

    • USE_TREE_CELL_SIZE

      public static final double USE_TREE_CELL_SIZE
      Sentinel value indicating that the view's default cell width or height should be used.
      See Also:
  • Constructor Details

    • TreeNode

      public TreeNode()
      Creates an empty tree node.
    • TreeNode

      public TreeNode(T value)
      Creates a tree node with the given value.
      Parameters:
      value - the value stored in this node
  • Method Details

    • getName

      public String getName()
      Returns the optional name used for styling this node and its links.
      Returns:
      the node name
    • setName

      public void setName(String name)
      Sets the optional name used for styling this node and its links.
      Parameters:
      name - the node name
    • parentProperty

      public final javafx.beans.property.ReadOnlyObjectProperty<TreeNode<T>> parentProperty()
      The read-only parent property.
      Returns:
      the parent property
      See Also:
    • setParent

      protected final void setParent(TreeNode<T> parent)
      Sets the value of the parent property.
      Property description:
      The read-only parent property.
      Parameters:
      parent - the value for the parent property
      See Also:
    • getParent

      public final TreeNode<T> getParent()
      Gets the value of the parent property.
      Property description:
      The read-only parent property.
      Returns:
      the value of the parent property
      See Also:
    • getChildren

      public javafx.collections.ObservableList<TreeNode<T>> getChildren()
      Returns the observable list of child nodes.
      Returns:
      the child nodes
    • getLinkedNodes

      public javafx.collections.ObservableList<TreeNode<T>> getLinkedNodes()
      Returns the observable list of additional nodes linked to this node.
      Returns:
      the linked nodes
    • isExpanded

      public final boolean isExpanded()
      Gets the value of the expanded property.
      Property description:
      The expanded property.
      Returns:
      the value of the expanded property
      See Also:
    • expandedProperty

      public final javafx.beans.property.BooleanProperty expandedProperty()
      The expanded property.
      Returns:
      the expanded property
      See Also:
    • setExpanded

      public final void setExpanded(boolean expanded)
      Sets the value of the expanded property.
      Property description:
      The expanded property.
      Parameters:
      expanded - the value for the expanded property
      See Also:
    • getValue

      public final T getValue()
      Gets the value of the value property.
      Property description:
      The value property.
      Returns:
      the value of the value property
      See Also:
    • valueProperty

      public final javafx.beans.property.ObjectProperty<T> valueProperty()
      The value property.
      Returns:
      the value property
      See Also:
    • setValue

      public final void setValue(T value)
      Sets the value of the value property.
      Property description:
      The value property.
      Parameters:
      value - the value for the value property
      See Also:
    • getWidth

      public final double getWidth()
      Gets the value of the width property.
      Property description:
      The preferred width property.

      A value of USE_TREE_CELL_SIZE lets the view use its default cell width.

      Returns:
      the value of the width property
      See Also:
    • widthProperty

      public final javafx.beans.property.DoubleProperty widthProperty()
      The preferred width property.

      A value of USE_TREE_CELL_SIZE lets the view use its default cell width.

      Returns:
      the width property
      See Also:
    • setWidth

      public final void setWidth(double width)
      Sets the value of the width property.
      Property description:
      The preferred width property.

      A value of USE_TREE_CELL_SIZE lets the view use its default cell width.

      Parameters:
      width - the value for the width property
      See Also:
    • getHeight

      public final double getHeight()
      Gets the value of the height property.
      Property description:
      The preferred height property.

      A value of USE_TREE_CELL_SIZE lets the view use its default cell height.

      Returns:
      the value of the height property
      See Also:
    • heightProperty

      public final javafx.beans.property.DoubleProperty heightProperty()
      The preferred height property.

      A value of USE_TREE_CELL_SIZE lets the view use its default cell height.

      Returns:
      the height property
      See Also:
    • setHeight

      public final void setHeight(double height)
      Sets the value of the height property.
      Property description:
      The preferred height property.

      A value of USE_TREE_CELL_SIZE lets the view use its default cell height.

      Parameters:
      height - the value for the height property
      See Also:
    • setSize

      public void setSize(double width, double height)
      Sets the preferred width and height of this node.
      Parameters:
      width - the preferred node width
      height - the preferred node height
    • isLeaf

      public boolean isLeaf()
      Checks whether this node has no children.
      Returns:
      true if the node is a leaf node
    • getDepth

      public int getDepth()
      Get the depth of the node in the tree. The depth of the root node is 0.
      Returns:
      the depth of the node in the tree
    • getLevel

      public int getLevel()
      Returns the level of this node in the tree.
      Returns:
      the level of this node, equivalent to getDepth()
    • isRoot

      public boolean isRoot()
      If there is no parent node, it is the root node
      Returns:
      true if the node is the root node of the tree
    • getLastChild

      public TreeNode<T> getLastChild()
      Returns the last child node.
      Returns:
      the last node in the child node list, or null if this node has no children
    • isLastChild

      public boolean isLastChild()
      Checks whether this node is the last child of its parent.
      Returns:
      true if this node is the last node of the parent
    • isFirstChild

      public boolean isFirstChild()
      Checks whether this node is the first child of its parent.
      Returns:
      true if this node is the first node of the parent
    • getFirstChild

      public TreeNode<T> getFirstChild()
      Returns the first child node.
      Returns:
      the first node in the child node list, or null if this node has no children
    • isAncestorCollapsed

      public boolean isAncestorCollapsed()
      Checks whether any ancestor of this node is collapsed.
      Returns:
      true if one of this node's ancestors is collapsed
    • stream

      public Stream<TreeNode<T>> stream()
      Creates a breadth-first stream starting with this node.
      Returns:
      a stream traversing this node and its descendants
    • toString

      public String toString()
      Overrides:
      toString in class Object