2003/05/08 13:38:40
[org.ibex.core.git] / src / org / xwt / Main.java
index 1cf9035..7713361 100644 (file)
@@ -8,6 +8,7 @@ import java.net.*;
 import java.util.*;
 import java.io.*;
 import java.awt.*;
+import org.mozilla.javascript.*;
 import org.bouncycastle.util.encoders.Base64;
 
 /** Entry point for the XWT Engine; handles splash screen, initial xwar loading, and argument processing */
@@ -34,6 +35,9 @@ public class Main extends Applet {
 
     public static Applet applet = null;
 
+    /** don't check if all surfaces are gone (and quit) until this is true */
+    public static boolean doneInitializing = false;
+
     /** applet entry point */
     public void init() {
         if ("true".equals(getParameter("showRenders"))) showRenders = true;
@@ -48,22 +52,24 @@ public class Main extends Applet {
             int startargs = 0;
             while (true) {
                 if (startargs > args.length - 1) {
-                    System.out.println("Usage: xwt [-s] [-v] source-location [initial-template]");
-                    System.out.println("");
-                    System.out.println("Options:");
-                    System.out.println("    -s show rendering activity with red rectangles");
-                    System.out.println("    -v verbose logging");
-                    System.out.println("");
-                    System.out.println("Source-location is one of the following:");
-                    System.out.println("    - the path to an xwar file");
-                    System.out.println("    - the path to a directory to be used as an xwar");
-                    System.out.println("    - the http url of an xwar");
-                    System.out.println("");
-                    System.out.println("Initial-template is the resource name of the template to load; defaults to 'main'");
+                    System.err.println("Usage: xwt [-s] [-v] [-l <port>/<url>] source-location [initial-template]");
+                    System.err.println("");
+                    System.err.println("Options:");
+                    System.err.println("    -s show rendering activity with red rectangles");
+                    System.err.println("    -v verbose logging");
+                    System.err.println("    -l serve logs via HTTP on 127.0.0.1:<port>/<url>");
+                    System.err.println("");
+                    System.err.println("Source-location is one of the following:");
+                    System.err.println("    - the path to an xwar file");
+                    System.err.println("    - the path to a directory to be used as an xwar");
+                    System.err.println("    - the http url of an xwar");
+                    System.err.println("");
+                    System.err.println("Initial-template is the resource name of the template to load; defaults to 'main'");
                     Runtime.getRuntime().exit(-1);
                 }
                 else if (args[startargs].equals("-s")) showRenders = true;
                 else if (args[startargs].equals("-v")) Log.verbose = true;
+                else if (args[startargs].equals("-l")) startargs++;          // FIXME
                 else break;
                 startargs++;
             }
@@ -77,7 +83,7 @@ public class Main extends Applet {
             PNG png = PNG.decode(new ByteArrayInputStream(Base64.decode(scarPicture_png_base64)), "bundled scar image");
             Surface.scarPicture = Platform.createPicture(png.getData(), png.getWidth(), png.getHeight());
 
-            InputStream is = Main.class.getClassLoader().getResourceAsStream("org/xwt/builtin.xwar");
+            InputStream is = Platform.getBuiltinInputStream();
             if (is == null) Platform.criticalAbort("unable to load builtin.xwar");
             Resources.loadArchive(is);
            
@@ -111,15 +117,22 @@ public class Main extends Applet {
             
             if (Log.on) Log.log(Main.class, "instantiating " + initialTemplate);
             final String initialTemplate_f = initialTemplate;
-            MessageQueue.add(new Message() {
-                    public void perform() {
+            ThreadMessage.newthread(new JSObject.JSFunction() {
+                    public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] arg) throws JavaScriptException {
                         new Box(initialTemplate_f, null);
+                       doneInitializing = true;
+            if (Surface.allSurfaces.size() == 0) {
+                Log.log(this, "exiting because all surfaces are gone");
+                Platform.exit();
+            }
+                        return null;
                     }
                 });
            
             // gcj-win32 exit()'s when the original thread dies, so we have to deadlock ourselves
-            if (Log.on) Log.log(Main.class, "main thread blocking on new semaphore");
-            new org.xwt.util.Semaphore().block();
+            //if (Log.on) Log.log(Main.class, "main thread blocking on new semaphore");
+            //new org.xwt.util.Semaphore().block();
+            Platform.running();
 
         } catch (Throwable e) {
             e.printStackTrace();