com.anthonyeden.lib.gui
Class FSTreeModel

java.lang.Object
  extended bycom.anthonyeden.lib.gui.FSTreeModel
All Implemented Interfaces:
javax.swing.tree.TreeModel

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

A tree model which models the file system from a given root. This class supports filtering of file names using Perl 5 regular expressions as provided by the Apache ORO regular expression library.

Author:
Anthony Eden

Constructor Summary
FSTreeModel(java.io.File root)
          Construct a new FSTreeModel from the given root file.
 
Method Summary
 void addFilter(org.apache.oro.text.regex.Pattern pattern)
          Add a filter.
 void addFilter(java.lang.String expression)
          Add a filter.
 void addTreeModelListener(javax.swing.event.TreeModelListener l)
          Add a TreeModelListener.
 java.lang.Object getChild(java.lang.Object parent, int index)
          Get the child of the given parent at the given index.
 int getChildCount(java.lang.Object parent)
          Get the number of children under the given parent.
 int getIndexOfChild(java.lang.Object parent, java.lang.Object child)
          Get the index of the child under the given parent.
protected  java.lang.Object[] getPath(java.io.File node)
          Get the tree path as an Object array for the given node.
 java.lang.Object getRoot()
          Get the root file
protected  java.util.ArrayList getTreeModelListeners()
          Get an ArrayList of TreeModelListeners.
 boolean isLeaf(java.lang.Object object)
          Return true if the given object is a leaf node.
 void reload()
          Reload the file system view from the root down.
 void reload(java.io.File node)
          Reload the file system view from the given node down.
 void reloadChanged(java.io.File node, java.io.File child)
          Reload after a change.
 void reloadChanged(java.io.File node, java.io.File[] children)
          Reload after an change.
 void reloadInsert(java.io.File node, java.io.File child)
          Reload after an insert.
 void reloadInsert(java.io.File node, java.io.File[] children)
          Reload after an insert.
 void removeFilter(org.apache.oro.text.regex.Pattern pattern)
          Remove a filter.
 void removeFilter(java.lang.String expression)
          Remove a filter.
 void removeTreeModelListener(javax.swing.event.TreeModelListener l)
          Remove a treeModelListeners.
 void valueForPathChanged(javax.swing.tree.TreePath path, java.lang.Object newValue)
          Notify the tree model that the value at the given TreePath has changed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FSTreeModel

public FSTreeModel(java.io.File root)
Construct a new FSTreeModel from the given root file.

Parameters:
root - The root file
Method Detail

getRoot

public java.lang.Object getRoot()
Get the root file

Specified by:
getRoot in interface javax.swing.tree.TreeModel
Returns:
The root file

getChild

public java.lang.Object getChild(java.lang.Object parent,
                                 int index)
Get the child of the given parent at the given index.

Specified by:
getChild in interface javax.swing.tree.TreeModel
Parameters:
parent - The parent object
index - The child index
Returns:
An object

getChildCount

public int getChildCount(java.lang.Object parent)
Get the number of children under the given parent.

Specified by:
getChildCount in interface javax.swing.tree.TreeModel
Parameters:
parent - The parent object
Returns:
The number of children

isLeaf

public boolean isLeaf(java.lang.Object object)
Return true if the given object is a leaf node.

Specified by:
isLeaf in interface javax.swing.tree.TreeModel
Parameters:
object - The object
Returns:
True if the object is leaf node

valueForPathChanged

public void valueForPathChanged(javax.swing.tree.TreePath path,
                                java.lang.Object newValue)
Notify the tree model that the value at the given TreePath has changed.

Specified by:
valueForPathChanged in interface javax.swing.tree.TreeModel
Parameters:
path - The TreePath
newValue - The new value

getIndexOfChild

public int getIndexOfChild(java.lang.Object parent,
                           java.lang.Object child)
Get the index of the child under the given parent.

Specified by:
getIndexOfChild in interface javax.swing.tree.TreeModel
Parameters:
parent - The parent object
child - The child object
Returns:
The child index

addTreeModelListener

public void addTreeModelListener(javax.swing.event.TreeModelListener l)
Add a TreeModelListener.

Specified by:
addTreeModelListener in interface javax.swing.tree.TreeModel
Parameters:
l - The treeModelListener

removeTreeModelListener

public void removeTreeModelListener(javax.swing.event.TreeModelListener l)
Remove a treeModelListeners.

Specified by:
removeTreeModelListener in interface javax.swing.tree.TreeModel
Parameters:
l - The treeModelListener

addFilter

public void addFilter(java.lang.String expression)
               throws org.apache.oro.text.regex.MalformedPatternException
Add a filter. Filters are Perl 5 regular expressions which are used to filter out unwanted files by name.

Parameters:
expression - The Perl 5 regular expression string
Throws:
org.apache.oro.text.regex.MalformedPatternException - Thrown if the expression is malformed

addFilter

public void addFilter(org.apache.oro.text.regex.Pattern pattern)
Add a filter. Filters are Perl 5 regular expressions which are used to filter out unwanted files by name.

Parameters:
pattern - The Pattern object

removeFilter

public void removeFilter(java.lang.String expression)
Remove a filter.

Parameters:
expression - The expression to remove.

removeFilter

public void removeFilter(org.apache.oro.text.regex.Pattern pattern)
Remove a filter.

Parameters:
pattern - The pattern to remove

reload

public void reload()
Reload the file system view from the root down.


reload

public void reload(java.io.File node)
Reload the file system view from the given node down.

Parameters:
node - The node

reloadInsert

public void reloadInsert(java.io.File node,
                         java.io.File child)
Reload after an insert.

Parameters:
node - The starting node
child - The inserted File object

reloadInsert

public void reloadInsert(java.io.File node,
                         java.io.File[] children)
Reload after an insert.

Parameters:
node - The starting node
children - An array of inserted File objects

reloadChanged

public void reloadChanged(java.io.File node,
                          java.io.File child)
Reload after a change.

Parameters:
node - The starting node
child - The changed File object

reloadChanged

public void reloadChanged(java.io.File node,
                          java.io.File[] children)
Reload after an change.

Parameters:
node - The starting node
children - An array of changed File objects

getPath

protected java.lang.Object[] getPath(java.io.File node)
Get the tree path as an Object array for the given node. The path starts with the given node as the last object in the path and works its way up the path to the root.

Parameters:
node - The File node
Returns:
An Object[] array

getTreeModelListeners

protected java.util.ArrayList getTreeModelListeners()
Get an ArrayList of TreeModelListeners.

Returns:
An ArrayList of TreeModelListeners


Copyright (c) 2000-2003 Anthony Eden. All Rights Reserved.