// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3)
// Source File Name: RootObjectTreeModel.java
package hep.rootio.util;
import hep.rootio.RootClass;
import hep.rootio.RootMember;
import hep.rootio.interfaces.RootObject;
import java.lang.reflect.Array;
import java.util.Enumeration;
import java.util.List;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeNode;
public class RootObjectTreeModel extends DefaultTreeModel
{
static class RootArrayNode extends RootObjectTreeNode
{
public int getChildCount()
{
return Array.getLength(array);
}
public TreeNode getChildAt(int index)
{
return RootObjectTreeNode.getNodeForValue(this, Array.get(array, index), "[" + index + "]", index);
}
String description()
{
return name + " (Array)";
}
private Object array;
private String name;
RootArrayNode(TreeNode parent, Object array, String name, int index)
{
super(parent, index);
this.array = array;
this.name = name;
}
}
static class RootListNode extends RootObjectTreeNode
{
public int getChildCount()
{
return list.size();
}
public TreeNode getChildAt(int index)
{
return RootObjectTreeNode.getNodeForValue(this, list.get(index), "[" + index + "]", index);
}
String description()
{
return name + " (List)";
}
private List list;
private String name;
RootListNode(TreeNode parent, List list, String name, int index)
{
super(parent, index);
this.list = list;
this.name = name;
}
}
static class RootObjectNode extends RootSubObject
{
String description()
{
return name + " (" + super.description() + ")";
}
private String name;
RootObjectNode(TreeNode parent, RootObject obj, String name, int index)
{
super(parent, obj, obj.rootClass(), index);
this.name = name;
}
}
static class RootSimpleValue extends RootObjectTreeNode
{
public boolean isLeaf()
{
return true;
}
String description()
{
return name + " = " + value;
}
private Object value;
private String name;
RootSimpleValue(TreeNode parent, Object value, String name, int index)
{
super(parent, index);
this.value = value;
this.name = name;
}
}
static class RootSubObject extends RootObjectTreeNode
{
public int getChildCount()
{
int n = klass.getSuperClasses().length;
n += klass.getMembers().length;
return n;
}
public TreeNode getChildAt(int index)
{
RootClass superClasses[] = klass.getSuperClasses();
if(index < superClasses.length)
{
return new RootSubObject(this, obj, superClasses[index], index);
} else
{
RootMember member = klass.getMembers()[index - superClasses.length];
Object value = obj.getValue(member.getName());
RootObjectTreeNode node = RootObjectTreeNode.getNodeForValue(this, value, member.getName(), index);
node.setToolTip(member.getComment());
return node;
}
}
String description()
{
return "Class " + klass.getClassName();
}
private RootObject obj;
private RootClass klass;
RootSubObject(TreeNode parent, RootObject obj, RootClass klass, int index)
{
super(parent, index);
this.obj = obj;
this.klass = klass;
}
}
static abstract class RootObjectTreeNode
implements TreeNode
{
public TreeNode getParent()
{
return parent;
}
public int getIndex(TreeNode child)
{
return ((RootObjectTreeNode)child).index;
}
public Enumeration children()
{
return new Enumeration() {
public boolean hasMoreElements()
{
return i < n;
}
public Object nextElement()
{
return getChildAt(i++);
}
private int n;
private int i;
{
n = getChildCount();
i = 0;
}
};
}
static RootObjectTreeNode getNodeForValue(TreeNode parent, Object value, String name, int index)
{
if(value == null)
return new RootSimpleValue(parent, "null", name, index);
if(value instanceof RootObject)
return new RootObjectNode(parent, (RootObject)value, name, index);
if(value instanceof List)
return new RootListNode(parent, (List)value, name, index);
if(value.getClass().isArray())
return new RootArrayNode(parent, value, name, index);
else
return new RootSimpleValue(parent, value, name, index);
}
public boolean getAllowsChildren()
{
return true;
}
public boolean isLeaf()
{
return false;
}
public int getChildCount()
{
return 0;
}
public TreeNode getChildAt(int p1)
{
throw new InternalError("getChildAt() called");
}
public String toString()
{
return description();
}
void setToolTip(String value)
{
tooltip = value;
}
String toolTip()
{
return tooltip;
}
abstract String description();
private TreeNode parent;
private int index;
private String tooltip;
RootObjectTreeNode(TreeNode parent, int index)
{
this.parent = parent;
this.index = index;
}
}
public RootObjectTreeModel(Object top, String name)
{
super(RootObjectTreeNode.getNodeForValue(null, top, name, 0));
}
protected RootObjectTreeModel(TreeNode node)
{
super(node);
}
protected static TreeNode getNodeForChild(TreeNode parent, Object child, String name, int index)
{
return RootObjectTreeNode.getNodeForValue(parent, child, name, index);
}
protected static int getIndex(TreeNode child)
{
return ((RootObjectTreeNode)child).index;
}
}
Ads help maintain this website.