Class DirectoryTreeNode
java.lang.Object
javax.swing.tree.DefaultMutableTreeNode
smile.swing.tree.DirectoryTreeNode
- All Implemented Interfaces:
Serializable, Cloneable, MutableTreeNode, TreeNode
A tree node for file directory.
- See Also:
-
Field Summary
Fields inherited from class DefaultMutableTreeNode
allowsChildren, children, EMPTY_ENUMERATION, parent, userObject -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddChildren(DefaultTreeModel model) Adds the child nodes, skipping hidden files (those whose name starts with '.').booleanisLeaf()Returnstrueif this node is a leaf (i.e.path()Returns the directory path.voidrefresh(DefaultTreeModel model) Refreshes the immediate children of this node to match the current state of the filesystem directory.toString()Methods inherited from class DefaultMutableTreeNode
add, breadthFirstEnumeration, children, clone, depthFirstEnumeration, getAllowsChildren, getChildAfter, getChildAt, getChildBefore, getChildCount, getDepth, getFirstChild, getFirstLeaf, getIndex, getLastChild, getLastLeaf, getLeafCount, getLevel, getNextLeaf, getNextNode, getNextSibling, getParent, getPath, getPathToRoot, getPreviousLeaf, getPreviousNode, getPreviousSibling, getRoot, getSharedAncestor, getSiblingCount, getUserObject, getUserObjectPath, insert, isNodeAncestor, isNodeChild, isNodeDescendant, isNodeRelated, isNodeSibling, isRoot, pathFromAncestorEnumeration, postorderEnumeration, preorderEnumeration, remove, remove, removeAllChildren, removeFromParent, setAllowsChildren, setParent, setUserObject
-
Constructor Details
-
DirectoryTreeNode
-
-
Method Details
-
path
-
toString
- Overrides:
toStringin classDefaultMutableTreeNode
-
isLeaf
public boolean isLeaf()Returnstrueif this node is a leaf (i.e. not a directory).Delegates to
DefaultMutableTreeNode.getAllowsChildren()which was set once fromFiles.isDirectory(Path, LinkOption...)in the constructor, avoiding a filesystem call on every repaint.- Specified by:
isLeafin interfaceTreeNode- Overrides:
isLeafin classDefaultMutableTreeNode
-
addChildren
Adds the child nodes, skipping hidden files (those whose name starts with '.').- Parameters:
model- the tree model to insert child nodes into.
-
refresh
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).
-