- public static void main(String[] args) {
- try {
- int startargs = 0;
- while (true) {
- if (startargs > args.length - 1) {
- 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++;
- }
- final String instancename = args.length > startargs + 1 ? args[startargs + 1] : "main";
-
- Platform.forceLoad();
- if (Log.on) for(int i=0; i<args.length; i++) Log.log(Main.class, "argument " + i + ": " + args[i]);
-
- 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 (args[startargs].startsWith("http://")) {
- if (Log.on) Log.log(Main.class, "downloading xwar");
- origin = args[startargs];
- initialTemplate = "org.xwt.builtin.splash";
-
- } else {
- if (Log.on) Log.log(Main.class, "loading xwar from local filesystem");
-
- // HACK because MSIE turns \'s into /'s in URLs... argh!!
- if (Platform.platform.getClass().getName().endsWith("Win32"))
- args[startargs] = args[startargs].replace('/', '\\');
-
- File f = new File(args[startargs]);
- origin = "file:" + f.getAbsolutePath();
- if (f.isDirectory()) {
- Resources.loadDirectory(f);
- Surface.scarAllSurfacesFromNowOn = true;
- } else {
- initialTemplate = "org.xwt.builtin.splash";
- }
-
- if (args.length > startargs + 1) initialTemplate = args[startargs + 1];
- }
- }
-
- if (Log.on) Log.log(Main.class, "instantiating " + initialTemplate);
- final String initialTemplate_f = initialTemplate;
- ThreadMessage.newthread(new JS.Function(-1, "java", null, null) {
- public Object _call(JS.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();
- Platform.running();