X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2FXWT.java;h=0c01e67cd0e2654c67562472695664a3a8b813e7;hb=4444c6057bb0cee5d2ae5a55b3045fd8eb790295;hp=99b158ff5bdac753bc6364dd05add44cc8d44891;hpb=214fe5c02d3f0fb9c3c61128a100e6a3cb01668e;p=org.ibex.core.git diff --git a/src/org/xwt/XWT.java b/src/org/xwt/XWT.java index 99b158f..0c01e67 100644 --- a/src/org/xwt/XWT.java +++ b/src/org/xwt/XWT.java @@ -19,12 +19,8 @@ public final class XWT extends JS.Obj { private final JS xwtMath = new XWTMath(); private final JS xwtString = new XWTString(); - /** 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 Object get(Object name) { if (name.equals("alt")) return Surface.alt ? Boolean.TRUE : Boolean.FALSE; - else if (name.equals("rr")) return rr; else if (name.equals("box")) return new Box(); else if (name.equals("control")) return Surface.control ? Boolean.TRUE : Boolean.FALSE; else if (name.equals("shift")) return Surface.shift ? Boolean.TRUE : Boolean.FALSE; @@ -39,21 +35,19 @@ public final class XWT extends JS.Obj { 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 if (!Surface.button1 && Surface.button2 && !Surface.button3) return new Integer(2); + else if (!Surface.button1 && !Surface.button2 && Surface.button3) return new Integer(3); else return new Integer(0); } else return rr.get(name); } - public void put(Object name, final Object value) { - if (name.equals("thread") && value != null && (value instanceof JS.Callable || value instanceof JS.CompiledFunction)) { + public Object put(Object name, final Object value) { + if (name.equals("thread") && value != null && (value instanceof JS.Callable || value instanceof Function)) { Scheduler.add(new Scheduler.Task() { public void perform() { - new JS.Thread((CompiledFunction)value).resume(); + new JS.Context((Function)value, null).resume(); } }); } else if (name.equals("clipboard")) Platform.setClipBoard(value.toString()); else if (name.equals("frame")) Platform.createSurface((Box)value, true, true); @@ -61,7 +55,8 @@ public final class XWT extends JS.Obj { else if (name.equals("proxyAuthorization")) { HTTP.Proxy.Authorization.authorization = value.toString(); HTTP.Proxy.Authorization.waitingForUser.release(); - } else super.put(name, value); + } else return super.put(name, value); + return null; } public Object callMethod(Object method, JS.Array args, boolean checkOnly) { @@ -89,14 +84,17 @@ public final class XWT extends JS.Obj { if (checkOnly) return Boolean.TRUE; return new Res.Zip((Res)args.elementAt(0)); + } else if (method.equals("uncab")) { + if (checkOnly) return Boolean.TRUE; + return new Res.Cab((Res)args.elementAt(0)); + } else if (method.equals("watchProgress")) { if (checkOnly) return Boolean.TRUE; - return new Res.ProgressWatcher((Res)args.elementAt(0), (JS.CompiledFunction)args.elementAt(1)); + return new Res.ProgressWatcher((Res)args.elementAt(0), (Function)args.elementAt(1)); } else if (method.equals("yield")) { if (checkOnly) return Boolean.TRUE; - sleep(0); - return null; + return sleep(0); } else if (method.equals("load")) { if (checkOnly) return Boolean.TRUE; @@ -141,44 +139,7 @@ public final class XWT extends JS.Obj { if (checkOnly) return Boolean.TRUE; if (args != null && (args.length() != 1 || args.elementAt(0) == null)) return null; int i = args == null ? 0 : Box.stoi(args.elementAt(0).toString()); - sleep(i); - return null; - - } else if (method.equals("openFile")) { - if (checkOnly) return Boolean.TRUE; - if (args.length() != 1) return null; - String file = Platform.fileDialog(args.elementAt(0).toString(), false); - return file == null ? null : new Res.File(file); - - } else if (method.equals("saveFile") || method.equals("saveFileAs")) { - if (checkOnly) return Boolean.TRUE; - if (args.length() != 2) return null; - if (!(args.elementAt(1) instanceof Res)) return null; - String file = args.elementAt(0).toString(); - if (method.equals("saveFileAs") || - safeFiles.get(Platform.isCaseSensitive() ? file : file.toLowerCase()) == null) { - file = Platform.fileDialog(file, true); - // FIXME: throw exception here - if (file == null) return null; - safeFiles.put(Platform.isCaseSensitive() ? file : file.toLowerCase(), new Object()); - } - try { - InputStream is = ((Res)args.elementAt(1)).getInputStream(); - FileOutputStream out = new FileOutputStream(file); - byte[] buffer = new byte[1024 * 16]; - while(true) { - int numread = is.read(buffer, 0, buffer.length); - if (numread == -1) break; - out.write(buffer, 0, numread); - } - is.close(); - out.close(); - return null; - } catch (IOException e) { - if (Log.on) Log.log(XWT.class, "IO Exception while writing a ByteStream to a file"); - if (Log.on) Log.log(XWT.class, e); - throw new JS.Exn("error while writing a Resource to a file"); - } + return sleep(i); } else if (method.equals("parseHTML")) { if (checkOnly) return Boolean.TRUE; @@ -234,15 +195,16 @@ public final class XWT extends JS.Obj { } } - public static void sleep(final int i) { - final JS.Thread jsthread = JS.Thread.current(); + public static Object sleep(final int i) { + final JS.Context jsthread = JS.Context.current(); final long currentTime = System.currentTimeMillis(); final Scheduler.Task task = new Scheduler.Task() { public void perform() { + // FIXME: don't busy-wait if (System.currentTimeMillis() - currentTime < i) Scheduler.add(this); else jsthread.resume(); } }; - jsthread.pause(); Scheduler.add(task); + return JS.Context.pause; } private static class XWTMath extends org.xwt.js.Math { @@ -256,7 +218,7 @@ public final class XWT extends JS.Obj { } public Object get(Object key) { Object ret = super.get(key); - if(ret == null) ret = JS.Math.get(key); + if(ret == null) ret = org.xwt.js.Math.singleton.get(key); return ret; } }