Class DirectoryTreeNode

java.lang.Object
javax.swing.tree.DefaultMutableTreeNode
smile.swing.tree.DirectoryTreeNode
All Implemented Interfaces:
Serializable, Cloneable, MutableTreeNode, TreeNode

public class DirectoryTreeNode extends DefaultMutableTreeNode
A tree node for file directory.
See Also:
  • Constructor Details

    • DirectoryTreeNode

      public DirectoryTreeNode(Path path)
      Constructor.
      Parameters:
      path - the directory path.
  • Method Details

    • path

      public Path path()
      Returns the directory path.
      Returns:
      the directory path.
    • toString

      public String toString()
      Overrides:
      toString in class DefaultMutableTreeNode
    • isLeaf

      public boolean isLeaf()
      Returns true if this node is a leaf (i.e. not a directory).

      Delegates to DefaultMutableTreeNode.getAllowsChildren() which was set once from Files.isDirectory(Path, LinkOption...) in the constructor, avoiding a filesystem call on every repaint.

      Specified by:
      isLeaf in interface TreeNode
      Overrides:
      isLeaf in class DefaultMutableTreeNode
    • addChildren

      public void addChildren(DefaultTreeModel model)
      Adds the child nodes, skipping hidden files (those whose name starts with '.').
      Parameters:
      model - the tree model to insert child nodes into.
    • refresh

      public void refresh(DefaultTreeModel model)
      Refreshes the immediate children of this node to match the current state of the filesystem directory.

      This method:

      • Removes child nodes whose paths no longer exist on disk.
      • Inserts new child nodes for paths that appeared on disk since the last refresh, maintaining the directories-first alphabetical order.
      • Does not touch already-expanded grandchildren, so open subtrees are preserved across a refresh cycle.

      Must be called on the Swing Event Dispatch Thread.

      Parameters:
      model - the tree model (used to fire the appropriate structural events).