X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2FXWT.java;h=f3368c4dee0bb0e18b0461871e81f29115418802;hb=a81a151e639664cb340cf3726f9e8b9c77d125fb;hp=8c9debbbda3eca5553f8014b3fef91ce2681af8a;hpb=e8442c40f5b8c03a4e6993cbcc9ce64dddab6a90;p=org.ibex.core.git diff --git a/src/org/xwt/XWT.java b/src/org/xwt/XWT.java index 8c9debb..f3368c4 100644 --- a/src/org/xwt/XWT.java +++ b/src/org/xwt/XWT.java @@ -1,4 +1,4 @@ -// Copyright 2002 Adam Megacz, see the COPYING file for licensing [GPL] +// Copyright 2003 Adam Megacz, see the COPYING file for licensing [GPL] package org.xwt; import java.io.*; @@ -7,11 +7,14 @@ import java.text.*; import java.util.*; import org.xwt.js.*; import org.xwt.util.*; +import org.xwt.translators.*; import org.bouncycastle.util.encoders.Base64; /** Singleton class that provides all functionality in the xwt.* namespace */ public final class XWT extends JS.Obj { + public Res resourceRoot = null; + public static final XWT singleton = new XWT(); private final JS xwtMath = new XWTMath(); private final JS xwtString = new XWTString(); @@ -24,17 +27,27 @@ public final class XWT extends JS.Obj { else if (name.equals("control")) return Surface.control ? Boolean.TRUE : Boolean.FALSE; else if (name.equals("shift")) return Surface.shift ? Boolean.TRUE : Boolean.FALSE; else if (name.equals("clipboard")) return Platform.getClipBoard(); - else if (name.equals("static")) return Static.getStatic(""); + /* FIXME + else if (name.equals("static")) return .getStatic(""); + */ + else if (name.equals("origin")) return Main.origin; + else if (name.equals("maxdim")) return new Integer(Short.MAX_VALUE); + 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("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("math")) return xwtMath; + else if (name.equals("string")) return xwtString; + else if (name.equals("parseInt")) return xwtString.get("parseInt"); + else if (name.equals("parseFloat")) return xwtString.get("parseFloat"); 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); else if (!Surface.button1 && !Surface.button2 && Surface.button3) return new Integer(1); else return new Integer(0); } - else if (name.equals("encodeURI")) throw new Error("not implemented"); - else if (name.equals("encodeURIComponent")) throw new Error("not implemented"); - else if (name.equals("decodeURI")) throw new Error("not implemented"); - else if (name.equals("decodeURIComponent")) throw new Error("not implemented"); else return super.get(name); } @@ -43,152 +56,82 @@ public final class XWT extends JS.Obj { else if (name.equals("clipboard")) Platform.setClipBoard(value.toString()); else if (name.equals("proxyAuthorization")) { // FIXME: undocumented, possibly insecure - Proxy.Authorization.authorization = value.toString(); - Proxy.Authorization.waitingForUser.release(); + HTTP.Proxy.Authorization.authorization = value.toString(); + HTTP.Proxy.Authorization.waitingForUser.release(); } else super.put(name, value); } - private XWT() { - super.put("maxdim", new Integer(Short.MAX_VALUE)); - super.put("origin", Main.origin); - super.put("altKeyName", Platform.altKeyName()); - super.put("screenWidth", new Integer(Platform.getScreenWidth())); - super.put("screenHeight", new Integer(Platform.getScreenHeight())); - super.put("fileSeparator", File.separator); - super.put("homeDir", System.getProperty("user.home")); - super.put("tempDir", System.getProperty("java.io.tempdir")); - super.put("math", xwtMath); - super.put("string", xwtString); + public Object callMethod(Object method, JS.Array args, boolean checkOnly) { - super.put("newBrowserWindow", new JS.Callable() { public Object call(JS.Array args) throws JS.Exn { + if (method.equals("newBrowserWindow")) { + if (checkOnly) return Boolean.TRUE; if (args.length() != 1 || args.elementAt(0) == null) return null; Platform.newBrowserWindow(args.elementAt(0).toString()); return null; - }}); - - super.put("parseFloat", new JS.Callable() { public Object call(JS.Array args) throws JS.Exn { - if (args.length() != 1 || args.elementAt(0) == null) return null; - return new Float(args.elementAt(0).toString()); - }}); - - super.put("parseInt", new JS.Callable() { public Object call(JS.Array args) throws JS.Exn { - if (args.length() != 1 || args.elementAt(0) == null) return null; - return new Float(args.elementAt(0).toString()); - }}); - super.put("yield", new JS.Callable() { public Object call(JS.Array args) throws JS.Exn { + } else if (method.equals("yield")) { + if (checkOnly) return Boolean.TRUE; sleep(0); return null; - }}); - super.put("theme", new JS.Callable() { public Object call(JS.Array args) throws JS.Exn { - if (args.length() != 2) return null; - if (args.elementAt(0) == null || args.elementAt(1) == null) return null; - for(int i=1; i 2) return null; - if (args.elementAt(0) == null || (args.length() == 2 && args.elementAt(1) == null)) return null; - String font = args.length() == 1 ? Platform.getDefaultFont() : args.elementAt(0).toString(); - String text = args.length() == 1 ? args.elementAt(0).toString() : args.elementAt(1).toString(); - XWF xwf = XWF.getXWF(font); - if (xwf == null) return new Integer(Platform.stringWidth(font, text)); - else return new Integer(xwf.stringWidth(text)); - }}); - super.put("textheight", new JS.Callable() { public Object call(JS.Array args) throws JS.Exn { - if (args.length() > 1) return null; - if (args.length() == 1 && args.elementAt(0) == null) return null; - String font = args.length() == 0 || args.elementAt(0) == null ? Platform.getDefaultFont() : args.elementAt(0).toString(); - XWF xwf = XWF.getXWF(font); - if (xwf == null) return new Integer(Platform.getMaxAscent(font) + Platform.getMaxDescent(font)); - else return new Integer(xwf.getMaxAscent() + xwf.getMaxDescent()); - }}); - - super.put("newBox", new JS.Callable() { public Object call(JS.Array args) throws JS.Exn { - if (args.length() > 0) Log.log(XWT.class, "DEPRECATED: xwt.newBox() with multiple arguments is deprecated; use xwt.newBox().apply()"); - JS.Callable callback = null; - for(int i=1; i 1 && args.elementAt(1) instanceof JS.Callable ? (JS.Callable)args.elementAt(1) : null); - return null; - }}); } private static void recurse(String indent, String name, Object o) { @@ -345,7 +223,6 @@ public final class XWT extends JS.Obj { } } - public static void sleep(int i) { java.lang.Thread thread = java.lang.Thread.currentThread(); if (!(thread instanceof ThreadMessage)) { @@ -354,7 +231,7 @@ public final class XWT extends JS.Obj { ThreadMessage mythread = (ThreadMessage)thread; mythread.done.release(); if (i > 0) try { java.lang.Thread.sleep(i); } catch (Exception e) { } - MessageQueue.add(mythread); + Message.Q.add(mythread); mythread.go.block(); } } @@ -383,6 +260,9 @@ public final class XWT extends JS.Obj { put("decodeURIComponent",gs.get("decodeURIComponent")); put("encodeURI",gs.get("encodeURI")); put("encodeURIComponent",gs.get("encodeURIComponent")); + put("escape",gs.get("escape")); + put("unescape",gs.get("unescape")); + put("fromCharCode",gs.get("stringFromCharCode")); setSeal(true); } }