TrueZIP 6.8.3

de.schlichtherle.io.swing.tree
Class FileTreeModel

java.lang.Object
  extended by de.schlichtherle.io.swing.tree.FileTreeModel
All Implemented Interfaces:
TreeModel

public class FileTreeModel
extends Object
implements TreeModel

A TreeModel which traverses java.io.File instances. If the root of this tree model is actually an instance of de.schlichtherle.io.File, its archive detector is used to detect any archive files in the directory tree. This allows you to traverse archive files just like directories.

Since:
TrueZIP 5.1
Author:
Christian Schlichtherle

Field Summary
private  Map cache
          Used to cache the contents of directories.
private static Collator collator
          A collator for file names which considers case according to the platform's standard.
private  Comparator comparator
          A comparator for java.io.File or super classes.
static Comparator FILE_NAME_COMPARATOR
          A comparator which sorts directory entries to the beginning.
private  FileFilter filter
           
private  EventListenerList listeners
           
private  File root
           
 
Constructor Summary
FileTreeModel()
          Equivalent to FileTreeModel(null, null, FILE_NAME_COMPARATOR).
FileTreeModel(File root)
          Equivalent to FileTreeModel(root, null, FILE_NAME_COMPARATOR).
FileTreeModel(File root, FileFilter filter)
          Equivalent to FileTreeModel(root, filter, FILE_NAME_COMPARATOR).
FileTreeModel(File root, FileFilter filter, Comparator comparator)
          Creates a new FileTreeModel which browses the specified root file.
 
Method Summary
 void addTreeModelListener(TreeModelListener l)
          Adds a listener to this model.
 boolean archiveCopyAllTo(File oldNode, File node)
          Copies oldNode to node recursively, preserving its last modification time and updates the tree accordingly.
 boolean archiveCopyTo(File oldNode, File node)
          Copies oldNode to node, preserving its last modification time and updates the tree accordingly.
 boolean copyAllTo(File oldNode, File node)
          Copies oldNode to node recursively and updates the tree accordingly.
 boolean copyFrom(File node, InputStream in)
          Creates node as a new file with the contents read from in and updates the tree accordingly.
 boolean copyTo(File oldNode, File node)
          Copies oldNode to node and updates the tree accordingly.
 boolean createNewFile(File node)
          Creates node as a new file in the file system and updates the tree accordingly.
private  File[] createPath(File node)
          Returns an array of File objects indicating the path from the root to the given node.
private  File[] createPath(File node, int level)
           
 TreePath createTreePath(File node)
          Returns a TreePath for the given node or null if the node is not part of this file tree.
 boolean delete(File node)
          Deletes the file or empty directory node and updates the tree accordingly.
 boolean deleteAll(File node)
          Deletes the file or (probably not empty) directory node and updates the tree accordingly.
protected  void fireTreeNodesChanged(TreeModelEvent evt)
          This method calls TreeModelListener.treeStructureChanged(TreeModelEvent) on all listeners of this TreeModel.
protected  void fireTreeNodesInserted(TreeModelEvent evt)
          This method calls TreeModelListener.treeStructureChanged(TreeModelEvent) on all listeners of this TreeModel.
protected  void fireTreeNodesRemoved(TreeModelEvent evt)
          This method calls TreeModelListener.treeStructureChanged(TreeModelEvent) on all listeners of this TreeModel.
protected  void fireTreeStructureChanged(TreeModelEvent evt)
          This method calls TreeModelListener.treeStructureChanged(TreeModelEvent) on all listeners of this TreeModel.
 void forget(File node)
          Deprecated. This method is only public in order to make it available to JFileTree - it is not intended for public use. In particular, this method does not notify the tree of any structural changes in the file system.
private  void forget(File node, boolean childrenToo)
          Clears the internal cache associated with node.
 Object getChild(Object parent, int index)
           
 int getChildCount(Object parent)
           
private  File[] getChildren(File parent)
           
 int getIndexOfChild(Object parent, Object child)
           
 Object getRoot()
          Returns the root of this tree model.
 TreePath getTreePath(File node)
          Deprecated. Use createTreePath(java.io.File) instead.
 boolean isLeaf(Object node)
           
 boolean mkdir(File node)
          Creates node as a new directory and updates the tree accordingly.
 boolean mkdirs(File node)
          Creates node as a new directory, including all parents, and updates the tree accordingly.
 void nodeChanged(File node)
          Updates the given node in the tree.
 void nodeInserted(File node)
          Inserts the given node in the tree.
 void nodeInsertedOrStructureChanged(File node)
          Inserts the given node in the tree or reloads the tree structure for the given node if it already exists.
 void nodeRemoved(File node)
          Removes the given node from the tree.
 void refresh()
          Refreshes the tree structure for the entire tree.
 void refresh(File node)
          Alias for structureChanged(java.io.File).
 void removeTreeModelListener(TreeModelListener l)
          Removes a listener from this model.
 boolean renameTo(File oldNode, File newNode)
          Renames oldNode to newNode and updates the tree accordingly.
 void structureChanged(File node)
          Reloads the tree structure for the given node.
 void valueForPathChanged(TreePath path, Object newValue)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

collator

private static final Collator collator
A collator for file names which considers case according to the platform's standard.


FILE_NAME_COMPARATOR

public static final Comparator FILE_NAME_COMPARATOR
A comparator which sorts directory entries to the beginning.


cache

private final Map cache
Used to cache the contents of directories. Maps File -> File[] instances.


root

private final File root

filter

private final FileFilter filter

comparator

private final Comparator comparator
A comparator for java.io.File or super classes.


listeners

private final EventListenerList listeners
Constructor Detail

FileTreeModel

public FileTreeModel()
Equivalent to FileTreeModel(null, null, FILE_NAME_COMPARATOR). This constructor isn't particularly useful - it's only provided to implement the JavaBean pattern.


FileTreeModel

public FileTreeModel(File root)
Equivalent to FileTreeModel(root, null, FILE_NAME_COMPARATOR).


FileTreeModel

public FileTreeModel(File root,
                     FileFilter filter)
Equivalent to FileTreeModel(root, filter, FILE_NAME_COMPARATOR).


FileTreeModel

public FileTreeModel(File root,
                     FileFilter filter,
                     Comparator comparator)
Creates a new FileTreeModel which browses the specified root file. If file is an instance of File, its archive detector is used to detect any archive files in the directory tree.

Parameters:
root - The root of this FileTreeModel. If this is null, an empty tree is created.
filter - Used to filter the files and directories which are present in this TreeModel. If this is null, all files are accepted.
comparator - A comparator for java.io.File instances or super classes. This must not be null.
Throws:
NullPointerException - If comparator is null.
IllegalArgumentException - If root isn't null and comparing it to itself didn't result in 0.
ClassCastException - If root isn't null and comparator isn't a Comparator for java.io.File or super class instances.
Since:
TrueZIP 6.5.4 (this constructor)
Method Detail

getRoot

public Object getRoot()
Returns the root of this tree model. This is actually an instance of java.io.File or a subclass, like de.schlichtherle.io.File.

Specified by:
getRoot in interface TreeModel
Returns:
A File object or null if this tree model has not been created with a File object.

getChild

public Object getChild(Object parent,
                       int index)
Specified by:
getChild in interface TreeModel

getChildCount

public int getChildCount(Object parent)
Specified by:
getChildCount in interface TreeModel

isLeaf

public boolean isLeaf(Object node)
Specified by:
isLeaf in interface TreeModel

valueForPathChanged

public void valueForPathChanged(TreePath path,
                                Object newValue)
Specified by:
valueForPathChanged in interface TreeModel

getIndexOfChild

public int getIndexOfChild(Object parent,
                           Object child)
Specified by:
getIndexOfChild in interface TreeModel

getChildren

private File[] getChildren(File parent)

getTreePath

public TreePath getTreePath(File node)
Deprecated. Use createTreePath(java.io.File) instead.

Forwards the call to createTreePath(java.io.File).


createTreePath

public TreePath createTreePath(File node)
Returns a TreePath for the given node or null if the node is not part of this file tree.


createPath

private File[] createPath(File node)
Returns an array of File objects indicating the path from the root to the given node.

Parameters:
node - The File object to get the path for.
Returns:
An array of File objects, suitable as a constructor argument for TreePath or null if node is not part of this file tree.

createPath

private File[] createPath(File node,
                          int level)

createNewFile

public boolean createNewFile(File node)
                      throws IOException
Creates node as a new file in the file system and updates the tree accordingly. However, the current selection may get lost. If you would like to create a new file with initial content, please use copyFrom(de.schlichtherle.io.File, InputStream).

Returns:
Whether or not the file has been newly created.
Throws:
IOException - If an I/O error occurs.

mkdir

public boolean mkdir(File node)
Creates node as a new directory and updates the tree accordingly. However, the current selection may get lost.

Returns:
Whether or not the file has been newly created.
Throws:
IOException - If an I/O error occurs.

mkdirs

public boolean mkdirs(File node)
Creates node as a new directory, including all parents, and updates the tree accordingly. However, the current selection may get lost.

Returns:
Whether or not the file has been newly created.
Throws:
IOException - If an I/O error occurs.

copyFrom

public boolean copyFrom(File node,
                        InputStream in)
Creates node as a new file with the contents read from in and updates the tree accordingly. However, the current selection may get lost. Note that the given stream is always closed.

Returns:
Whether or not the file has been newly created.
Throws:
IOException - If an I/O error occurs.

copyTo

public boolean copyTo(File oldNode,
                      File node)
Copies oldNode to node and updates the tree accordingly. However, the current selection may get lost.

Returns:
Whether or not the file has been successfully renamed.

copyAllTo

public boolean copyAllTo(File oldNode,
                         File node)
Copies oldNode to node recursively and updates the tree accordingly. However, the current selection may get lost.

Returns:
Whether or not the file has been successfully renamed.

archiveCopyTo

public boolean archiveCopyTo(File oldNode,
                             File node)
Copies oldNode to node, preserving its last modification time and updates the tree accordingly. However, the current selection may get lost.

Returns:
Whether or not the file has been successfully renamed.

archiveCopyAllTo

public boolean archiveCopyAllTo(File oldNode,
                                File node)
Copies oldNode to node recursively, preserving its last modification time and updates the tree accordingly. However, the current selection may get lost.

Returns:
Whether or not the file has been successfully renamed.

renameTo

public boolean renameTo(File oldNode,
                        File newNode)
Renames oldNode to newNode and updates the tree accordingly. However, the current selection may get lost.

Returns:
Whether or not the file has been successfully renamed.

delete

public boolean delete(File node)
Deletes the file or empty directory node and updates the tree accordingly. However, the current selection may get lost.

Returns:
Whether or not the file or directory has been successfully deleted.
Throws:
IOException - If an I/O error occurs.

deleteAll

public boolean deleteAll(File node)
Deletes the file or (probably not empty) directory node and updates the tree accordingly. However, the current selection may get lost.

Returns:
Whether or not the file or directory has been successfully deleted.
Throws:
IOException - If an I/O error occurs.

nodeInsertedOrStructureChanged

public void nodeInsertedOrStructureChanged(File node)
Inserts the given node in the tree or reloads the tree structure for the given node if it already exists. This method calls TreeModelListener.treeNodesInserted(TreeModelEvent) on all listeners of this TreeModel.


nodeInserted

public void nodeInserted(File node)
Inserts the given node in the tree. If node already exists, nothing happens. This method calls TreeModelListener.treeNodesInserted(TreeModelEvent) on all listeners of this TreeModel.


nodeChanged

public void nodeChanged(File node)
Updates the given node in the tree. This method calls TreeModelListener.treeNodesChanged(TreeModelEvent) on all listeners of this TreeModel.


nodeRemoved

public void nodeRemoved(File node)
Removes the given node from the tree. This method calls TreeModelListener.treeNodesRemoved(TreeModelEvent) on all listeners of this TreeModel.


refresh

public void refresh()
Refreshes the tree structure for the entire tree. This method calls TreeModelListener.treeStructureChanged(TreeModelEvent) on all listeners of this TreeModel.


refresh

public final void refresh(File node)
Alias for structureChanged(java.io.File).


structureChanged

public void structureChanged(File node)
Reloads the tree structure for the given node. This method calls TreeModelListener.treeStructureChanged(TreeModelEvent) on all listeners of this TreeModel.


forget

public final void forget(File node)
Deprecated. This method is only public in order to make it available to JFileTree - it is not intended for public use. In particular, this method does not notify the tree of any structural changes in the file system.

Clears the internal cache associated with node and all of its children.


forget

private void forget(File node,
                    boolean childrenToo)
Clears the internal cache associated with node.

Parameters:
childrenToo - If and only if true, the internal cache for all children is cleared, too.

addTreeModelListener

public void addTreeModelListener(TreeModelListener l)
Adds a listener to this model.

Specified by:
addTreeModelListener in interface TreeModel
Parameters:
l - The listener to add.

removeTreeModelListener

public void removeTreeModelListener(TreeModelListener l)
Removes a listener from this model.

Specified by:
removeTreeModelListener in interface TreeModel
Parameters:
l - The listener to remove.

fireTreeNodesChanged

protected void fireTreeNodesChanged(TreeModelEvent evt)
This method calls TreeModelListener.treeStructureChanged(TreeModelEvent) on all listeners of this TreeModel. May be used to tell the listeners about a change in the file system.


fireTreeNodesInserted

protected void fireTreeNodesInserted(TreeModelEvent evt)
This method calls TreeModelListener.treeStructureChanged(TreeModelEvent) on all listeners of this TreeModel. May be used to tell the listeners about a change in the file system.


fireTreeNodesRemoved

protected void fireTreeNodesRemoved(TreeModelEvent evt)
This method calls TreeModelListener.treeStructureChanged(TreeModelEvent) on all listeners of this TreeModel. May be used to tell the listeners about a change in the file system.


fireTreeStructureChanged

protected void fireTreeStructureChanged(TreeModelEvent evt)
This method calls TreeModelListener.treeStructureChanged(TreeModelEvent) on all listeners of this TreeModel. May be used to tell the listeners about a change in the file system.


TrueZIP 6.8.3

Copyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.