// 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:   RootDirectoryTreeModel.java

package hep.rootio.util;

import hep.rootio.RootClass;
import hep.rootio.interfaces.*;

import java.io.IOException;
import java.io.PrintStream;
import java.util.List;
import javax.swing.event.TreeModelListener;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;

// Referenced classes of package hep.rootio.util:
//            FakeTKey, BranchEntry

public class RootDirectoryTreeModel
    implements TreeModel
{

    public RootDirectoryTreeModel(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
        {
            if(parent instanceof TKey)
            {
                TKey node = (TKey)parent;
                Object object = node.getObject();
                if(object instanceof TDirectory)
                {
                    TDirectory dir = (TDirectory)object;
                    return dir.getKey(index);
                } else
                {
                    TTree tree = (TTree)object;
                    return tree.getBranch(index);
                }
            }
            TBranch branch = (TBranch)parent;
            int n = branch.getBranches().size();
            if(index < n)
            {
                Object p = branch.getBranches().get(index);
                if(p instanceof TBranch)
                    return p;
                if(p instanceof TBranchClones)
                    return p;
                else
                    return new BranchEntry("????" + p.getClass(), index);
            } else
            {
                return new BranchEntry(branch, index, n);
            }
        }
        catch(IOException x)
        {
            handleException(x);
            return new BranchEntry(x, index);
        }
    }

    public int getChildCount(Object parent)
    {
        try
        {
            if(parent instanceof TKey)
            {
                TKey node = (TKey)parent;
                Object object = node.getObject();
                if(object instanceof TDirectory)
                {
                    TDirectory dir = (TDirectory)object;
                    return dir.nKeys();
                } else
                {
                    TTree tree = (TTree)object;
                    return tree.getNBranches();
                }
            } else
            {
                TBranch branch = (TBranch)parent;
                int n = branch.getBranches().size();
                n += branch.getNEntries();
                return n;
            }
        }
        catch(IOException x)
        {
            handleException(x);
        }
        return 0;
    }

    public int getIndexOfChild(Object parent, Object child)
    {
        try
        {
            if(parent instanceof TKey)
            {
                TKey node = (TKey)parent;
                Object object = node.getObject();
                if(object instanceof TDirectory)
                {
                    TDirectory dir = (TDirectory)object;
                    int n = dir.nKeys();
                    for(int i = 0; i < n; i++)
                        if(dir.getKey(i).equals(child))
                            return i;

                    throw new IOException("Could not find " + child + " in " + dir);
                }
                TTree tree = (TTree)object;
                for(int i = 0; i < tree.getNBranches(); i++)
                    if(tree.getBranch(i).equals(child))
                        return i;

                throw new IOException("Could not find " + child + " in " + tree);
            }
            if(child instanceof BranchEntry)
            {
                BranchEntry entry = (BranchEntry)child;
                return entry.getIndex();
            }
            TBranch branch = (TBranch)parent;
            int index = branch.getBranches().indexOf(child);
            if(index < 0)
                System.out.println("Illegal index " + index + " " + child + " " + branch);
            return index;
        }
        catch(IOException x)
        {
            handleException(x);
        }
        return -1;
    }

    public Object getRoot()
    {
        return top;
    }

    public boolean isLeaf(Object parent)
    {
        try
        {
            if(parent instanceof TKey)
            {
                TKey key = (TKey)parent;
                RootClass rc = key.getObjectClass();
                if(rc.instanceOf("TDirectory"))
                    return false;
                return !rc.instanceOf("TTree");
            }
            return !(parent instanceof TBranch);
        }
        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.