X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2FXWT.java;h=f20cf26cb8637f6e193cac04f01da25ce29c5ded;hb=d5f0e6ca91a3359b09352d3df367d6b6bd22f096;hp=ed8feb1541077b8a6f17ce625f7df77ca2227c4b;hpb=e6a665b309c7103a3a29c2cd96b1073409c13606;p=org.ibex.core.git diff --git a/src/org/xwt/XWT.java b/src/org/xwt/XWT.java index ed8feb1..f20cf26 100644 --- a/src/org/xwt/XWT.java +++ b/src/org/xwt/XWT.java @@ -37,7 +37,7 @@ public final class XWT extends JS.Obj { } public void put(Object name, Object value) { - if (name.equals("thread") && value != null && value instanceof JS.Function) ThreadMessage.newthread((JS.Function)value); + if (name.equals("thread") && value != null && value instanceof JS.Callable) ThreadMessage.newthread((JS.Callable)value); else if (name.equals("clipboard")) Platform.setClipBoard(value.toString()); else if (name.equals("proxyAuthorization")) { // FIXME: undocumented, possibly insecure @@ -55,67 +55,30 @@ public final class XWT extends JS.Obj { put("fileSeparator", File.separator); put("homeDir", System.getProperty("user.home")); put("tempDir", System.getProperty("java.io.tempdir")); + put("math", org.xwt.js.Math.singleton); - put("math", new JS.Obj() { public Object get(Object name) { - if ("ceil".equals(name)) return new JS.Function(-1, "java", null, null) { public Object _call(JS.Array args) - { if (args.elementAt(0) == null) return null; - return new Long((long)Math.ceil(Double.parseDouble(args.elementAt(0).toString()))); } }; - else if ("floor".equals(name)) return new JS.Function(-1, "java", null, null) { public Object _call(JS.Array args) - { if (args.elementAt(0) == null) return null; - return new Long((long)Math.floor(Double.parseDouble(args.elementAt(0).toString()))); } }; - else if ("round".equals(name)) return new JS.Function(-1, "java", null, null) { public Object _call(JS.Array args) - { if (args.elementAt(0) == null) return null; - return new Long((long)Math.round(Double.parseDouble(args.elementAt(0).toString()))); } }; - else if ("abs".equals(name)) return new JS.Function(-1, "java", null, null) { public Object _call(JS.Array args) - { if (args.elementAt(0) == null) return null; - return new Long((long)Math.abs(Double.parseDouble(args.elementAt(0).toString()))); } }; - else if ("min".equals(name)) return new JS.Function(-1, "java", null, null) { public Object _call(JS.Array args) { - if (args.length() < 2 || args.elementAt(0) == null || args.elementAt(1) == null) return args.elementAt(0); - return new Double(Math.min(((Number)args.elementAt(0)).doubleValue(), - ((Number)args.elementAt(1)).doubleValue())); } }; - else if ("max".equals(name)) return new JS.Function(-1, "java", null, null) { public Object _call(JS.Array args) { - if (args.length() < 2) return args.elementAt(0); - return new Double(Math.max(((Number)args.elementAt(0)).doubleValue(), - ((Number)args.elementAt(1)).doubleValue())); } }; - else if ("cos".equals(name)) return new JS.Function(-1, "java", null, null) { public Object _call(JS.Array args) { - return new Double(Math.cos(((Number)args.elementAt(0)).doubleValue())); } }; - else if ("sin".equals(name)) return new JS.Function(-1, "java", null, null) { public Object _call(JS.Array args) { - return new Double(Math.sin(((Number)args.elementAt(0)).doubleValue())); } }; - else if ("tan".equals(name)) return new JS.Function(-1, "java", null, null) { public Object _call(JS.Array args) { - return new Double(Math.tan(((Number)args.elementAt(0)).doubleValue())); } }; - else if ("acos".equals(name)) return new JS.Function(-1, "java", null, null) { public Object _call(JS.Array args) { - return new Double(Math.acos(((Number)args.elementAt(0)).doubleValue())); } }; - else if ("asin".equals(name)) return new JS.Function(-1, "java", null, null) { public Object _call(JS.Array args) { - return new Double(Math.asin(((Number)args.elementAt(0)).doubleValue())); } }; - else if ("atan".equals(name)) return new JS.Function(-1, "java", null, null) { public Object _call(JS.Array args) { - return new Double(Math.atan(((Number)args.elementAt(0)).doubleValue())); } }; - else if ("sqrt".equals(name)) return new JS.Function(-1, "java", null, null) { public Object _call(JS.Array args) { - return new Double(Math.sqrt(((Number)args.elementAt(0)).doubleValue())); } }; - return null; - }}); - - put("newBrowserWindow", new JS.Function(-1, "java", null, null) { public Object _call(JS.Array args) throws JS.Exn { + put("newBrowserWindow", new JS.Callable() { public Object call(Array args) throws JS.Exn { if (args.length() != 1 || args.elementAt(0) == null) return null; Platform.newBrowserWindow(args.elementAt(0).toString()); return null; }}); - put("parseFloat", new JS.Function(-1, "java", null, null) { public Object _call(JS.Array args) throws JS.Exn { + put("parseFloat", new JS.Callable() { public Object call(Array args) throws JS.Exn { if (args.length() != 1 || args.elementAt(0) == null) return null; return new Float(args.elementAt(0).toString()); }}); - put("parseInt", new JS.Function(-1, "java", null, null) { public Object _call(JS.Array args) throws JS.Exn { + put("parseInt", new JS.Callable() { public Object call(Array args) throws JS.Exn { if (args.length() != 1 || args.elementAt(0) == null) return null; return new Float(args.elementAt(0).toString()); }}); - put("yield", new JS.Function(-1, "java", null, null) { public Object _call(JS.Array args) throws JS.Exn { + put("yield", new JS.Callable() { public Object call(Array args) throws JS.Exn { sleep(0); return null; }}); - put("theme", new JS.Function(-1, "java", null, null) { public Object _call(JS.Array args) throws JS.Exn { + put("theme", new JS.Callable() { public Object call(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(); @@ -183,7 +146,7 @@ public final class XWT extends JS.Obj { else return new Integer(xwf.stringWidth(text)); }}); - put("textheight", new JS.Function(-1, "java", null, null) { public Object _call(JS.Array args) throws JS.Exn { + put("textheight", new JS.Callable() { public Object call(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(); @@ -192,19 +155,19 @@ public final class XWT extends JS.Obj { else return new Integer(xwf.getMaxAscent() + xwf.getMaxDescent()); }}); - put("newBox", new JS.Function(-1, "java", null, null) { public Object _call(JS.Array args) throws JS.Exn { + put("newBox", new JS.Callable() { public Object call(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.Function callback = null; + JS.Callable callback = null; for(int i=1; i 1 && args.elementAt(1) instanceof JS.Function ? (JS.Function)args.elementAt(1) : null); + args.length() > 1 && args.elementAt(1) instanceof JS.Callable ? (JS.Callable)args.elementAt(1) : null); return null; }}); } @@ -359,16 +322,16 @@ public final class XWT extends JS.Obj { if (!name.equals("")) name += " : "; if (o == null) { - Log.log(JS.getCurrentFunction().getSourceName(), indent + name + ""); + Log.log(Context.getCurrentSourceNameAndLine() , indent + name + ""); - } else if (o instanceof JS.Array) { - Log.log(JS.getCurrentFunction().getSourceName(), indent + name + ""); - JS.Array na = (JS.Array)o; + } else if (o instanceof Array) { + Log.log(Context.getCurrentSourceNameAndLine() , indent + name + ""); + Array na = (Array)o; for(int i=0; i"); + Log.log(Context.getCurrentSourceNameAndLine() , indent + name + ""); JS s = (JS)o; Object[] keys = s.keys(); for(int i=0; i