// Copyright 2002 Adam Megacz, see the COPYING file for licensing [GPL]
package org.xwt;
-import org.xwt.util.*;
-import java.lang.reflect.*;
import java.applet.*;
import java.net.*;
import java.util.*;
import java.io.*;
import java.awt.*;
import org.bouncycastle.util.encoders.Base64;
+import org.xwt.js.*;
+import org.xwt.util.*;
/** Entry point for the XWT Engine; handles splash screen, initial xwar loading, and argument processing */
-public class Main extends Applet {
+public class Main {
/**
* Used for security checks. If this is null, it means that only
/** true iff the user asked for rendered regions to be shown with a red rectangle */
public static boolean showRenders = false;
- public Main() { }
- public void paint(Graphics g) { } // do-nothing method to avoid repaints
- public void update(Graphics g) { } // do-nothing method, to avoid repaints
-
- public static Applet applet = null;
-
- /** applet entry point */
- public void init() {
- if ("true".equals(getParameter("showRenders"))) showRenders = true;
- if ("true".equals(getParameter("verbose"))) Log.verbose = true;
- applet = this;
- main(new String[] { getParameter("initial-xwar-url"), "main" });
- }
+ /** don't check if all surfaces are gone (and quit) until this is true */
+ public static boolean doneInitializing = false;
/** common entry point */
public static void main(String[] args) {
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++;
else break;
startargs++;
}
Platform.forceLoad();
if (Log.on) for(int i=0; i<args.length; i++) Log.log(Main.class, "argument " + i + ": " + args[i]);
- // we do this here instead of in a static initializer to avoid threading hazards
- if (Log.on) Log.log(Main.class, "loading scar image");
- 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);
+ if (Log.on) Log.log(Main.class, "loading scar image");
+ PNG png = PNG.decode(new ByteArrayInputStream(Resources.getResource("org.xwt.builtin.scar.png")), "bundled scar image");
+ Surface.scarPicture = Platform.createPicture(png.getData(), png.getWidth(), png.getHeight());
+
String initialTemplate = "main";
if (args.length > startargs) {
if (Log.on) Log.log(Main.class, "instantiating " + initialTemplate);
final String initialTemplate_f = initialTemplate;
- MessageQueue.add(new Message() {
- public void perform() {
+ ThreadMessage.newthread(new JS.Callable() {
+ public Object call(Array args) throws JS.Exn {
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();
}
}
- /** a base64-encoded png image of the scar */
- public static final String scarPicture_png_base64 =
- "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAA" +
- "CXBIWXMAAAsRAAALEQF/ZF+RAAAAB3RJTUUH0gIYAgsIkuS+AwAAA7lJREFUeJzF1l9MW1Uc" +
- "wPHvvb3lz/oHOssd0hXo+NNONow102xDSXzoJGiyGBIyDNMlJvjn0USNL74ZY3wnxOgeWIxo" +
- "9uAmZBrMiNkYYw5xRGBFQdiuzgtl/Gmht7S9PsBM162lGwN+yU3uPTf3nM895/c7OXwOfSKI" +
- "23Z1yDJt0Ms2hQhwARa3CyHeudkuhJj4sB0IMblhqxH3ALYacV/AViJSArYKkRawFYh1AZuN" +
- "yAiwmQgpzTsBMMzVv14V00PWQGDhJpd/UNugdwBebIOFRwFINwOGwJHXPH/d9BdYrbXZpaV1" +
- "ZUPeZ8RuiHnhXAvYNxMghEEMaXO79rjqyLeV6c5iD01Nrz4bevnYwYFVxJkWsG4WQM+B+I6e" +
- "7/q0SH98srXuYufpk2NGo8Tx5jcF6/unDwyA5oVzmwUAiBlhReg622eG6L7xDuWbjp+iJSVO" +
- "Kisfl2Z8p8QLENxoYqatgjzQAeFy4QvOs0ZX5bGmeunvWxK//jaNQQpLsPHqSJkDgKT6GrxD" +
- "xZ6DkimrzFffUFS020dX50B8efaPyeyuN5ZZBW4IkQogqb6Gp0b9IxZJcmKzubCYvfT0KAjx" +
- "ES3r1LtTQDzxg4dFiA5V/UCRZUtio+p7xTtyfdgqiEXIBW5cew6xv/p5ap8zBVbi8ez5hg9d" +
- "O8DA6kxtCCG2w8/JiPngrMUgObE/VoHDeYAn9taytBxDRw+/VH9YlHJFR7Dxo4o1xF3xoAiD" +
- "AMI1mKwJhcYUWa63hkKRyXx7saZliU9WH8XjqSUciWHLs3HrX6x2e9a0212yqEXthWGPNzdy" +
- "9cdZkpZjCiLvwNvfwxcZAQASEe6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