private class Sub extends JSCallable {
String key;
Sub(String key) { this.key = key; }
+ public String toString() { return "XWTSUB " + key; }
public void put(Object key, Object val) { XWT.this.put(this.key + "." + key, val); }
- public Object get(Object key) { return XWT.this.get(this.key + "." + key); }
+ public Object get(Object key) { return XWT.this._get(this.key + "." + key); }
public Object call(Object method, JSArray args) { return XWT.this.call(method == null ? key : this.key + "." + method, args); }
}
- public Object get(Object name) {
+ public Object _get(Object name) {
//#switch(name)
case "math": return xwtMath;
case "string": return xwtString;
case "date": return new JSDate();
case "origin": return Main.origin;
case "box": return new BoxTree();
+ case "log": return new Sub("log");
case "ui": return new Sub("ui");
+ case "thread": return new Sub("thread");
case "ui.key": return new Sub("ui.key");
case "ui.key.alt": return Surface.alt ? Boolean.TRUE : Boolean.FALSE;
case "ui.key.control": return Surface.control ? Boolean.TRUE : Boolean.FALSE;
case "fs.home": return System.getProperty("user.home");
case "fs.temp": return System.getProperty("java.io.tempdir");
case "ui.mouse": return new Sub("ui.mouse");
+ case "res": return new Sub("res");
case "ui.mouse.button":
if (Surface.button1 && !Surface.button2 && !Surface.button3) return new Integer(1);
else if (!Surface.button1 && Surface.button2 && !Surface.button3) return new Integer(2);
case "undocumented": return new Sub("undocumented");
case "undocumented.internal": return new Sub("undocumented.internal");
//#end
- return rr.get(name);
+ return null;
+ }
+
+ public Object get(Object name) {
+ Object ret = _get(name);
+ if (ret != null) return ret;
+ return !name.equals("clone") && !name.equals("apply") ? rr.get(name) : null;
}
public void put(Object name, final Object value) {
//#switch(name)
case "thread":
- Scheduler.add(new Scheduler.Task() { public void perform() { JSContext.invokePauseable((JSFunction)value); } });
+ System.out.println("new thread " + value);
+ Scheduler.add(new Scheduler.Task() {
+ public String toString() { return "thread task"; }
+ public void perform() { JSContext.invokePauseable((JSFunction)value); } });
case "ui.clipboard": Platform.setClipBoard((String)value);
case "ui.frame": Platform.createSurface((Box)value, true, true);
case "ui.window": Platform.createSurface((Box)value, false, true);
case "res.uncab": return new Res.Cab((Res)a);
case "res.cache": try { return new Res.CachedRes((Res)a, "resources", true); }
catch (Res.NotCacheableException e) { throw new JS.Exn("this resource cannot be cached"); }
- case "res.fromURL": return Res.fromString((String)a);
+ case "res.url":
+ String url = (String)a;
+ if (url.startsWith("http://")) return new Res.HTTP(url);
+ else if (url.startsWith("https://")) return new Res.HTTP(url);
+ else if (url.startsWith("data:")) return new Res.ByteArray(Base64.decode(url.substring(5)), null);
+ else if (url.startsWith("utf8:")) return new Res.ByteArray(url.substring(5).getBytes(), null);
+ throw new JS.Exn("invalid resource specifier " + url);
+
case "thread.sleep": sleep(JS.toInt(a)); return null;
case "log.println": Log.logJS(this, a== null ? "**null**" : a.toString()); return null;
case "log.dump": Log.recursiveLog("","",a); return null;
public static final JSMath xwtMath = new JSMath() {
private JS gs = new JSScope.Global(null);
+ public String toString() { return "XWTMATH"; }
public Object get(Object key) {
//#switch(key)
case "isNaN": return gs.get("isNaN");