X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2FXWT.java;h=ed8feb1541077b8a6f17ce625f7df77ca2227c4b;hb=e6a665b309c7103a3a29c2cd96b1073409c13606;hp=2f28e32399663e087f54bcf532621dcee3cf549f;hpb=345865827e473f64410c7e3c07e73d20a8db7c4f;p=org.ibex.core.git diff --git a/src/org/xwt/XWT.java b/src/org/xwt/XWT.java index 2f28e32..ed8feb1 100644 --- a/src/org/xwt/XWT.java +++ b/src/org/xwt/XWT.java @@ -18,9 +18,7 @@ public final class XWT extends JS.Obj { private static Hashtable safeFiles = new Hashtable(); public Object get(Object name) { - if (name.equals("parseFloat")) throw new Error("not implemented"); - else if (name.equals("parseInt")) throw new Error("not implemented"); - else if (name.equals("alt")) return Surface.alt ? Boolean.TRUE : Boolean.FALSE; + if (name.equals("alt")) return Surface.alt ? Boolean.TRUE : Boolean.FALSE; 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(); @@ -59,53 +57,65 @@ public final class XWT extends JS.Obj { put("tempDir", System.getProperty("java.io.tempdir")); put("math", new JS.Obj() { public Object get(Object name) { - if ("ceil".equals(name)) return new JS.Function() { public Object _call(JS.Array args) + 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() { public Object _call(JS.Array args) + 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() { public Object _call(JS.Array args) + 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() { public Object _call(JS.Array args) + 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() { public Object _call(JS.Array args) { + 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() { public Object _call(JS.Array args) { + 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() { public Object _call(JS.Array args) { + 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() { public Object _call(JS.Array args) { + 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() { public Object _call(JS.Array args) { + 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() { public Object _call(JS.Array args) { + 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() { public Object _call(JS.Array args) { + 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() { public Object _call(JS.Array args) { + 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() { public Object _call(JS.Array args) throws JS.Exn { + put("newBrowserWindow", new JS.Function(-1, "java", null, null) { public Object _call(JS.Array args) throws JS.Exn { if (args.length() != 1 || args.elementAt(0) == null) return null; Platform.newBrowserWindow(args.elementAt(0).toString()); return null; }}); - put("yield", new JS.Function() { public Object _call(JS.Array args) throws JS.Exn { + put("parseFloat", new JS.Function(-1, "java", null, null) { 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()); + }}); + + put("parseInt", new JS.Function(-1, "java", null, null) { 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()); + }}); + + put("yield", new JS.Function(-1, "java", null, null) { public Object _call(JS.Array args) throws JS.Exn { sleep(0); return null; }}); - put("theme", new JS.Function() { public Object _call(JS.Array args) throws JS.Exn { + put("theme", new JS.Function(-1, "java", null, null) { 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(); @@ -173,7 +183,7 @@ public final class XWT extends JS.Obj { else return new Integer(xwf.stringWidth(text)); }}); - put("textheight", new JS.Function() { public Object _call(JS.Array args) throws JS.Exn { + put("textheight", new JS.Function(-1, "java", null, null) { 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(); @@ -182,7 +192,7 @@ public final class XWT extends JS.Obj { else return new Integer(xwf.getMaxAscent() + xwf.getMaxDescent()); }}); - put("newBox", new JS.Function() { public Object _call(JS.Array args) throws JS.Exn { + put("newBox", new JS.Function(-1, "java", null, null) { 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.Function callback = null; for(int i=1; i 1 && args.elementAt(1) instanceof JS.Function ? (JS.Function)args.elementAt(1) : null);