|
import javax.swing.event.*;
|
import javax.swing.tree.*;
|
|
class cTreeModel implements TreeModel
|
{
|
Object3D root;
|
|
public cTreeModel(Object3D owner)
|
{
|
root = owner;
|
}
|
|
public void addTreeModelListener(TreeModelListener l)
|
{
|
}
|
|
public Object getChild(Object parent, int index)
|
{
|
Object3D /*Composite*/ group = (Object3D /*Composite*/) parent;
|
|
return group./*children.*/get(index);
|
}
|
|
public int getChildCount(Object parent)
|
{
|
//if (parent instanceof Composite)
|
{
|
return ((Object3D /*Composite*/) parent)/*.children*/.Size();
|
}
|
|
//return 0;
|
}
|
|
public int getIndexOfChild(Object parent, Object child)
|
{
|
Object3D /*Composite*/ group = (Object3D /*Composite*/) parent;
|
|
return group./*GetObject().*/indexOf(child);
|
}
|
|
public Object getRoot()
|
{
|
return root;
|
}
|
|
public boolean isLeaf(Object node)
|
{
|
return ((Object3D) node).Size() == 0; // !(node instanceof Composite);
|
}
|
|
public void removeTreeModelListener(TreeModelListener l)
|
{
|
}
|
|
public void valueForPathChanged(TreePath path, Object newValue)
|
{
|
}
|
|
static class Renderer extends DefaultTreeCellRenderer
|
{
|
public Renderer()
|
{
|
}
|
|
public java.awt.Component getTreeCellRendererComponent(
|
javax.swing.JTree tree,
|
Object value,
|
boolean sel,
|
boolean expanded,
|
boolean leaf,
|
int row,
|
boolean hasFocus)
|
{
|
//System.out.println(value.getClass());
|
super.getTreeCellRendererComponent(tree, value, sel,
|
expanded, leaf, row, hasFocus);
|
String stringValue = tree.convertValueToText(value, sel,
|
expanded, leaf, row, hasFocus);
|
|
//this.tree = tree;
|
this.hasFocus = hasFocus;
|
setText(stringValue);
|
|
Object3D obj = (Object3D) value;
|
|
int r = 0, g = 0, b = 0;
|
|
if (obj.live)
|
{
|
g = 192;
|
}
|
|
if (obj.hide)
|
{
|
r = 192;
|
}
|
|
if (obj.link2master)
|
{
|
b = 192;
|
}
|
|
java.awt.Color fg = new java.awt.Color(r, g, b);
|
|
// isDropCell = false;
|
// JTree.DropLocation dropLocation = tree.getDropLocation();
|
//
|
// if (dropLocation != null
|
// && dropLocation.getChildIndex() == -1
|
// && tree.getRowForPath(dropLocation.getPath()) == row) {
|
//
|
// Color col = UIManager.getColor("Tree.dropCellForeground");
|
// if (col != null) {
|
// fg = col;
|
// } else {
|
// fg = getTextSelectionColor();
|
// }
|
//
|
// isDropCell = true;
|
// } else if (sel) {
|
// fg = getTextSelectionColor();
|
// } else {
|
// fg = getTextNonSelectionColor();
|
// }
|
|
// setBackground(fg);
|
setForeground(fg);
|
|
// There needs to be a way to specify disabled icons.
|
// if (!tree.isEnabled()) {
|
// setEnabled(false);
|
//
|
// if (leaf) {
|
// setDisabledIcon(getLeafIcon());
|
// } else if (expanded) {
|
// setDisabledIcon(getOpenIcon());
|
// } else {
|
// setDisabledIcon(getClosedIcon());
|
// }
|
// }
|
// else {
|
// setEnabled(true);
|
//
|
// if (leaf) {
|
// setIcon(getLeafIcon());
|
// } else if (expanded) {
|
// setIcon(getOpenIcon());
|
// } else {
|
// setIcon(getClosedIcon());
|
// }
|
// }
|
|
setComponentOrientation(tree.getComponentOrientation());
|
|
selected = sel;
|
|
//Object3D obj = (Object3D) value;
|
|
if (obj.material == null)
|
{
|
setIcon(null);
|
}
|
|
setToolTipText("This book is in the Tutorial series.");
|
|
return this;
|
}
|
|
public void setText(String text)
|
{
|
//System.out.println(text);
|
super.setText(text);
|
}
|
}
|
}
|