Package gov.nih.mipav.view
Class ViewFileTreeNode
- java.lang.Object
-
- javax.swing.tree.DefaultMutableTreeNode
-
- gov.nih.mipav.view.ViewFileTreeNode
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,javax.swing.tree.MutableTreeNode,javax.swing.tree.TreeNode
public class ViewFileTreeNode extends javax.swing.tree.DefaultMutableTreeNodeThis class is used to represent a file system in a tree. This is a node of the file system. It has a java.io.File as its user object.Nodes in the tree are expanded by calling this class's explore method. You can set the explore method to return only directories by setting the directoriesOnly flag. Additionally you can call explore with a file filter, and only nodes that satisfy that file filter will be returned. Directories are verified to contain valid files before they are added to the tree.
Basic structure of class taken from Sun's Graphic Java Swing "Trees" section.
- Author:
- David Parsons, Neva Cherniavsky
- See Also:
ViewImageDirectory,JDialogAnonymizeDirectory, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private booleandirectoriesOnlyDOCUMENT ME!private booleanexploredDOCUMENT ME!private booleanrootfileDOCUMENT ME!private static longserialVersionUIDUse serialVersionUID for interoperability.
-
Constructor Summary
Constructors Constructor Description ViewFileTreeNode(java.io.File node)Loads a File into the tree-leaf.ViewFileTreeNode(java.io.File node, boolean fsRoot)Loads a File into a tree-leaf.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidexplore()Adds the children of this file to the this FileNode for display in a JTree. adjusts theexploredvariable.voidexplore(ViewImageFileFilter filter)Adds the children of this file to the this FileNode for display in a JTree. adjusts theexploredvariable.booleanexploreDirectoriesOnly()Accessor to whether or not the FileNode is to only explore Directories.voidexploreDirectoriesOnly(boolean directoryChildren)Sets the FileNode to view only directories when it goes exploring.java.lang.StringgetAbsolutePath()The absolute path of the FileNode, as taken from its File.booleangetAllowsChildren()Only directoies can allow children.java.lang.StringgetDirectory()The directory of the FileNode, as taken from its File.java.io.FilegetFile()Returns the File that is this node on the tree.java.lang.StringgetName()The name of the FileNode, as taken from its File.private booleanhasValidChildren(ViewImageFileFilter filter)Checks if this directory ought to be added to the list based on whether it has any children that satisfy the filter.booleanisDirectory()Returnstrueif this fileNode is a directory and not a normal file.booleanisExplored()Whether or not this node has been 'explored', and its subdirectories and file-children have been found.booleanisLeaf()Leaves are not directories.java.lang.StringtoString()Gets the name of the File.-
Methods inherited from class javax.swing.tree.DefaultMutableTreeNode
add, breadthFirstEnumeration, children, clone, depthFirstEnumeration, 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
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
Use serialVersionUID for interoperability.- See Also:
- Constant Field Values
-
directoriesOnly
private boolean directoriesOnly
DOCUMENT ME!
-
explored
private boolean explored
DOCUMENT ME!
-
rootfile
private boolean rootfile
DOCUMENT ME!
-
-
Constructor Detail
-
ViewFileTreeNode
public ViewFileTreeNode(java.io.File node)
Loads a File into the tree-leaf.- Parameters:
node- File for tree leaf.
-
ViewFileTreeNode
public ViewFileTreeNode(java.io.File node, boolean fsRoot)Loads a File into a tree-leaf. This method permits telling the node that the file is a root for the filesystem.It can be useful to remember whether or not the given file was a root. (which is not information normally stored by the File.)
- Parameters:
node- File for tree leaf.fsRoot- Flag indicating if this is a root.
-
-
Method Detail
-
explore
public void explore()
Adds the children of this file to the this FileNode for display in a JTree. adjusts theexploredvariable. Does nothing if the FileNode is not a directory or if the node has already been explored. If directories only are to be explored, then the only children to be added will be directories; otherwise, all files in the directory will be added to the node.Implementation of this is different from the Sun Books' code.
-
explore
public void explore(ViewImageFileFilter filter)
Adds the children of this file to the this FileNode for display in a JTree. adjusts theexploredvariable. Does nothing if the FileNode is not a directory or if the node has already been explored. If directories only are to be explored, then the only children to be added will be directories. Otherwise, if the file filter is not null, only the files that satisfy the filter will be added. If the filter is null, all files will be added.Implementation of this is different from the Sun Books' code.
- Parameters:
filter- File filter; can be null.
-
exploreDirectoriesOnly
public boolean exploreDirectoriesOnly()
Accessor to whether or not the FileNode is to only explore Directories.- Returns:
trueif FileNode only explores directories.
-
exploreDirectoriesOnly
public void exploreDirectoriesOnly(boolean directoryChildren)
Sets the FileNode to view only directories when it goes exploring.- Parameters:
directoryChildren- The permission to view only directories.
-
getAbsolutePath
public java.lang.String getAbsolutePath()
The absolute path of the FileNode, as taken from its File.- Returns:
- The File's name.
-
getAllowsChildren
public boolean getAllowsChildren()
Only directoies can allow children.- Specified by:
getAllowsChildrenin interfacejavax.swing.tree.TreeNode- Overrides:
getAllowsChildrenin classjavax.swing.tree.DefaultMutableTreeNode- Returns:
trueif this is a directory.
-
getDirectory
public java.lang.String getDirectory()
The directory of the FileNode, as taken from its File.- Returns:
- The directory's name.
-
getFile
public java.io.File getFile()
Returns the File that is this node on the tree.- Returns:
- the File that is this node on the tree.
-
getName
public java.lang.String getName()
The name of the FileNode, as taken from its File.- Returns:
- The File's name.
-
isDirectory
public boolean isDirectory()
Returnstrueif this fileNode is a directory and not a normal file.- Returns:
trueif this fileNode is a directory.
-
isExplored
public boolean isExplored()
Whether or not this node has been 'explored', and its subdirectories and file-children have been found.- Returns:
- whether or not this FileNode knows that is known.
-
isLeaf
public boolean isLeaf()
Leaves are not directories. Directories can extend.- Specified by:
isLeafin interfacejavax.swing.tree.TreeNode- Overrides:
isLeafin classjavax.swing.tree.DefaultMutableTreeNode- Returns:
trueif not directory.
-
toString
public java.lang.String toString()
Gets the name of the File. When this FileNode is a FileNode for a root of the filesystem, the String returned is the absolute path (that is so on Windows systems,the user sees "C:\"); otherwise, the string returned is the filename.- Overrides:
toStringin classjavax.swing.tree.DefaultMutableTreeNode- Returns:
- Name of the file.
-
hasValidChildren
private boolean hasValidChildren(ViewImageFileFilter filter)
Checks if this directory ought to be added to the list based on whether it has any children that satisfy the filter.- Parameters:
filter- Filter to check files against; if null returns true.- Returns:
- Flag indicating if this directory has valid children.
-
-