|
import java.io.*;
|
import javax.swing.Icon;
|
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 java.util.Hashtable<String, javax.swing.ImageIcon> icons = new java.util.Hashtable<String, javax.swing.ImageIcon>();
|
|
|
static class Renderer extends DefaultTreeCellRenderer
|
{
|
|
public Renderer()
|
{
|
}
|
|
public java.awt.Component getTreeCellRendererComponent(
|
//cTree tree,
|
javax.swing.JTree 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);
|
|
String valueString = value.toString();
|
String lcString = valueString.toLowerCase();
|
|
if (lcString.endsWith(".gfd") || lcString.endsWith(".obj") || lcString.endsWith(".3ds"))
|
{
|
if (true)
|
{
|
// Small icons
|
String valueTruncated = valueString.substring(0, valueString.length()-4);
|
|
//System.out.println("valueTruncated = " + valueTruncated);
|
|
javax.swing.ImageIcon rendererIcon = icons.get(valueTruncated);
|
|
if (rendererIcon == null)
|
{
|
if (new File(valueTruncated + ".jpg").exists())
|
{
|
rendererIcon = new javax.swing.ImageIcon(valueTruncated + ".jpg");
|
}
|
else
|
{
|
if (new File(valueTruncated + ".png").exists())
|
{
|
rendererIcon = new javax.swing.ImageIcon(valueTruncated + ".png");
|
}
|
}
|
|
if (rendererIcon == null)
|
{
|
rendererIcon = ObjEditor.GetIcon("icons/primitives.png");
|
}
|
|
icons.put(valueTruncated, rendererIcon);
|
}
|
|
setIcon(rendererIcon);
|
}
|
else
|
{
|
// Large icons
|
String[] split = valueString.split("/");
|
|
String valueTruncated = "";
|
|
for (int i=1; i<split.length-1; i++)
|
{
|
valueTruncated += "/" + split[i];
|
}
|
|
valueTruncated += "/icon.jpg";
|
|
System.out.println(valueTruncated);
|
|
javax.swing.ImageIcon rendererIcon = icons.get(valueTruncated);
|
|
if (rendererIcon == null)
|
{
|
if (new File(valueTruncated).exists())
|
{
|
rendererIcon = new javax.swing.ImageIcon(valueTruncated);
|
}
|
|
if (rendererIcon == null)
|
{
|
rendererIcon = new javax.swing.ImageIcon();
|
}
|
|
icons.put(valueTruncated, rendererIcon);
|
}
|
|
setIcon(rendererIcon);
|
}
|
}
|
else
|
{
|
//setIcon(null);
|
// Icon systemIcon = javax.swing.filechooser.FileSystemView.getFileSystemView().getSystemIcon( new File(valueString) );
|
// setIcon(systemIcon);
|
}
|
|
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());
|
}
|
}
|
}
|