// 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: RootHistogramTreeModel.java
package hep.rootio.util;
import hep.rootio.RootClass;
import hep.rootio.interfaces.TDirectory;
import hep.rootio.interfaces.TKey;
import java.io.IOException;
import javax.swing.event.TreeModelListener;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
// Referenced classes of package hep.rootio.util:
// FakeTKey
public class RootHistogramTreeModel
implements TreeModel
{
public RootHistogramTreeModel(TDirectory topDir)
{
top = new FakeTKey(topDir);
}
protected void handleException(IOException x)
{
throw new RuntimeException("IOException reading root file");
}
public Object getChild(Object parent, int index)
{
try
{
TKey node = (TKey)parent;
Object object = node.getObject();
if(object instanceof TDirectory)
{
TDirectory dir = (TDirectory)object;
int nKeys = dir.nKeys();
for(int i = 0; i < nKeys; i++)
{
TKey key = dir.getKey(i);
RootClass keyClass = key.getObjectClass();
if((keyClass.instanceOf("TDirectory") || keyClass.instanceOf("TH1")) && index-- == 0)
return key;
}
}
return null;
}
catch(IOException x)
{
handleException(x);
}
return null;
}
public int getChildCount(Object parent)
{
try
{
TKey node = (TKey)parent;
TDirectory dir = (TDirectory)node.getObject();
int nKeys = dir.nKeys();
int nChildren = 0;
for(int i = 0; i < nKeys; i++)
{
TKey key = dir.getKey(i);
RootClass keyClass = key.getObjectClass();
if(keyClass.instanceOf("TDirectory"))
nChildren++;
else
if(keyClass.instanceOf("TH1"))
nChildren++;
}
return nChildren;
}
catch(IOException x)
{
handleException(x);
}
return 0;
}
public int getIndexOfChild(Object parent, Object child)
{
try
{
TKey node = (TKey)parent;
TDirectory dir = (TDirectory)node.getObject();
int nKeys = dir.nKeys();
int nChildren = 0;
for(int i = 0; i < nKeys; i++)
{
TKey key = dir.getKey(i);
if(key == child)
return nChildren;
RootClass keyClass = key.getObjectClass();
if(keyClass.instanceOf("TDirectory"))
nChildren++;
else
if(keyClass.instanceOf("TH1"))
nChildren++;
}
return -1;
}
catch(IOException x)
{
handleException(x);
}
return -1;
}
public Object getRoot()
{
return top;
}
public boolean isLeaf(Object parent)
{
try
{
TKey key = (TKey)parent;
RootClass rc = key.getObjectClass();
return !rc.instanceOf("TDirectory");
}
catch(IOException x)
{
handleException(x);
}
return true;
}
public void removeTreeModelListener(TreeModelListener treemodellistener)
{
}
public void valueForPathChanged(TreePath treepath, Object obj)
{
}
public void addTreeModelListener(TreeModelListener treemodellistener)
{
}
private TKey top;
}
Ads help maintain this website.