|
import java.io.*;
|
import javax.swing.event.*;
|
import javax.swing.tree.*;
|
|
class cFileSystemModel implements TreeModel
|
{
|
File root;
|
cFilter filter;
|
|
public cFileSystemModel(File r)
|
{
|
root = r;
|
}
|
|
public cFileSystemModel(File r, cFilter f)
|
{
|
root = r;
|
filter = f;
|
}
|
|
public void addTreeModelListener(TreeModelListener l)
|
{
|
}
|
|
public Object getChild(Object parent, int index)
|
{
|
//new Exception().printStackTrace();
|
|
//System.out.println("child[" + index + "] = " + ((File) parent).listFiles(filter)[index]);
|
|
File[] files = table.get(parent);
|
assert(files != null);
|
//return ((File) parent).listFiles(filter)[index];
|
return files[index];
|
|
}
|
|
java.util.Hashtable<File, File[]> table = new java.util.Hashtable<File, File[]>();
|
|
public int getChildCount(Object parent)
|
{
|
if( isLeaf(parent) )
|
return 0;
|
else
|
{
|
//System.out.println(parent + " childcount = " + ((File) parent).listFiles(filter).length);
|
File[] files = table.get(parent);
|
|
if(files == null)
|
{
|
files = ((File) parent).listFiles(filter);
|
table.put(((File) parent), files);
|
}
|
|
return files.length;
|
}
|
}
|
|
public int getIndexOfChild(Object parent, Object child)
|
{
|
assert false;
|
return 0;
|
}
|
|
public Object getRoot()
|
{
|
return root;
|
}
|
|
public boolean isLeaf(Object node)
|
{
|
return !((File) node).isDirectory();
|
}
|
|
public void removeTreeModelListener(TreeModelListener l)
|
{
|
}
|
|
public void valueForPathChanged(TreePath path, Object newValue)
|
{
|
}
|
|
static class Renderer extends DefaultTreeCellRenderer
|
{
|
public Renderer() {
|
}
|
|
public java.awt.Component getTreeCellRendererComponent(
|
cTree tree,
|
Object value,
|
boolean sel,
|
boolean expanded,
|
boolean leaf,
|
int row,
|
boolean hasFocus)
|
{
|
System.out.println(value);
|
super.getTreeCellRendererComponent(
|
tree, value, sel,
|
expanded, leaf, row,
|
hasFocus);
|
setToolTipText("This book is in the Tutorial series.");
|
|
return this;
|
}
|
|
public void setText(String text)
|
{
|
//System.out.println(text);
|
super.setText(new File(text).getName());
|
}
|
}
|
}
|