package baf.sci; import java.io.*; import java.util.Vector; import com.sun.java.swing.tree.*; /** A representation of a directory in which SCI resources can be found. */ public class ResourceDir implements TreeNode { File file; Vector collections; public ResourceDir(String path) { file = new File(path); collections = new Vector(); // Collect resources in the current directory collections.addElement(new ExternalResourceCollection(this)); // Read resource.map and create all of its ResourceIndices File map = new File(file, "resource.map"); try { InputStream in = new BufferedInputStream(new FileInputStream(map)); int end = 0; // the smallest nonexistent resource file # while (true) { InternalResourceIndex residx = new InternalResourceIndex(in); while (residx.resfilenum >= end) { collections.addElement(new ResourceCollection(this, end)); end++; } ResourceCollection coll = (ResourceCollection)collections.elementAt(residx.resfilenum+1); coll.addResourceIndex(residx); } } catch (IOException e) { if (!(e instanceof EOFException)) e.printStackTrace(); } } public String toString() { return file.toString(); } /* TreeNode functions */ public TreeNode getChildAt(int i) { return (TreeNode)collections.elementAt(i); } public int getChildCount() { return collections.size(); } public TreeNode getParent() { return null; } public int getIndex(TreeNode node) { return collections.indexOf(node); } public boolean getAllowsChildren() { return true; } public boolean isLeaf() { return false; } public java.util.Enumeration children() { return collections.elements(); } }