Quaqua 8.0 2011-10-02

ch.randelshofer.quaqua.filechooser
Class FileSystemTreeModel

java.lang.Object
  extended by ch.randelshofer.quaqua.filechooser.FileSystemTreeModel
All Implemented Interfaces:
javax.swing.tree.TreeModel

public class FileSystemTreeModel
extends java.lang.Object
implements javax.swing.tree.TreeModel

The FileSystemTreeModel provides the data model for the file system in a QuaquaFileChooserUI.

It is capable of resolving aliases to files, and it updates its content asynchronously to the AWT Event Dispatcher thread.

Version:
$Id: FileSystemTreeModel.java 363 2010-11-21 17:41:04Z wrandelshofer $
Author:
Werner Randelshofer

Nested Class Summary
 class FileSystemTreeModel.AliasDirectoryNode
           
 class FileSystemTreeModel.AliasNode
           
 class FileSystemTreeModel.DirectoryNode
          This is the implementation for a directory node (a composite node).
 class FileSystemTreeModel.Node
          This is the implementation for a file node (a leaf node).
 
Field Summary
static java.io.File COMPUTER
           
static int INVALID
          This is used for keeping track of the validation state of a node.
protected  javax.swing.event.EventListenerList listenerList
          We store all our listeners here.
static int VALID
          This is used for keeping track of the validation state of a node.
static int VALIDATING
          This is used for keeping track of the validation state of a node.
 
Constructor Summary
FileSystemTreeModel(javax.swing.JFileChooser fileChooser)
          Creates a new instance.
 
Method Summary
 void addTreeModelListener(javax.swing.event.TreeModelListener l)
          Adds a listener for the TreeModelEvent posted after the tree changes.
 void clear()
          Removes all children from the root node.
protected  FileSystemTreeModel.Node createNode(java.io.File f)
          Creates a node for the specified file.
 void dispatchAliasResolution(java.lang.Runnable r)
           
 void dispatchDirectoryUpdater(java.lang.Runnable r)
           
 void dispatchFileUpdater(java.lang.Runnable r)
           
 void dispose()
           
protected  void fireTreeNodeChanged(FileSystemTreeModel.Node node)
          Notifies all listeners that have registered interest for notification on this event type.
protected  void fireTreeNodesChanged(javax.swing.tree.TreeModel source, java.lang.Object[] path, int[] childIndices, java.lang.Object[] children)
          Notifies all listeners that have registered interest for notification on this event type.
protected  void fireTreeNodesInserted(javax.swing.tree.TreeModel source, java.lang.Object[] path, int[] childIndices, java.lang.Object[] children)
          Notifies all listeners that have registered interest for notification on this event type.
protected  void fireTreeNodesRemoved(javax.swing.tree.TreeModel source, java.lang.Object[] path, int[] childIndices, java.lang.Object[] children)
          Notifies all listeners that have registered interest for notification on this event type.
protected  void fireTreeStructureChanged(javax.swing.tree.TreeModel source, java.lang.Object[] path)
          Notifies all listeners that have registered interest for notification on this event type.
 java.lang.Object getChild(java.lang.Object parent, int index)
           
 int getChildCount(java.lang.Object parent)
           
 int getIndexOfChild(java.lang.Object parent, java.lang.Object child)
           
 FileSystemTreeModel.Node getPrototypeValue()
           
 java.lang.Object getRoot()
           
 void invalidateAll()
          Invalidates all nodes in the tree.
 void invalidateCache()
           
 void invalidatePath(javax.swing.tree.TreePath path)
          Invalidates the provided path.
 boolean isAutoValidate()
           
 boolean isLeaf(java.lang.Object node)
           
 boolean isResolveAliasesToFiles()
           
 boolean isResolveFileLabels()
           
 void lazyInvalidatePath(javax.swing.tree.TreePath path)
          Lazily invalidates the provided path.
 void removeTreeModelListener(javax.swing.event.TreeModelListener l)
          Removes a listener previously added with addTreeModelListener().
 void setAutoValidate(boolean b)
          Sets auto validation of the tree.
 void setResolveAliasesToFiles(boolean newValue)
           
 void setResolveFileLabels(boolean newValue)
           
 void stopValidation()
          Stalls validation of the the provided path.
 javax.swing.tree.TreePath toPath(java.io.File file, javax.swing.tree.TreePath templatePath)
           
 javax.swing.tree.TreePath toPath0(java.io.File file)
           
 void validatePath(javax.swing.tree.TreePath path)
          Validates (refreshes) the nodes specified by the provided path.
 void valueForPathChanged(javax.swing.tree.TreePath path, java.lang.Object newValue)
          Messaged when the user has altered the value for the item identified by path to newValue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMPUTER

public static final java.io.File COMPUTER

INVALID

public static final int INVALID
This is used for keeping track of the validation state of a node.

See Also:
Constant Field Values

VALIDATING

public static final int VALIDATING
This is used for keeping track of the validation state of a node.

See Also:
Constant Field Values

VALID

public static final int VALID
This is used for keeping track of the validation state of a node.

See Also:
Constant Field Values

listenerList

protected javax.swing.event.EventListenerList listenerList
We store all our listeners here.

Constructor Detail

FileSystemTreeModel

public FileSystemTreeModel(javax.swing.JFileChooser fileChooser)
Creates a new instance.

Parameters:
fileChooser - The JFileChooser is used to determine the user presentable (localized) names of the files.
Method Detail

dispatchDirectoryUpdater

public void dispatchDirectoryUpdater(java.lang.Runnable r)

dispatchFileUpdater

public void dispatchFileUpdater(java.lang.Runnable r)

dispatchAliasResolution

public void dispatchAliasResolution(java.lang.Runnable r)

clear

public void clear()
Removes all children from the root node.


dispose

public void dispose()

getPrototypeValue

public FileSystemTreeModel.Node getPrototypeValue()

getChild

public java.lang.Object getChild(java.lang.Object parent,
                                 int index)
Specified by:
getChild in interface javax.swing.tree.TreeModel

getChildCount

public int getChildCount(java.lang.Object parent)
Specified by:
getChildCount in interface javax.swing.tree.TreeModel

getIndexOfChild

public int getIndexOfChild(java.lang.Object parent,
                           java.lang.Object child)
Specified by:
getIndexOfChild in interface javax.swing.tree.TreeModel

getRoot

public java.lang.Object getRoot()
Specified by:
getRoot in interface javax.swing.tree.TreeModel

createNode

protected FileSystemTreeModel.Node createNode(java.io.File f)
Creates a node for the specified file. This is used to create nodes depending on their type (file, directory, alias to file, or alias to directory) and depending on the "resolveAliases" property.


toPath

public javax.swing.tree.TreePath toPath(java.io.File file,
                                        javax.swing.tree.TreePath templatePath)

toPath0

public javax.swing.tree.TreePath toPath0(java.io.File file)

isLeaf

public boolean isLeaf(java.lang.Object node)
Specified by:
isLeaf in interface javax.swing.tree.TreeModel

valueForPathChanged

public void valueForPathChanged(javax.swing.tree.TreePath path,
                                java.lang.Object newValue)
Messaged when the user has altered the value for the item identified by path to newValue. If newValue signifies a truly new value the model should post a treeNodesChanged event.

Specified by:
valueForPathChanged in interface javax.swing.tree.TreeModel
Parameters:
path - path to the node that the user has altered
newValue - the new value from the TreeCellEditor

setAutoValidate

public void setAutoValidate(boolean b)
Sets auto validation of the tree. If the tree is autovalidating, it synchronizes its content with the file system.


isAutoValidate

public boolean isAutoValidate()

setResolveAliasesToFiles

public void setResolveAliasesToFiles(boolean newValue)

isResolveAliasesToFiles

public boolean isResolveAliasesToFiles()

setResolveFileLabels

public void setResolveFileLabels(boolean newValue)

isResolveFileLabels

public boolean isResolveFileLabels()

invalidateCache

public void invalidateCache()

invalidatePath

public void invalidatePath(javax.swing.tree.TreePath path)
Invalidates the provided path. This should be used to invalidateChildren the tree model when there are significant changes in the JFileChooser. Such as showing the JFileChooser and changing the FileFilters of the JFileChooser. To actually get a refresh of the tree, validatePath must be called.


invalidateAll

public void invalidateAll()
Invalidates all nodes in the tree. This should be used to invalidate the tree model when there are significant changes in the JFileChooser. To actually get a refresh of the tree, validatePath must be called.


stopValidation

public void stopValidation()
Stalls validation of the the provided path. This should be used to stop validation of the tree model when it is no longer needed.


lazyInvalidatePath

public void lazyInvalidatePath(javax.swing.tree.TreePath path)
Lazily invalidates the provided path. This should be used to trigger lazy refreshes of the tree model when the user navigates through the tree.


validatePath

public void validatePath(javax.swing.tree.TreePath path)
Validates (refreshes) the nodes specified by the provided path. Validation is done for nodes only, which have been marked as invalid. The validation is done asynchronously in worker threads.


addTreeModelListener

public void addTreeModelListener(javax.swing.event.TreeModelListener l)
Adds a listener for the TreeModelEvent posted after the tree changes.

Specified by:
addTreeModelListener in interface javax.swing.tree.TreeModel
Parameters:
l - the listener to add
See Also:
removeTreeModelListener(javax.swing.event.TreeModelListener)

removeTreeModelListener

public void removeTreeModelListener(javax.swing.event.TreeModelListener l)
Removes a listener previously added with addTreeModelListener().

Specified by:
removeTreeModelListener in interface javax.swing.tree.TreeModel
Parameters:
l - the listener to remove
See Also:
addTreeModelListener(javax.swing.event.TreeModelListener)

fireTreeNodeChanged

protected void fireTreeNodeChanged(FileSystemTreeModel.Node node)
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

Parameters:
node - the node being changed
See Also:
EventListenerList

fireTreeNodesChanged

protected void fireTreeNodesChanged(javax.swing.tree.TreeModel source,
                                    java.lang.Object[] path,
                                    int[] childIndices,
                                    java.lang.Object[] children)
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

Parameters:
source - the node being changed
path - the path to the root node
childIndices - the indices of the changed elements
children - the changed elements
See Also:
EventListenerList

fireTreeNodesInserted

protected void fireTreeNodesInserted(javax.swing.tree.TreeModel source,
                                     java.lang.Object[] path,
                                     int[] childIndices,
                                     java.lang.Object[] children)
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

Parameters:
source - the node where new elements are being inserted
path - the path to the root node
childIndices - the indices of the new elements
children - the new elements
See Also:
EventListenerList

fireTreeNodesRemoved

protected void fireTreeNodesRemoved(javax.swing.tree.TreeModel source,
                                    java.lang.Object[] path,
                                    int[] childIndices,
                                    java.lang.Object[] children)
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

Parameters:
source - the node where elements are being removed
path - the path to the root node
childIndices - the indices of the removed elements
children - the removed elements
See Also:
EventListenerList

fireTreeStructureChanged

protected void fireTreeStructureChanged(javax.swing.tree.TreeModel source,
                                        java.lang.Object[] path)
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

Parameters:
source - the node where the tree model has changed
path - the path to the root node
See Also:
EventListenerList

Copyright 2003-2007 (c) Werner Randelshofer.
All rights reserved.