2002/09/02 18:38:20
[org.ibex.core.git] / src / org / xwt / Main.java
index d22e436..294fd9e 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;
@@ -77,7 +81,9 @@ 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());
 
-            Resources.loadArchive(Main.class.getClassLoader().getResourceAsStream("org/xwt/builtin.xwar"));
+            InputStream is = Main.class.getClassLoader().getResourceAsStream("org/xwt/builtin.xwar");
+            if (is == null) Platform.criticalAbort("unable to load builtin.xwar");
+            Resources.loadArchive(is);
            
             String initialTemplate = "main";
 
@@ -98,6 +104,7 @@ public class Main extends Applet {
                     origin = "file:" + f.getAbsolutePath();
                     if (f.isDirectory()) {
                         Resources.loadDirectory(f);
+                        Surface.scarAllSurfacesFromNowOn = true;
                     } else {
                         initialTemplate = "org.xwt.builtin.splash";
                     }
@@ -108,9 +115,15 @@ 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;
                     }
                 });