getSkin() implements cached skin creation

This commit is contained in:
hns 2001-01-18 18:11:34 +00:00
parent 335931bddb
commit f49b5eb157

View file

@ -554,14 +554,22 @@ public class HopExtension {
} }
/** /**
* Get a parsed Skin from the central skin repository * Get a parsed Skin from the central skin cache if possible, otherwise create it
*/ */
class GlobalGetSkin extends BuiltinFunctionObject { class GlobalGetSkin extends BuiltinFunctionObject {
GlobalGetSkin (String name, Evaluator evaluator, FunctionPrototype fp) { GlobalGetSkin (String name, Evaluator evaluator, FunctionPrototype fp) {
super (fp, evaluator, name, 1); super (fp, evaluator, name, 1);
} }
public ESValue callFunction (ESObject thisObject, ESValue[] arguments) throws EcmaScriptException { public ESValue callFunction (ESObject thisObject, ESValue[] arguments) throws EcmaScriptException {
throw new EcmaScriptException ("getSkin() is not implemented yet, use createSkin() instead"); if (arguments.length != 1 || ESNull.theNull.equals (arguments[0]))
throw new EcmaScriptException ("getSkin must be called with one String argument!");
String str = arguments[0].toString ();
Skin skin = (Skin) app.skincache.get (str);
if (skin == null) {
skin = new Skin (str);
app.skincache.put (str, skin);
}
return new ESWrapper (skin, evaluator);
} }
} }
@ -574,7 +582,7 @@ public class HopExtension {
} }
public ESValue callFunction (ESObject thisObject, ESValue[] arguments) throws EcmaScriptException { public ESValue callFunction (ESObject thisObject, ESValue[] arguments) throws EcmaScriptException {
if (arguments.length != 1 || ESNull.theNull.equals (arguments[0])) if (arguments.length != 1 || ESNull.theNull.equals (arguments[0]))
throw new EcmaScriptException ("getSkin must be called with one String argument!"); throw new EcmaScriptException ("createSkin must be called with one String argument!");
return new ESWrapper (new Skin (arguments[0].toString()), evaluator); return new ESWrapper (new Skin (arguments[0].toString()), evaluator);
} }
} }