X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2FXWT.java;h=6ea3c0e8a45927a9c8cece4983f85ab2b264e6e1;hb=9a33358173f08013fdacd02c11f3823352bdae23;hp=fb958e47b72dab0d7219d52cf9ecc89abe4b6456;hpb=6242c991f365dbd67eba62ecfa5df769a83fcbc6;p=org.ibex.core.git diff --git a/src/org/xwt/XWT.java b/src/org/xwt/XWT.java index fb958e4..6ea3c0e 100644 --- a/src/org/xwt/XWT.java +++ b/src/org/xwt/XWT.java @@ -12,6 +12,10 @@ import org.mozilla.javascript.*; public final class XWT extends JSObject { public static final XWT singleton = new XWT(); + + /** each key is a string representing a filename which the user has already given XWT permission to write to */ + private static Hashtable safeFiles = new Hashtable(); + public String getClassName() { return "XWT"; } private XWT() { setSeal(true); } @@ -28,15 +32,28 @@ public final class XWT extends JSObject { else if (name.equals("regexp")) return regexp; else if (name.equals("sleep")) return sleep; else if (name.equals("yield")) return yield; + else if (name.equals("newBrowserWindow")) return newBrowserWindow; else if (name.equals("textwidth")) return textwidth; else if (name.equals("textheight")) return textheight; else if (name.equals("newBox")) return newBox; else if (name.equals("soap")) return soap; else if (name.equals("xmlrpc")) return xmlrpc; + else if (name.equals("origin")) return Main.origin; else if (name.equals("clipboard")) return Platform.getClipBoard(); else if (name.equals("altKeyName")) return Platform.altKeyName(); + else if (name.equals("screenWidth")) return new Integer(Platform.getScreenWidth()); + else if (name.equals("screenHeight")) return new Integer(Platform.getScreenHeight()); else if (name.equals("static")) return Static.getStatic(""); else if (name.equals("theme")) return theme; + else if (name.equals("openFile")) return openFile; + else if (name.equals("saveFile")) return saveFile; + else if (name.equals("saveFileAs")) return saveFileAs; + else if (name.equals("utfEncode")) return utfEncode; + else if (name.equals("fileSeparator")) return File.separator; + else if (name.equals("homeDir")) return System.getProperty("user.home"); + else if (name.equals("tempDir")) return System.getProperty("java.io.tempdir"); + else if (name.equals("recursivePrintObject")) return recursivePrintObject; + else if (name.equals("parseHTML")) return parseHTML; else if (name.equals("button")) { if (Surface.button1 && !Surface.button2 && !Surface.button3) return new Integer(1); else if (!Surface.button1 && Surface.button2 && !Surface.button3) return new Integer(1); @@ -45,6 +62,8 @@ public final class XWT extends JSObject { } else if (name.equals("println")) return println; else if (name.equals("math")) return org.xwt.util.JSObject.defaultObjects.get("Math", null); + else if (name.equals("loadArchive")) return loadArchive; + else if (name.equals("prefetchImage")) return prefetchImage; else return super.get(name, start); } @@ -58,29 +77,34 @@ public final class XWT extends JSObject { // JSFunction Instances /////////////////////////////////////////////////////////////////// - /** Helper class for defining functions. */ - private static abstract class JSFunction extends JSObject implements Function { - JSFunction() { setSeal(true); } - public Scriptable construct(Context cx, Scriptable scope, java.lang.Object[] args) { return null; } - } + private static final JSObject.JSFunction newBrowserWindow = new JSObject.JSFunction() { + public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException { + if (args.length != 1 || args[0] == null) return null; + Platform.newBrowserWindow(args[0].toString()); + return null; + } + }; - private static final JSFunction yield = new JSFunction() { + public static final JSObject.JSFunction yield = new JSObject.JSFunction() { public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException { sleep.call(cx, null, null, null); return null; } }; - private static final JSFunction println = new JSFunction() { + private static final JSObject.JSFunction println = new JSObject.JSFunction() { public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException { if (args.length == 1) - if (Log.on) - Log.log(cx.interpreterSourceFile, args[0] == null ? "null" : args[0].toString()); + if (Log.on) { + String source = cx.interpreterSourceFile; + if (source.endsWith("._")) source = source.substring(0, source.length() - 2); + Log.log(source, args[0] == null ? "null" : args[0].toString()); + } return null; } }; - private static final JSFunction date = new JSFunction() { + private static final JSObject.JSFunction date = new JSObject.JSFunction() { public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException { try { return Context.enter().newObject(org.xwt.util.JSObject.defaultObjects, "Date", args); } catch (Exception e) { @@ -91,9 +115,9 @@ public final class XWT extends JSObject { } }; - private static final JSFunction regexp = new JSFunction() { + private static final JSObject.JSFunction regexp = new JSObject.JSFunction() { public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException { - try { return Context.enter().newObject(org.xwt.util.JSObject.defaultObjects, "Regexp", args); + try { return Context.enter().newObject(org.xwt.util.JSObject.defaultObjects, "RegExp", args); } catch (Exception e) { if (Log.on) Log.log(this, "Exception in Context.newObject() -- this should never happen"); if (Log.on) Log.log(this, e); @@ -102,13 +126,13 @@ public final class XWT extends JSObject { } }; - private static final JSFunction listfonts = new JSFunction() { + private static final JSObject.JSFunction listfonts = new JSObject.JSFunction() { public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException { return Context.enter().newArray(org.xwt.util.JSObject.defaultObjects, Platform.listFonts()); } }; - private static final JSFunction theme = new JSFunction() { + private static final JSObject.JSFunction theme = new JSObject.JSFunction() { public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException { if (args.length != 2) return null; if (args[0] == null || args[1] == null) return null; @@ -117,14 +141,14 @@ public final class XWT extends JSObject { } }; - private static final JSFunction xmlrpc = new JSFunction() { + private static final JSObject.JSFunction xmlrpc = new JSObject.JSFunction() { public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException { if (args.length != 1 || args[0] == null) return null; return new XMLRPC(args[0].toString(), ""); } }; - private static final JSFunction soap = new JSFunction() { + private static final JSObject.JSFunction soap = new JSObject.JSFunction() { public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException { if (args.length == 1 && args[0] != null) return new SOAP(args[0].toString(), "", null, null); else if (args.length == 2 && args[0] != null && args[1] != null) @@ -135,7 +159,7 @@ public final class XWT extends JSObject { } }; - private static final JSFunction textwidth = new JSFunction() { + private static final JSObject.JSFunction textwidth = new JSObject.JSFunction() { public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) throws JavaScriptException { if (args.length < 1 || args.length > 2) return null; if (args[0] == null || (args.length == 2 && args[1] == null)) return null; @@ -148,7 +172,7 @@ public final class XWT extends JSObject { }; - private static final JSFunction textheight = new JSFunction() { + private static final JSObject.JSFunction textheight = new JSObject.JSFunction() { public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException { if (args.length > 1) return null; if (args.length == 1 && args[0] == null) return null; @@ -159,23 +183,32 @@ public final class XWT extends JSObject { } }; - private static final JSFunction newBox = new JSFunction() { + private static final JSObject.JSFunction newBox = new JSObject.JSFunction() { public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException { - Box ret = new Box(args.length == 0 || args[0] == null ? "box" : args[0].toString(), Template.defaultImportList); + + Function callback = null; + for(int i=1; i"); + + } else if (o instanceof NativeArray) { + Log.log(cx.interpreterSourceFile, indent + name + ""); + NativeArray na = (NativeArray)o; + for(int i=0; i"); + Scriptable s = (Scriptable)o; + Object[] keys = s.getIds(); + for(int i=0; i 1 && args[1] instanceof Function ? (Function)args[1] : null); + return null; + } + }; + }