public abstract class Resources {
public static char DELIMITER = '.';
public static String FILE_EXTENSION = ".rcrs";<P> public class DoesNotExistException extends IOException {
public String getMessage() {
return "Resource does not exist.";
}
}<P> public static Resources loadResources(File f) throws IOException {
try {
FileInputStream in = new FileInputStream(f);
ObjectInputStream oin = new ObjectInputStream(in);
Object o = oin.readObject();
if(! (o instanceof Resources))
throw new IOException("Not a Resources file");
Resources ret = (Resources)o;
ret.restore(f);
return ret;
}
catch(Exception e) {
throw new IOException(e.getMessage());
}
}<P> //write Resources object to file, using Externalizable or Serializable
public abstract void save(File f) throws IOException;<P> //the File you were saved to, grab any information you may need from it
public abstract void restore(File f);<P> public abstract void createCategory(String category) throws IOException;
public abstract void put(Resource r, String key) throws IOException;
public abstract Resource get(String key) throws IOException;
public abstract void remove(String key);
public abstract DefaultTreeModel getTreeModel();
}<P>public interface Resource extends Serializable {<P> public Component getEditor(ResourceNode node);<P>}<P>public class StringResource implements Resource {<P> protected String string;<P> public StringResource(String s) {
string = s;
}<P> public String getString() {
return string;
}<P> public void setString(String s) {
this.string = s;
}<P> public Component getEditor(ResourceNode node) {
return new StringResourceEditor(this, node);
}<P> public boolean equals(Object o) {
if(! (o instanceof StringResource))
return false;
StringResource s = (StringResource)o;
return s.string.equals(string);
}<P> public String toString() {
return "String resource: " + getString();
}<P>}