package baf.sci; import com.sun.java.swing.tree.TreeNode; import java.io.*; import java.util.*; /** This class represents a single SCI resource that has not been loaded * into memory. */ public abstract class ResourceIndex implements TreeNode, baf.util.Comparable { int restype, resnum; TypedResourceList parent; /** Creates a ResourceIndex for an external file with the given * attributes. */ ResourceIndex(int restype, int resnum) { this.restype = restype; this.resnum = resnum; } ResourceIndex() { } public String toString() { return Resource.getName(restype, resnum); } public abstract byte[] getArray() throws ResourceNotFoundException; public Resource getResource() throws ResourceNotFoundException { byte b[] = getArray(); Resource res; switch (restype) { case Resource.SCRIPT: res = new ScriptResource(b, resnum); break; case Resource.TEXT: res = new TextResource(b, resnum); break; default: res = new Resource(b, restype, resnum); } return res; } public void view() throws ResourceNotFoundException { getResource().view(); } /* TreeNode interface */ public TreeNode getChildAt(int i) { throw new NoSuchElementException(); } public int getChildCount() { return 0; } public TreeNode getParent() { return parent; } public int getIndex(TreeNode child) { return -1; } public boolean getAllowsChildren() { return false; } public boolean isLeaf() { return true; } public Enumeration children() { Vector v = new Vector(); return v.elements(); } /* Comparable interface */ public int compareTo(Object o) { ResourceIndex i = (ResourceIndex)o; if (i.restype != restype) return restype - i.restype; else return resnum - i.resnum; } }