2003/05/26 10:38:33
[org.ibex.core.git] / src / org / xwt / XWT.java
index dd6edc2..2f28e32 100644 (file)
@@ -79,6 +79,18 @@ public final class XWT extends JS.Obj {
                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) {
+               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) {
+               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) {
+               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) {
+               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) {
+               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) {
+               return new Double(Math.atan(((Number)args.elementAt(0)).doubleValue())); } };
            return null;
        }});
 
@@ -114,7 +126,7 @@ public final class XWT extends JS.Obj {
        put("println", new JS.Function() { public Object _call(JS.Array args) throws JS.Exn {
            if (args.length() != 1) return null;
            if (Log.on) Log.log(this, JS.getFileAndLine() + " " +
-                               (args.elementAt(0) == null ? "null" : args.elementAt(0).toString()));
+                               (args.elementAt(0) == null ? "**null**" : args.elementAt(0).toString()));
            return null;
        }});
 
@@ -137,11 +149,6 @@ public final class XWT extends JS.Obj {
            return ret;
        }});
 
-       put("theme", new JS.Function() { public Object _call(JS.Array args) throws JS.Exn {
-           Log.log(XWT.class, "xwt.theme() not implemented...");
-           return null;
-       }});
-
        put("xmlrpc", new JS.Function() { public Object _call(JS.Array args) throws JS.Exn {
            if (args.length() != 1 || args.elementAt(0) == null) return null;
            return new XMLRPC(args.elementAt(0).toString(), "");
@@ -272,65 +279,63 @@ public final class XWT extends JS.Obj {
     }});
 
     put("loadArchive", new JS.Function() { public Object _call(JS.Array args) throws JS.Exn {
-                if (!ThreadMessage.suspendThread()) return null;
-
-                try {
-                    if (args == null || args.length() < 1 || args.elementAt(0) == null) return null;
-                    URL u = new URL(args.elementAt(0).toString());
-                    
-                    JS.Function callback = null;
-                    if (args.length() == 2 && args.elementAt(1) != null && args.elementAt(1) instanceof JS.Function)
-                       callback = (JS.Function)args.elementAt(1);
-                    
-                    if (!u.getFile().endsWith(".xwar")) {
-                        if (Log.on) Log.log(this, "Error: archive names must end with .xwar: " + u.getFile());
-                        throw new JS.Exn("Error: archive names must end with .xwar: " + u.getFile());
-                    }
-                    
-                    if (u.getProtocol().equals("http")) {
-                        HTTP http = new HTTP(u.toString());
-                        if (Main.originAddr == null) {
-                            try {
-                                Main.originAddr = InetAddress.getByName(u.getHost());
-                            } catch (UnknownHostException e) {
-                                if (Log.on) Log.log(this, "couldn't resolve " + u.getHost() + "; proceeding without permissions");
-                                Main.originAddr = InetAddress.getByName("0.0.0.0");
-                            }
-                        } else {
-                            Main.originAddr = InetAddress.getByName("0.0.0.0");
-                        }
-                        HTTP.HTTPInputStream in = http.GET();
-                        Resources.loadArchive(in, in.getContentLength(), callback);
-
-                    } else if (u.getProtocol().equals("file")) {
-                        if (Main.originAddr != null) {
-                            if (Log.on) Log.log(this, "scripts downloaded from the network may not load xwars from the local filesystem");
-                            throw new JS.Exn("scripts downloaded from the network may not load xwars from the local filesystem");
-                        }
-                        Resources.loadArchive(new FileInputStream(u.getFile()), (int)new File(u.getFile()).length(), callback);
-                        
-                    } else {
-                        if (Log.on) Log.log(this, "unknown protocol \"" + u.getProtocol() + "\"");
-                        throw new JS.Exn("unknown protocol \"" + u.getProtocol() + "\"");
-                    }
-                    
-                } catch (MalformedURLException me) {
-                    if (Log.on) Log.log(this, "Malformed URL: " + args.elementAt(0));
-                    if (Log.on) Log.log(this, me);
-                    throw new JS.Exn(me.toString());
-                    
-                } catch (IOException ioe) {
-                    if (Log.on) Log.log(this, "IOException while loading archive:");
-                    if (Log.on) Log.log(this, ioe);
-                    throw new JS.Exn(ioe.toString());
-
-                } finally {
-                    ThreadMessage.resumeThread();
-
-                }
-                return null;
-            }
-        });
+       if (!ThreadMessage.suspendThread()) return null;
+       try {
+           if (args == null || args.length() < 1 || args.elementAt(0) == null) return null;
+           URL u = new URL(args.elementAt(0).toString());
+           
+           JS.Function callback = null;
+           if (args.length() == 2 && args.elementAt(1) != null && args.elementAt(1) instanceof JS.Function)
+               callback = (JS.Function)args.elementAt(1);
+           
+           if (!u.getFile().endsWith(".xwar")) {
+               if (Log.on) Log.log(this, "Error: archive names must end with .xwar: " + u.getFile());
+               throw new JS.Exn("Error: archive names must end with .xwar: " + u.getFile());
+           }
+           
+           if (u.getProtocol().equals("http")) {
+               HTTP http = new HTTP(u.toString());
+               if (Main.originAddr == null) {
+                   try {
+                       Main.originAddr = InetAddress.getByName(u.getHost());
+                   } catch (UnknownHostException e) {
+                       if (Log.on) Log.log(this, "couldn't resolve " + u.getHost() + "; proceeding without permissions");
+                       Main.originAddr = InetAddress.getByName("0.0.0.0");
+                   }
+               } else {
+                   Main.originAddr = InetAddress.getByName("0.0.0.0");
+               }
+               HTTP.HTTPInputStream in = http.GET();
+               Resources.loadArchive(in, in.getContentLength(), callback);
+               
+           } else if (u.getProtocol().equals("file")) {
+               if (Main.originAddr != null) {
+                   if (Log.on) Log.log(this, "scripts downloaded from the network may not load xwars from the local filesystem");
+                   throw new JS.Exn("scripts downloaded from the network may not load xwars from the local filesystem");
+               }
+               Resources.loadArchive(new FileInputStream(u.getFile()), (int)new File(u.getFile()).length(), callback);
+               
+           } else {
+               if (Log.on) Log.log(this, "unknown protocol \"" + u.getProtocol() + "\"");
+               throw new JS.Exn("unknown protocol \"" + u.getProtocol() + "\"");
+           }
+           
+       } catch (MalformedURLException me) {
+           if (Log.on) Log.log(this, "Malformed URL: " + args.elementAt(0));
+           if (Log.on) Log.log(this, me);
+           throw new JS.Exn(me.toString());
+           
+       } catch (IOException ioe) {
+           if (Log.on) Log.log(this, "IOException while loading archive:");
+           if (Log.on) Log.log(this, ioe);
+           throw new JS.Exn(ioe.toString());
+           
+       } finally {
+           ThreadMessage.resumeThread();
+           
+       }
+       return null;
+    }});
 
     put("prefetchImage", new JS.Function() { public Object _call(JS.Array args) throws JS.Exn {
        if (args == null || args.length() < 1 || args.elementAt(0) == null) return null;