Class ViewFileTreeNode

java.lang.Object
javax.swing.tree.DefaultMutableTreeNode
gov.nih.mipav.view.ViewFileTreeNode
All Implemented Interfaces:
Serializable, Cloneable, MutableTreeNode, TreeNode

public class ViewFileTreeNode extends DefaultMutableTreeNode
This 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:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      Use serialVersionUID for interoperability.
      See Also:
    • directoriesOnly

      private boolean directoriesOnly
      DOCUMENT ME!
    • explored

      private boolean explored
      DOCUMENT ME!
    • rootfile

      private boolean rootfile
      DOCUMENT ME!
  • Constructor Details

    • ViewFileTreeNode

      public ViewFileTreeNode(File node)
      Loads a File into the tree-leaf.
      Parameters:
      node - File for tree leaf.
    • ViewFileTreeNode

      public ViewFileTreeNode(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 Details

    • explore

      public void explore()
      Adds the children of this file to the this FileNode for display in a JTree. adjusts the explored variable. 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 the explored variable. 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:
      true if 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 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:
      getAllowsChildren in interface TreeNode
      Overrides:
      getAllowsChildren in class DefaultMutableTreeNode
      Returns:
      true if this is a directory.
    • getDirectory

      public String getDirectory()
      The directory of the FileNode, as taken from its File.
      Returns:
      The directory's name.
    • getFile

      public File getFile()
      Returns the File that is this node on the tree.
      Returns:
      the File that is this node on the tree.
    • getName

      public String getName()
      The name of the FileNode, as taken from its File.
      Returns:
      The File's name.
    • isDirectory

      public boolean isDirectory()
      Returns true if this fileNode is a directory and not a normal file.
      Returns:
      true if 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:
      isLeaf in interface TreeNode
      Overrides:
      isLeaf in class DefaultMutableTreeNode
      Returns:
      true if not directory.
    • toString

      public 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:
      toString in class 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.