ti.chimera.fs
Class FileSystemTreeModel

java.lang.Object
  extended byti.swing.treetable.AbstractTreeModel
      extended byti.chimera.fs.FileSystemTreeModel
All Implemented Interfaces:
javax.swing.tree.TreeModel
Direct Known Subclasses:
FileSystemTreeTableModel

public class FileSystemTreeModel
extends AbstractTreeModel

Class that makes a TreeModel of the file system AbstractFileSystem. There are some additional "add-ons" that you should use to ensure proper behavior of your tree. (XXX I should probably just add a factory method to install the TreeCellRenderer and TreeExpansionListener, and any other steps that may get added in the future....)

   JTree tree = new JTree( new FileSystemTreeModel( "/", null ) )
   tree.setCellRenderer( new FileSystemTreeModel.FileSystemTreeCellRenderer() );
   tree.addTreeExpansionListener( new FileSystemTreeModel.FileSystemTreeExpansionListener() );
 

Version:
0.1
Author:
Rob Clark

Nested Class Summary
static class FileSystemTreeModel.FileSystemNode
          Because the AbstractFileSystem.children() can be expensive, we cache the results in the FileSystemNode.
static class FileSystemTreeModel.FileSystemTreeCellRenderer
          A TreeCellRenderer that uses the icons set with #setFileIcon.
static class FileSystemTreeModel.FileSystemTreeExpansionListener
          A TreeExpansionListener which helps the TreeModel track what files are visible, so that the model can make intelligent choices about what files to watch (poll) for changes.
static interface FileSystemTreeModel.FileSystemTreeFilter
          Filter which controls what files are visible in the model.
 
Field Summary
 
Fields inherited from class ti.swing.treetable.AbstractTreeModel
listenerList, root
 
Constructor Summary
FileSystemTreeModel(oscript.fs.AbstractFile root, FileSystemTreeModel.FileSystemTreeFilter filter)
          Class Constructor.
FileSystemTreeModel(java.lang.String path, FileSystemTreeModel.FileSystemTreeFilter filter)
          Class Constructor.
 
Method Summary
 java.lang.Object getChild(java.lang.Object parent, int idx)
           
 int getChildCount(java.lang.Object parent)
           
static javax.swing.Icon getFileIcon(java.lang.String extension)
          Get the icon associated with the specified file type.
static java.lang.String getFileInfo(java.lang.String extension)
           
 FileSystemTreeModel.FileSystemNode getFileSystemNode(oscript.fs.AbstractFile file)
          Cached lookup of FileSystemNode
 FileSystemTreeModel.FileSystemNode getFileSystemNode(java.lang.String path)
          Cached lookup of FileSystemNode
 javax.swing.tree.TreePath getTreePath(oscript.fs.AbstractFile file)
          Utility to go from AbstractFile to TreePath
 boolean isLeaf(java.lang.Object node)
          Is the particular node a leaf node?
protected static oscript.fs.AbstractFile pathToFile(java.lang.String path)
          utility to go from path to file...
static void setFileInfo(java.lang.String extension, javax.swing.Icon icon, java.lang.String info)
          Set the icon to draw, and the description of the type, for files of the specified type (as determined by file extension).
 
Methods inherited from class ti.swing.treetable.AbstractTreeModel
addTreeModelListener, fireTreeNodesChanged, fireTreeNodesInserted, fireTreeNodesRemoved, fireTreeStructureChanged, getIndexOfChild, getRoot, removeTreeModelListener, valueForPathChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileSystemTreeModel

public FileSystemTreeModel(java.lang.String path,
                           FileSystemTreeModel.FileSystemTreeFilter filter)
Class Constructor.

Parameters:
path - the path to the root node of the tree
filter - the filter, or null

FileSystemTreeModel

public FileSystemTreeModel(oscript.fs.AbstractFile root,
                           FileSystemTreeModel.FileSystemTreeFilter filter)
Class Constructor.

Parameters:
root - the root node of the tree
filter - the filter, or null
Method Detail

isLeaf

public boolean isLeaf(java.lang.Object node)
Description copied from class: AbstractTreeModel
Is the particular node a leaf node?

Specified by:
isLeaf in interface javax.swing.tree.TreeModel
Overrides:
isLeaf in class AbstractTreeModel

getChild

public java.lang.Object getChild(java.lang.Object parent,
                                 int idx)

getChildCount

public int getChildCount(java.lang.Object parent)

getFileSystemNode

public FileSystemTreeModel.FileSystemNode getFileSystemNode(java.lang.String path)
Cached lookup of FileSystemNode


getFileSystemNode

public FileSystemTreeModel.FileSystemNode getFileSystemNode(oscript.fs.AbstractFile file)
Cached lookup of FileSystemNode


setFileInfo

public static void setFileInfo(java.lang.String extension,
                               javax.swing.Icon icon,
                               java.lang.String info)
Set the icon to draw, and the description of the type, for files of the specified type (as determined by file extension). If an icon or description has already been registered for this file type, the new icon will replace the existing one.

Parameters:
extension - the file type extension
icon - the icon to display for this file type, or null
info - an info string describing the file type, or null

getFileIcon

public static javax.swing.Icon getFileIcon(java.lang.String extension)
Get the icon associated with the specified file type.

Parameters:
extension - the file type extension
Returns:
the icon to displayed for this file type, or null if none

getFileInfo

public static java.lang.String getFileInfo(java.lang.String extension)

getTreePath

public javax.swing.tree.TreePath getTreePath(oscript.fs.AbstractFile file)
Utility to go from AbstractFile to TreePath


pathToFile

protected static final oscript.fs.AbstractFile pathToFile(java.lang.String path)
utility to go from path to file... catches and deals with exceptions, but could return null.