2003/09/24 07:33:32
authormegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:36:14 +0000 (07:36 +0000)
committermegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:36:14 +0000 (07:36 +0000)
darcs-hash:20040130073614-2ba56-e37e59fe20ff2db5cc28fe75aff03e818a4f88d9.gz

19 files changed:
Makefile
src/edu/stanford/ejalbert/BrowserLauncher.java [new file with mode: 0644]
src/org/xwt/Box.java.pp
src/org/xwt/HTTP.java
src/org/xwt/Message.java
src/org/xwt/Platform.java
src/org/xwt/Res.java
src/org/xwt/SOAP.java
src/org/xwt/Surface.java
src/org/xwt/Template.java
src/org/xwt/Trap.java
src/org/xwt/XMLRPC.java
src/org/xwt/XWT.java
src/org/xwt/js/ArrayImpl.java
src/org/xwt/js/CompiledFunctionImpl.java
src/org/xwt/js/Date.java
src/org/xwt/js/JS.java
src/org/xwt/js/Regexp.java
src/org/xwt/plat/AWT.java

index d3a6b13..e38b4c2 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -68,16 +68,18 @@ build/class/%.class: build/java/%.java .jikes
        mkdir -p build/class
        ./.jikes $<
 
        mkdir -p build/class
        ./.jikes $<
 
+# this forces a clean build every time because jikes is so damn buggy
 compile: .compile
 compile: .compile
-.compile: $(all_java_sources)
+.compile: $(all_java_sources) .jikes
        @echo -e "\n\033[1mcompiling          .java -> .class: src/**/*.java\033[0m"
        @echo -e "\n\033[1mcompiling          .java -> .class: src/**/*.java\033[0m"
+       rm -rf build/class
        mkdir -p build/class
        mkdir -p build/class
-       @./.jikes $^
+       @./.jikes $(all_java_sources)
        touch .compile
 
 # PHASE 4: gcj-generated headers
 java_headers          := $(all_java_sources:build/java/%.java=build/h/%.h) 
        touch .compile
 
 # PHASE 4: gcj-generated headers
 java_headers          := $(all_java_sources:build/java/%.java=build/h/%.h) 
-build/h/%.h: build/class/%.class
+build/h/%.h: .compile
        @echo -e "\n\033[1mextracting        .class -> .h:     $<\033[0m"
        mkdir -p `dirname $@`
        ls `echo $< | sed s/.class\$$//`*.class |\
        @echo -e "\n\033[1mextracting        .class -> .h:     $<\033[0m"
        mkdir -p `dirname $@`
        ls `echo $< | sed s/.class\$$//`*.class |\
@@ -151,7 +153,7 @@ build/$(platform)/builtin.o: build/res/builtin.jar
 # having the individual .o's depend on the .java's (otherwise every .o gets recompiled when one .java changes)
 gcj: .vendor .install_gcc-3.3_$(target) $(target_bin)
 
 # having the individual .o's depend on the .java's (otherwise every .o gets recompiled when one .java changes)
 gcj: .vendor .install_gcc-3.3_$(target) $(target_bin)
 
-build/JVM/xwt.jar: $(java_sources:build/java/%.java=build/class/%.class) build/res/builtin.jar
+build/JVM/xwt.jar: .compile build/res/builtin.jar
        @echo -e "\n\033[1marchiving         .class -> .jar:   build/JVM/xwt.jar\033[0m"
        mkdir -p build/JVM
        echo -e "Manifest-Version: 1.0\nMain-Class: org.xwt.Main\n" > build/JVM/.manifest
        @echo -e "\n\033[1marchiving         .class -> .jar:   build/JVM/xwt.jar\033[0m"
        mkdir -p build/JVM
        echo -e "Manifest-Version: 1.0\nMain-Class: org.xwt.Main\n" > build/JVM/.manifest
diff --git a/src/edu/stanford/ejalbert/BrowserLauncher.java b/src/edu/stanford/ejalbert/BrowserLauncher.java
new file mode 100644 (file)
index 0000000..0e2b856
--- /dev/null
@@ -0,0 +1,584 @@
+package edu.stanford.ejalbert;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+/**
+ * BrowserLauncher is a class that provides one static method, openURL, which opens the default
+ * web browser for the current user of the system to the given URL.  It may support other
+ * protocols depending on the system -- mailto, ftp, etc. -- but that has not been rigorously
+ * tested and is not guaranteed to work.
+ * <p>
+ * Yes, this is platform-specific code, and yes, it may rely on classes on certain platforms
+ * that are not part of the standard JDK.  What we're trying to do, though, is to take something
+ * that's frequently desirable but inherently platform-specific -- opening a default browser --
+ * and allow programmers (you, for example) to do so without worrying about dropping into native
+ * code or doing anything else similarly evil.
+ * <p>
+ * Anyway, this code is completely in Java and will run on all JDK 1.1-compliant systems without
+ * modification or a need for additional libraries.  All classes that are required on certain
+ * platforms to allow this to run are dynamically loaded at runtime via reflection and, if not
+ * found, will not cause this to do anything other than returning an error when opening the
+ * browser.
+ * <p>
+ * There are certain system requirements for this class, as it's running through Runtime.exec(),
+ * which is Java's way of making a native system call.  Currently, this requires that a Macintosh
+ * have a Finder which supports the GURL event, which is true for Mac OS 8.0 and 8.1 systems that
+ * have the Internet Scripting AppleScript dictionary installed in the Scripting Additions folder
+ * in the Extensions folder (which is installed by default as far as I know under Mac OS 8.0 and
+ * 8.1), and for all Mac OS 8.5 and later systems.  On Windows, it only runs under Win32 systems
+ * (Windows 95, 98, and NT 4.0, as well as later versions of all).  On other systems, this drops
+ * back from the inherently platform-sensitive concept of a default browser and simply attempts
+ * to launch Netscape via a shell command.
+ * <p>
+ * This code is Copyright 1999-2001 by Eric Albert (ejalbert@cs.stanford.edu) and may be
+ * redistributed or modified in any form without restrictions as long as the portion of this
+ * comment from this paragraph through the end of the comment is not removed.  The author
+ * requests that he be notified of any application, applet, or other binary that makes use of
+ * this code, but that's more out of curiosity than anything and is not required.  This software
+ * includes no warranty.  The author is not repsonsible for any loss of data or functionality
+ * or any adverse or unexpected effects of using this software.
+ * <p>
+ * Credits:
+ * <br>Steven Spencer, JavaWorld magazine (<a href="http://www.javaworld.com/javaworld/javatips/jw-javatip66.html">Java Tip 66</a>)
+ * <br>Thanks also to Ron B. Yeh, Eric Shapiro, Ben Engber, Paul Teitlebaum, Andrea Cantatore,
+ * Larry Barowski, Trevor Bedzek, Frank Miedrich, and Ron Rabakukk
+ *
+ * @author Eric Albert (<a href="mailto:ejalbert@cs.stanford.edu">ejalbert@cs.stanford.edu</a>)
+ * @version 1.4b1 (Released June 20, 2001)
+ */
+public class BrowserLauncher {
+
+       /**
+        * The Java virtual machine that we are running on.  Actually, in most cases we only care
+        * about the operating system, but some operating systems require us to switch on the VM. */
+       private static int jvm;
+
+       /** The browser for the system */
+       private static Object browser;
+
+       /**
+        * Caches whether any classes, methods, and fields that are not part of the JDK and need to
+        * be dynamically loaded at runtime loaded successfully.
+        * <p>
+        * Note that if this is <code>false</code>, <code>openURL()</code> will always return an
+        * IOException.
+        */
+       private static boolean loadedWithoutErrors;
+
+       /** The com.apple.mrj.MRJFileUtils class */
+       private static Class mrjFileUtilsClass;
+
+       /** The com.apple.mrj.MRJOSType class */
+       private static Class mrjOSTypeClass;
+
+       /** The com.apple.MacOS.AEDesc class */
+       private static Class aeDescClass;
+       
+       /** The <init>(int) method of com.apple.MacOS.AETarget */
+       private static Constructor aeTargetConstructor;
+       
+       /** The <init>(int, int, int) method of com.apple.MacOS.AppleEvent */
+       private static Constructor appleEventConstructor;
+       
+       /** The <init>(String) method of com.apple.MacOS.AEDesc */
+       private static Constructor aeDescConstructor;
+       
+       /** The findFolder method of com.apple.mrj.MRJFileUtils */
+       private static Method findFolder;
+
+       /** The getFileCreator method of com.apple.mrj.MRJFileUtils */
+       private static Method getFileCreator;
+       
+       /** The getFileType method of com.apple.mrj.MRJFileUtils */
+       private static Method getFileType;
+       
+       /** The openURL method of com.apple.mrj.MRJFileUtils */
+       private static Method openURL;
+       
+       /** The makeOSType method of com.apple.MacOS.OSUtils */
+       private static Method makeOSType;
+       
+       /** The putParameter method of com.apple.MacOS.AppleEvent */
+       private static Method putParameter;
+       
+       /** The sendNoReply method of com.apple.MacOS.AppleEvent */
+       private static Method sendNoReply;
+       
+       /** Actually an MRJOSType pointing to the System Folder on a Macintosh */
+       private static Object kSystemFolderType;
+
+       /** The keyDirectObject AppleEvent parameter type */
+       private static Integer keyDirectObject;
+
+       /** The kAutoGenerateReturnID AppleEvent code */
+       private static Integer kAutoGenerateReturnID;
+       
+       /** The kAnyTransactionID AppleEvent code */
+       private static Integer kAnyTransactionID;
+
+       /** The linkage object required for JDirect 3 on Mac OS X. */
+       private static Object linkage;
+       
+       /** The framework to reference on Mac OS X */
+       private static final String JDirect_MacOSX = "/System/Library/Frameworks/Carbon.framework/Frameworks/HIToolbox.framework/HIToolbox";
+
+       /** JVM constant for MRJ 2.0 */
+       private static final int MRJ_2_0 = 0;
+       
+       /** JVM constant for MRJ 2.1 or later */
+       private static final int MRJ_2_1 = 1;
+
+       /** JVM constant for Java on Mac OS X 10.0 (MRJ 3.0) */
+       private static final int MRJ_3_0 = 3;
+       
+       /** JVM constant for MRJ 3.1 */
+       private static final int MRJ_3_1 = 4;
+
+       /** JVM constant for any Windows NT JVM */
+       private static final int WINDOWS_NT = 5;
+       
+       /** JVM constant for any Windows 9x JVM */
+       private static final int WINDOWS_9x = 6;
+
+       /** JVM constant for any other platform */
+       private static final int OTHER = -1;
+
+       /**
+        * The file type of the Finder on a Macintosh.  Hardcoding "Finder" would keep non-U.S. English
+        * systems from working properly.
+        */
+       private static final String FINDER_TYPE = "FNDR";
+
+       /**
+        * The creator code of the Finder on a Macintosh, which is needed to send AppleEvents to the
+        * application.
+        */
+       private static final String FINDER_CREATOR = "MACS";
+
+       /** The name for the AppleEvent type corresponding to a GetURL event. */
+       private static final String GURL_EVENT = "GURL";
+
+       /**
+        * The first parameter that needs to be passed into Runtime.exec() to open the default web
+        * browser on Windows.
+        */
+    private static final String FIRST_WINDOWS_PARAMETER = "/c";
+    
+    /** The second parameter for Runtime.exec() on Windows. */
+    private static final String SECOND_WINDOWS_PARAMETER = "start";
+    
+    /**
+     * The third parameter for Runtime.exec() on Windows.  This is a "title"
+     * parameter that the command line expects.  Setting this parameter allows
+     * URLs containing spaces to work.
+     */
+    private static final String THIRD_WINDOWS_PARAMETER = "\"\"";
+       
+       /**
+        * The shell parameters for Netscape that opens a given URL in an already-open copy of Netscape
+        * on many command-line systems.
+        */
+       private static final String NETSCAPE_REMOTE_PARAMETER = "-remote";
+       private static final String NETSCAPE_OPEN_PARAMETER_START = "'openURL(";
+       private static final String NETSCAPE_OPEN_PARAMETER_END = ")'";
+       
+       /**
+        * The message from any exception thrown throughout the initialization process.
+        */
+       private static String errorMessage;
+
+       /**
+        * An initialization block that determines the operating system and loads the necessary
+        * runtime data.
+        */
+       static {
+               loadedWithoutErrors = true;
+               String osName = System.getProperty("os.name");
+               if (osName.startsWith("Mac OS")) {
+                       String mrjVersion = System.getProperty("mrj.version");
+                       String majorMRJVersion = mrjVersion.substring(0, 3);
+                       try {
+                               double version = Double.valueOf(majorMRJVersion).doubleValue();
+                               if (version == 2) {
+                                       jvm = MRJ_2_0;
+                               } else if (version >= 2.1 && version < 3) {
+                                       // Assume that all 2.x versions of MRJ work the same.  MRJ 2.1 actually
+                                       // works via Runtime.exec() and 2.2 supports that but has an openURL() method
+                                       // as well that we currently ignore.
+                                       jvm = MRJ_2_1;
+                               } else if (version == 3.0) {
+                                       jvm = MRJ_3_0;
+                               } else if (version >= 3.1) {
+                                       // Assume that all 3.1 and later versions of MRJ work the same.
+                                       jvm = MRJ_3_1;
+                               } else {
+                                       loadedWithoutErrors = false;
+                                       errorMessage = "Unsupported MRJ version: " + version;
+                               }
+                       } catch (NumberFormatException nfe) {
+                               loadedWithoutErrors = false;
+                               errorMessage = "Invalid MRJ version: " + mrjVersion;
+                       }
+               } else if (osName.startsWith("Windows")) {
+                       if (osName.indexOf("9") != -1) {
+                               jvm = WINDOWS_9x;
+                       } else {
+                               jvm = WINDOWS_NT;
+                       }
+               } else {
+                       jvm = OTHER;
+               }
+               
+               if (loadedWithoutErrors) {      // if we haven't hit any errors yet
+                       loadedWithoutErrors = loadClasses();
+               }
+       }
+
+       /**
+        * This class should be never be instantiated; this just ensures so.
+        */
+       private BrowserLauncher() { }
+       
+       /**
+        * Called by a static initializer to load any classes, fields, and methods required at runtime
+        * to locate the user's web browser.
+        * @return <code>true</code> if all intialization succeeded
+        *                      <code>false</code> if any portion of the initialization failed
+        */
+       private static boolean loadClasses() {
+               switch (jvm) {
+                       case MRJ_2_0:
+                               try {
+                                       Class aeTargetClass = Class.forName("com.apple.MacOS.AETarget");
+                                       Class osUtilsClass = Class.forName("com.apple.MacOS.OSUtils");
+                                       Class appleEventClass = Class.forName("com.apple.MacOS.AppleEvent");
+                                       Class aeClass = Class.forName("com.apple.MacOS.ae");
+                                       aeDescClass = Class.forName("com.apple.MacOS.AEDesc");
+
+                                       aeTargetConstructor = aeTargetClass.getDeclaredConstructor(new Class [] { int.class });
+                                       appleEventConstructor = appleEventClass.getDeclaredConstructor(new Class[] { int.class, int.class, aeTargetClass, int.class, int.class });
+                                       aeDescConstructor = aeDescClass.getDeclaredConstructor(new Class[] { String.class });
+
+                                       makeOSType = osUtilsClass.getDeclaredMethod("makeOSType", new Class [] { String.class });
+                                       putParameter = appleEventClass.getDeclaredMethod("putParameter", new Class[] { int.class, aeDescClass });
+                                       sendNoReply = appleEventClass.getDeclaredMethod("sendNoReply", new Class[] { });
+
+                                       Field keyDirectObjectField = aeClass.getDeclaredField("keyDirectObject");
+                                       keyDirectObject = (Integer) keyDirectObjectField.get(null);
+                                       Field autoGenerateReturnIDField = appleEventClass.getDeclaredField("kAutoGenerateReturnID");
+                                       kAutoGenerateReturnID = (Integer) autoGenerateReturnIDField.get(null);
+                                       Field anyTransactionIDField = appleEventClass.getDeclaredField("kAnyTransactionID");
+                                       kAnyTransactionID = (Integer) anyTransactionIDField.get(null);
+                               } catch (ClassNotFoundException cnfe) {
+                                       errorMessage = cnfe.getMessage();
+                                       return false;
+                               } catch (NoSuchMethodException nsme) {
+                                       errorMessage = nsme.getMessage();
+                                       return false;
+                               } catch (NoSuchFieldException nsfe) {
+                                       errorMessage = nsfe.getMessage();
+                                       return false;
+                               } catch (IllegalAccessException iae) {
+                                       errorMessage = iae.getMessage();
+                                       return false;
+                               }
+                               break;
+                       case MRJ_2_1:
+                               try {
+                                       mrjFileUtilsClass = Class.forName("com.apple.mrj.MRJFileUtils");
+                                       mrjOSTypeClass = Class.forName("com.apple.mrj.MRJOSType");
+                                       Field systemFolderField = mrjFileUtilsClass.getDeclaredField("kSystemFolderType");
+                                       kSystemFolderType = systemFolderField.get(null);
+                                       findFolder = mrjFileUtilsClass.getDeclaredMethod("findFolder", new Class[] { mrjOSTypeClass });
+                                       getFileCreator = mrjFileUtilsClass.getDeclaredMethod("getFileCreator", new Class[] { File.class });
+                                       getFileType = mrjFileUtilsClass.getDeclaredMethod("getFileType", new Class[] { File.class });
+                               } catch (ClassNotFoundException cnfe) {
+                                       errorMessage = cnfe.getMessage();
+                                       return false;
+                               } catch (NoSuchFieldException nsfe) {
+                                       errorMessage = nsfe.getMessage();
+                                       return false;
+                               } catch (NoSuchMethodException nsme) {
+                                       errorMessage = nsme.getMessage();
+                                       return false;
+                               } catch (SecurityException se) {
+                                       errorMessage = se.getMessage();
+                                       return false;
+                               } catch (IllegalAccessException iae) {
+                                       errorMessage = iae.getMessage();
+                                       return false;
+                               }
+                               break;
+                       case MRJ_3_0:
+                           try {
+                                       Class linker = Class.forName("com.apple.mrj.jdirect.Linker");
+                                       Constructor constructor = linker.getConstructor(new Class[]{ Class.class });
+                                       linkage = constructor.newInstance(new Object[] { BrowserLauncher.class });
+                               } catch (ClassNotFoundException cnfe) {
+                                       errorMessage = cnfe.getMessage();
+                                       return false;
+                               } catch (NoSuchMethodException nsme) {
+                                       errorMessage = nsme.getMessage();
+                                       return false;
+                               } catch (InvocationTargetException ite) {
+                                       errorMessage = ite.getMessage();
+                                       return false;
+                               } catch (InstantiationException ie) {
+                                       errorMessage = ie.getMessage();
+                                       return false;
+                               } catch (IllegalAccessException iae) {
+                                       errorMessage = iae.getMessage();
+                                       return false;
+                               }
+                               break;
+                       case MRJ_3_1:
+                               try {
+                                       mrjFileUtilsClass = Class.forName("com.apple.mrj.MRJFileUtils");
+                                       openURL = mrjFileUtilsClass.getDeclaredMethod("openURL", new Class[] { String.class });
+                               } catch (ClassNotFoundException cnfe) {
+                                       errorMessage = cnfe.getMessage();
+                                       return false;
+                               } catch (NoSuchMethodException nsme) {
+                                       errorMessage = nsme.getMessage();
+                                       return false;
+                               }
+                               break;
+                       default:
+                           break;
+               }
+               return true;
+       }
+
+       /**
+        * Attempts to locate the default web browser on the local system.  Caches results so it
+        * only locates the browser once for each use of this class per JVM instance.
+        * @return The browser for the system.  Note that this may not be what you would consider
+        *                      to be a standard web browser; instead, it's the application that gets called to
+        *                      open the default web browser.  In some cases, this will be a non-String object
+        *                      that provides the means of calling the default browser.
+        */
+       private static Object locateBrowser() {
+               if (browser != null) {
+                       return browser;
+               }
+               switch (jvm) {
+                       case MRJ_2_0:
+                               try {
+                                       Integer finderCreatorCode = (Integer) makeOSType.invoke(null, new Object[] { FINDER_CREATOR });
+                                       Object aeTarget = aeTargetConstructor.newInstance(new Object[] { finderCreatorCode });
+                                       Integer gurlType = (Integer) makeOSType.invoke(null, new Object[] { GURL_EVENT });
+                                       Object appleEvent = appleEventConstructor.newInstance(new Object[] { gurlType, gurlType, aeTarget, kAutoGenerateReturnID, kAnyTransactionID });
+                                       // Don't set browser = appleEvent because then the next time we call
+                                       // locateBrowser(), we'll get the same AppleEvent, to which we'll already have
+                                       // added the relevant parameter. Instead, regenerate the AppleEvent every time.
+                                       // There's probably a way to do this better; if any has any ideas, please let
+                                       // me know.
+                                       return appleEvent;
+                               } catch (IllegalAccessException iae) {
+                                       browser = null;
+                                       errorMessage = iae.getMessage();
+                                       return browser;
+                               } catch (InstantiationException ie) {
+                                       browser = null;
+                                       errorMessage = ie.getMessage();
+                                       return browser;
+                               } catch (InvocationTargetException ite) {
+                                       browser = null;
+                                       errorMessage = ite.getMessage();
+                                       return browser;
+                               }
+                       case MRJ_2_1:
+                               File systemFolder;
+                               try {
+                                       systemFolder = (File) findFolder.invoke(null, new Object[] { kSystemFolderType });
+                               } catch (IllegalArgumentException iare) {
+                                       browser = null;
+                                       errorMessage = iare.getMessage();
+                                       return browser;
+                               } catch (IllegalAccessException iae) {
+                                       browser = null;
+                                       errorMessage = iae.getMessage();
+                                       return browser;
+                               } catch (InvocationTargetException ite) {
+                                       browser = null;
+                                       errorMessage = ite.getTargetException().getClass() + ": " + ite.getTargetException().getMessage();
+                                       return browser;
+                               }
+                               String[] systemFolderFiles = systemFolder.list();
+                               // Avoid a FilenameFilter because that can't be stopped mid-list
+                               for(int i = 0; i < systemFolderFiles.length; i++) {
+                                       try {
+                                               File file = new File(systemFolder, systemFolderFiles[i]);
+                                               if (!file.isFile()) {
+                                                       continue;
+                                               }
+                                               // We're looking for a file with a creator code of 'MACS' and
+                                               // a type of 'FNDR'.  Only requiring the type results in non-Finder
+                                               // applications being picked up on certain Mac OS 9 systems,
+                                               // especially German ones, and sending a GURL event to those
+                                               // applications results in a logout under Multiple Users.
+                                               Object fileType = getFileType.invoke(null, new Object[] { file });
+                                               if (FINDER_TYPE.equals(fileType.toString())) {
+                                                       Object fileCreator = getFileCreator.invoke(null, new Object[] { file });
+                                                       if (FINDER_CREATOR.equals(fileCreator.toString())) {
+                                                               browser = file.toString();      // Actually the Finder, but that's OK
+                                                               return browser;
+                                                       }
+                                               }
+                                       } catch (IllegalArgumentException iare) {
+                                               browser = browser;
+                                               errorMessage = iare.getMessage();
+                                               return null;
+                                       } catch (IllegalAccessException iae) {
+                                               browser = null;
+                                               errorMessage = iae.getMessage();
+                                               return browser;
+                                       } catch (InvocationTargetException ite) {
+                                               browser = null;
+                                               errorMessage = ite.getTargetException().getClass() + ": " + ite.getTargetException().getMessage();
+                                               return browser;
+                                       }
+                               }
+                               browser = null;
+                               break;
+                       case MRJ_3_0:
+                       case MRJ_3_1:
+                               browser = "";   // Return something non-null
+                               break;
+                       case WINDOWS_NT:
+                               browser = "cmd.exe";
+                               break;
+                       case WINDOWS_9x:
+                               browser = "command.com";
+                               break;
+                       case OTHER:
+                       default:
+                               browser = "netscape";
+                               break;
+               }
+               return browser;
+       }
+
+       /**
+        * Attempts to open the default web browser to the given URL.
+        * @param url The URL to open
+        * @throws IOException If the web browser could not be located or does not run
+        */
+       public static void openURL(String url) throws IOException {
+               if (!loadedWithoutErrors) {
+                       throw new IOException("Exception in finding browser: " + errorMessage);
+               }
+               Object browser = locateBrowser();
+               if (browser == null) {
+                       throw new IOException("Unable to locate browser: " + errorMessage);
+               }
+               
+               switch (jvm) {
+                       case MRJ_2_0:
+                               Object aeDesc = null;
+                               try {
+                                       aeDesc = aeDescConstructor.newInstance(new Object[] { url });
+                                       putParameter.invoke(browser, new Object[] { keyDirectObject, aeDesc });
+                                       sendNoReply.invoke(browser, new Object[] { });
+                               } catch (InvocationTargetException ite) {
+                                       throw new IOException("InvocationTargetException while creating AEDesc: " + ite.getMessage());
+                               } catch (IllegalAccessException iae) {
+                                       throw new IOException("IllegalAccessException while building AppleEvent: " + iae.getMessage());
+                               } catch (InstantiationException ie) {
+                                       throw new IOException("InstantiationException while creating AEDesc: " + ie.getMessage());
+                               } finally {
+                                       aeDesc = null;  // Encourage it to get disposed if it was created
+                                       browser = null; // Ditto
+                               }
+                               break;
+                       case MRJ_2_1:
+                               Runtime.getRuntime().exec(new String[] { (String) browser, url } );
+                               break;
+                       case MRJ_3_0:
+                               int[] instance = new int[1];
+                               int result = ICStart(instance, 0);
+                               if (result == 0) {
+                                       int[] selectionStart = new int[] { 0 };
+                                       byte[] urlBytes = url.getBytes();
+                                       int[] selectionEnd = new int[] { urlBytes.length };
+                                       result = ICLaunchURL(instance[0], new byte[] { 0 }, urlBytes,
+                                                                                       urlBytes.length, selectionStart,
+                                                                                       selectionEnd);
+                                       if (result == 0) {
+                                               // Ignore the return value; the URL was launched successfully
+                                               // regardless of what happens here.
+                                               ICStop(instance);
+                                       } else {
+                                               throw new IOException("Unable to launch URL: " + result);
+                                       }
+                               } else {
+                                       throw new IOException("Unable to create an Internet Config instance: " + result);
+                               }
+                               break;
+                       case MRJ_3_1:
+                               try {
+                                       openURL.invoke(null, new Object[] { url });
+                               } catch (InvocationTargetException ite) {
+                                       throw new IOException("InvocationTargetException while calling openURL: " + ite.getMessage());
+                               } catch (IllegalAccessException iae) {
+                                       throw new IOException("IllegalAccessException while calling openURL: " + iae.getMessage());
+                               }
+                               break;
+                   case WINDOWS_NT:
+                   case WINDOWS_9x:
+                       // Add quotes around the URL to allow ampersands and other special
+                       // characters to work.
+                               Process process = Runtime.getRuntime().exec(new String[] { (String) browser,
+                                                                                                                               FIRST_WINDOWS_PARAMETER,
+                                                                                                                               SECOND_WINDOWS_PARAMETER,
+                                                                                                                               THIRD_WINDOWS_PARAMETER,
+                                                                                                                               '"' + url + '"' });
+                               // This avoids a memory leak on some versions of Java on Windows.
+                               // That's hinted at in <http://developer.java.sun.com/developer/qow/archive/68/>.
+                               try {
+                                       process.waitFor();
+                                       process.exitValue();
+                               } catch (InterruptedException ie) {
+                                       throw new IOException("InterruptedException while launching browser: " + ie.getMessage());
+                               }
+                               break;
+                       case OTHER:
+                               // Assume that we're on Unix and that Netscape is installed
+                               
+                               // First, attempt to open the URL in a currently running session of Netscape
+                               process = Runtime.getRuntime().exec(new String[] { (String) browser,
+                                                                                                       NETSCAPE_REMOTE_PARAMETER,
+                                                                                                       NETSCAPE_OPEN_PARAMETER_START +
+                                                                                                       url +
+                                                                                                       NETSCAPE_OPEN_PARAMETER_END });
+                               try {
+                                       int exitCode = process.waitFor();
+                                       if (exitCode != 0) {    // if Netscape was not open
+                                               Runtime.getRuntime().exec(new String[] { (String) browser, url });
+                                       }
+                               } catch (InterruptedException ie) {
+                                       throw new IOException("InterruptedException while launching browser: " + ie.getMessage());
+                               }
+                               break;
+                       default:
+                               // This should never occur, but if it does, we'll try the simplest thing possible
+                               Runtime.getRuntime().exec(new String[] { (String) browser, url });
+                               break;
+               }
+       }
+
+       /**
+        * Methods required for Mac OS X.  The presence of native methods does not cause
+        * any problems on other platforms.
+        */
+       private native static int ICStart(int[] instance, int signature);
+       private native static int ICStop(int[] instance);
+       private native static int ICLaunchURL(int instance, byte[] hint, byte[] data, int len,
+                                                                                       int[] selectionStart, int[] selectionEnd);
+}
index 554b287..f18182c 100644 (file)
@@ -102,10 +102,10 @@ public final class Box extends JS.Scope {
     //#define MIN_LENGTH Integer.MIN_VALUE
 
     // always correct (set directly by user)
     //#define MIN_LENGTH Integer.MIN_VALUE
 
     // always correct (set directly by user)
-    LENGTH minwidth = 0;        
-    LENGTH minheight = 0;        
-    LENGTH maxwidth = MAX_LENGTH;
-    LENGTH maxheight = MAX_LENGTH;
+    public LENGTH minwidth = 0;        
+    public LENGTH minheight = 0;        
+    public LENGTH maxwidth = MAX_LENGTH;
+    public LENGTH maxheight = MAX_LENGTH;
     private LENGTH hpad = 0;
     private LENGTH vpad = 0;
     private String text = null;
     private LENGTH hpad = 0;
     private LENGTH vpad = 0;
     private String text = null;
@@ -137,7 +137,7 @@ public final class Box extends JS.Scope {
     //private SVG.Paint fill = null;
     //private SVG.Paint stroke = null;
 
     //private SVG.Paint fill = null;
     //private SVG.Paint stroke = null;
 
-    private Picture image;                       // will disappear
+    public Picture image;                        // will disappear
     private int fillcolor = 0x00000000;          // will become SVG.Paint
     private int strokecolor = 0xFF000000;        // will become SVG.Paint
 
     private int fillcolor = 0x00000000;          // will become SVG.Paint
     private int strokecolor = 0xFF000000;        // will become SVG.Paint
 
@@ -196,10 +196,11 @@ public final class Box extends JS.Scope {
 
     // Reflow ////////////////////////////////////////////////////////////////////////////////////////
 
 
     // Reflow ////////////////////////////////////////////////////////////////////////////////////////
 
-    void reflow() {
+    void reflow() { reflow(width, height); }
+    void reflow(int new_width, int new_height) {
         repack();
         if (Surface.abort) return;
         repack();
         if (Surface.abort) return;
-        resize(x, y, width, height);
+        resize(x, y, new_width, new_height);
     }
 
     /** Checks if the Box's size has changed, dirties it if necessary, and makes sure childrens' sizes are up to date */
     }
 
     /** Checks if the Box's size has changed, dirties it if necessary, and makes sure childrens' sizes are up to date */
@@ -270,8 +271,8 @@ public final class Box extends JS.Scope {
     }
 
 
     }
 
 
-    void resize(LENGTH x, LENGTH y, LENGTH width, LENGTH height) {
-
+    private void resize(LENGTH x, LENGTH y, LENGTH width, LENGTH height) {
+        
         // --- Phase 1 ----------------------------------------------------------------------
         // run PosChange/SizeChange, dirty as needed
         if (x != this.x || y != this.y || width != this.width || height != this.height) {
         // --- Phase 1 ----------------------------------------------------------------------
         // run PosChange/SizeChange, dirty as needed
         if (x != this.x || y != this.y || width != this.width || height != this.height) {
@@ -286,8 +287,8 @@ public final class Box extends JS.Scope {
                     if (Log.on) Log.logJS(this, "Warning, more than 500 SizeChange/PosChange traps triggered since last complete render");
                 } else {
                     sizePosChangesSinceLastRender++;
                     if (Log.on) Log.logJS(this, "Warning, more than 500 SizeChange/PosChange traps triggered since last complete render");
                 } else {
                     sizePosChangesSinceLastRender++;
-                    if (sizechange) put("SizeChange", Boolean.TRUE);
-                    if (poschange) put("PosChange", Boolean.TRUE);
+                    try { if (sizechange) put("SizeChange", Boolean.TRUE); } catch (Exception e) { Log.log(this, e); }
+                    try { if (poschange) put("PosChange", Boolean.TRUE); } catch (Exception e) { Log.log(this, e); }
                     Surface.abort = true;
                     return;
                 }
                     Surface.abort = true;
                     return;
                 }
@@ -390,17 +391,14 @@ public final class Box extends JS.Scope {
         int globaly = parenty + (parent == null ? 0 : y);
 
         // intersect the x,y,w,h rendering window with ourselves; quit if it's empty
         int globaly = parenty + (parent == null ? 0 : y);
 
         // intersect the x,y,w,h rendering window with ourselves; quit if it's empty
-        clipw = min(max(clipx, parent == null ? 0 : globalx) + clipw,
-                    (parent == null ? 0 : globalx) + width) - globalx;
-        cliph = min(max(clipy, parent == null ? 0 : globaly) + cliph,
-                    (parent == null ? 0 : globaly) + height) - globaly;
+        clipw = min(max(clipx, parent == null ? 0 : globalx) + clipw, (parent == null ? 0 : globalx) + width) - globalx;
+        cliph = min(max(clipy, parent == null ? 0 : globaly) + cliph, (parent == null ? 0 : globaly) + height) - globaly;
         clipx = max(clipx, parent == null ? 0 : globalx);
         clipy = max(clipy, parent == null ? 0 : globaly);
         if (clipw <= 0 || cliph <= 0) return;
 
         clipx = max(clipx, parent == null ? 0 : globalx);
         clipy = max(clipy, parent == null ? 0 : globaly);
         if (clipw <= 0 || cliph <= 0) return;
 
-        if ((fillcolor & 0xFF000000) != 0x00000000 || parent == null)
-            buf.fillRect(clipx, clipy, clipx + clipw, clipy + cliph,
-                         (fillcolor & 0xFF000000) != 0 ? fillcolor : 0xFF777777);
+        if ((fillcolor & 0xFF000000) != 0x00000000)
+            buf.fillRect(clipx, clipy, clipx + clipw, clipy + cliph, fillcolor);
 
         if (image != null)
             if ((flags & TILE_FLAG) != 0) renderTiledImage(globalx, globaly, clipx, clipy, clipw, cliph, buf);
 
         if (image != null)
             if ((flags & TILE_FLAG) != 0) renderTiledImage(globalx, globaly, clipx, clipy, clipw, cliph, buf);
@@ -1126,6 +1124,7 @@ public final class Box extends JS.Scope {
                     public Object get(Box b) { return b.image == null ? null : ImageDecoder.imageToNameMap.get(b.image); }
                     */
                     public void put(Box b, Object value) {
                     public Object get(Box b) { return b.image == null ? null : ImageDecoder.imageToNameMap.get(b.image); }
                     */
                     public void put(Box b, Object value) {
+                        //if (image != null) System.out.println("hit");
                         if (value == null) {
                             b.image = null;
                         } else if (value instanceof Res) {
                         if (value == null) {
                             b.image = null;
                         } else if (value instanceof Res) {
index 19fc41c..50c71c9 100644 (file)
@@ -510,7 +510,7 @@ public class HTTP {
                 int i = super.read();
                 if (i == -1) throw new HTTPException("encountered end of stream while reading chunk length");
 
                 int i = super.read();
                 if (i == -1) throw new HTTPException("encountered end of stream while reading chunk length");
 
-                // FIXME: handle chunking extensions
+                // FEATURE: handle chunking extensions
                 if (i == '\r') {
                     super.read();    // LF
                     break;
                 if (i == '\r') {
                     super.read();    // LF
                     break;
@@ -755,8 +755,6 @@ public class HTTP {
                         try {
                             org.xwt.js.JS.Array arr = new org.xwt.js.JS.Array();
                             arr.addElement(((JS.Exn)e).getObject());
                         try {
                             org.xwt.js.JS.Array arr = new org.xwt.js.JS.Array();
                             arr.addElement(((JS.Exn)e).getObject());
-                            // FIXME
-                            //XWT.recursivePrintObject.call();
                         } catch (Exception e2) {
                             Log.log(Platform.class, e);
                         }
                         } catch (Exception e2) {
                             Log.log(Platform.class, e);
                         }
@@ -787,11 +785,10 @@ public class HTTP {
                 Message.Q.add(new Message() {
                         public void perform() {
                             Box b = new Box();
                 Message.Q.add(new Message() {
                         public void perform() {
                             Box b = new Box();
-                            /* FIXME
-                            Template.getTemplate("org.xwt.builtin.proxy_authorization", null).apply(b, null, null, null, 0, 0, null);
+                            Template t = Template.getTemplate((Res)Main.builtin.get("org/xwt/builtin/proxy_authorization.xwt"));
+                            t.apply(b, null, 0, 0, null);
                             b.put("realm", realm);
                             b.put("proxyIP", proxyIP);
                             b.put("realm", realm);
                             b.put("proxyIP", proxyIP);
-                            */
                         }
                     });
 
                         }
                     });
 
@@ -804,12 +801,10 @@ public class HTTP {
 
         // ProxyAutoConfigRootScope ////////////////////////////////////////////////////////////////////
 
 
         // ProxyAutoConfigRootScope ////////////////////////////////////////////////////////////////////
 
-        public static class ProxyAutoConfigRootScope extends JS.Scope {
+        public static class ProxyAutoConfigRootScope extends JS.GlobalScope {
 
             public ProxyAutoConfigRootScope() { super(null); }
         
 
             public ProxyAutoConfigRootScope() { super(null); }
         
-            // FIXME: needs "standard objects"
-
             public Object get(Object name) {
                 if (name.equals("isPlainHostName")) return isPlainHostName;
                 else if (name.equals("dnsDomainIs")) return dnsDomainIs;
             public Object get(Object name) {
                 if (name.equals("isPlainHostName")) return isPlainHostName;
                 else if (name.equals("dnsDomainIs")) return dnsDomainIs;
index 8162f0c..c8d60cc 100644 (file)
@@ -89,7 +89,6 @@ public interface Message {
                     if (Log.on) Log.log(this, "caught throwable in Q.run(); this should never happen");
                     if (Log.on) Log.log(this, "    currentlyPerforming == " + currentlyPerforming);
                     if (Log.on) Log.log(this, "    working             == " + working);
                     if (Log.on) Log.log(this, "caught throwable in Q.run(); this should never happen");
                     if (Log.on) Log.log(this, "    currentlyPerforming == " + currentlyPerforming);
                     if (Log.on) Log.log(this, "    working             == " + working);
-                    // FIXME - this currently calls compiledfunction.toString which gives more info than we need
                     if (Log.on) Log.log(this, t);
                     if (Log.on) Log.log(this, "resuming Q loop");
                 }
                     if (Log.on) Log.log(this, t);
                     if (Log.on) Log.log(this, "resuming Q loop");
                 }
index accf069..9216dcb 100644 (file)
@@ -229,6 +229,15 @@ public class Platform {
         }
     }
 
         }
     }
 
+    /** default implementation is Eric Albert's BrowserLauncher.java */
+    protected void _newBrowserWindow(String url) {
+        try {
+            edu.stanford.ejalbert.BrowserLauncher.openURL(url);
+        } catch (Exception e) {
+            Log.log(this, e);
+        }
+    }
+
     /** opens a new browser window */
     public static void newBrowserWindow(String url) {
         if (!(url.startsWith("https://") || url.startsWith("http://") || url.startsWith("ftp://") || url.startsWith("mailto:"))) {
     /** opens a new browser window */
     public static void newBrowserWindow(String url) {
         if (!(url.startsWith("https://") || url.startsWith("http://") || url.startsWith("ftp://") || url.startsWith("mailto:"))) {
@@ -249,9 +258,6 @@ public class Platform {
         if (Log.on) Log.log(Platform.class, "newBrowserWindow, url = " + url);
         platform._newBrowserWindow(url);
     }
         if (Log.on) Log.log(Platform.class, "newBrowserWindow, url = " + url);
         platform._newBrowserWindow(url);
     }
-    protected void _newBrowserWindow(String url) {
-        if (Log.on) Log.log(this, "Platform " + platform.getClass().getName() + " cannot open browser windows");
-    }
 
     /** used to notify the user of very serious failures; usually used when logging is not working or unavailable */
     public static void criticalAbort(String message) {
 
     /** used to notify the user of very serious failures; usually used when logging is not working or unavailable */
     public static void criticalAbort(String message) {
@@ -269,14 +275,12 @@ public class Platform {
         Object titlebar = b.get("titlebar", true);
         if (titlebar != null) ret.setTitleBarText(titlebar.toString());
 
         Object titlebar = b.get("titlebar", true);
         if (titlebar != null) ret.setTitleBarText(titlebar.toString());
 
-        /* FIXME
         Object icon = b.get("icon", true);
         Object icon = b.get("icon", true);
-        if (icon != null && !"".equals(icon)) {
-            Picture pic = ImageDecoder.getPicture(icon.toString());
+        if (icon != null && icon instanceof Res) {
+            Picture pic = Picture.fromRes((Res)icon);
             if (pic != null) ret.setIcon(pic);
             else if (Log.on) Log.log(Platform.class, "unable to load icon " + icon);
         }
             if (pic != null) ret.setIcon(pic);
             else if (Log.on) Log.log(Platform.class, "unable to load icon " + icon);
         }
-        */
 
         ret.setLimits(b.minwidth, b.minheight, b.maxwidth, b.maxheight);
 
 
         ret.setLimits(b.minwidth, b.minheight, b.maxwidth, b.maxheight);
 
index 20858e6..77b502b 100644 (file)
@@ -43,12 +43,13 @@ public abstract class Res extends JS {
         return ret;
     }
 
         return ret;
     }
 
-    public static Res stringToRes(String url) {
+    public static Res stringToRes(String url) { return stringToRes(url, false); }
+    public static Res stringToRes(String url, boolean permitLocalFilesystem) {
         if (url.indexOf('!') != -1)
             return (Res)(new Zip(stringToRes(url.substring(0, url.lastIndexOf('!')))).get(url.substring(url.lastIndexOf('!') + 1)));
         if (url.startsWith("http://")) return new HTTP(url);
         if (url.startsWith("https://")) return new HTTP(url);
         if (url.indexOf('!') != -1)
             return (Res)(new Zip(stringToRes(url.substring(0, url.lastIndexOf('!')))).get(url.substring(url.lastIndexOf('!') + 1)));
         if (url.startsWith("http://")) return new HTTP(url);
         if (url.startsWith("https://")) return new HTTP(url);
-        if (url.startsWith("file:")) return new File(url.substring(5));
+        if (url.startsWith("file:") && permitLocalFilesystem) return new File(url.substring(5));
         if (url.startsWith("cab:")) return new CAB(stringToRes(url.substring(4)));
         throw new JS.Exn("invalid resource specifier");
     }
         if (url.startsWith("cab:")) return new CAB(stringToRes(url.substring(4)));
         throw new JS.Exn("invalid resource specifier");
     }
@@ -70,7 +71,6 @@ public abstract class Res extends JS {
         }
     }
 
         }
     }
 
-    // FIXME: dangerous
     /** a file */
     public static class File extends Res {
         private String path;
     /** a file */
     public static class File extends Res {
         private String path;
index debbc24..2771304 100644 (file)
@@ -41,7 +41,7 @@ class SOAP extends XMLRPC {
         if (name.equals("SOAP-ENV:Envelope")) return;
         if (name.equals("SOAP-ENV:Body")) return;
         if (name.equals("SOAP-ENV:Fault")) fault = true;
         if (name.equals("SOAP-ENV:Envelope")) return;
         if (name.equals("SOAP-ENV:Body")) return;
         if (name.equals("SOAP-ENV:Fault")) fault = true;
-
         // add a generic struct; we'll change this if our type is different
         objects.addElement(new JS.Obj());
 
         // add a generic struct; we'll change this if our type is different
         objects.addElement(new JS.Obj());
 
index 922f2e3..089480e 100644 (file)
@@ -17,6 +17,7 @@ import java.util.*;
  *  MessageQueue-time (the size/position/state at the time that the
  *  now-executing message was enqueued). This distinction is important.
  */
  *  MessageQueue-time (the size/position/state at the time that the
  *  now-executing message was enqueued). This distinction is important.
  */
+// FIXME: put the scar box back in
 public abstract class Surface extends PixelBuffer {
 
     public int getWidth() { return root == null ? 0 : root.width; }
 public abstract class Surface extends PixelBuffer {
 
     public int getWidth() { return root == null ? 0 : root.width; }
@@ -33,9 +34,6 @@ public abstract class Surface extends PixelBuffer {
     /** When set to true, render() should abort as soon as possible and restart the rendering process */
     static volatile boolean abort = false;
 
     /** When set to true, render() should abort as soon as possible and restart the rendering process */
     static volatile boolean abort = false;
 
-    /** the scar image drawn on the bottom right hand corner */
-    static Box scarBox = null;
-
     public static boolean alt = false;          ///< true iff the alt button is pressed down, in real time
     public static boolean control = false;      ///< true iff the control button is pressed down, in real time
     public static boolean shift = false;        ///< true iff the shift button is pressed down, in real time
     public static boolean alt = false;          ///< true iff the alt button is pressed down, in real time
     public static boolean control = false;      ///< true iff the control button is pressed down, in real time
     public static boolean shift = false;        ///< true iff the shift button is pressed down, in real time
@@ -224,9 +222,8 @@ public abstract class Surface extends PixelBuffer {
     protected final void SizeChange(final int width, final int height) {
         Message.Q.add(new Message() { public void perform() {
             if (width == root.width && height == root.height) return;
     protected final void SizeChange(final int width, final int height) {
         Message.Q.add(new Message() { public void perform() {
             if (width == root.width && height == root.height) return;
-            root.width = width;
-            root.height = height;
             root.needs_reflow = true;
             root.needs_reflow = true;
+            root.reflow(width, height);
         }});
         abort = true;
     }
         }});
         abort = true;
     }
@@ -252,12 +249,9 @@ public abstract class Surface extends PixelBuffer {
 
     /** wrapper for setSize() which makes sure to dirty the place where the scar used to be */
     void setSize() {
 
     /** wrapper for setSize() which makes sure to dirty the place where the scar used to be */
     void setSize() {
-        scarBox.dirty();
-        root.width = Math.max(root.width, scarBox.minwidth);
-        root.height = Math.max(root.height, scarBox.minheight);
+        root.width = Math.max(root.width, 10);
+        root.height = Math.max(root.height, 10);
         setSize(root.width, root.height);
         setSize(root.width, root.height);
-        scarBox.x = 0;
-        scarBox.y = root.height - scarBox.minheight;
     }
 
     /** Indicates that the Surface is no longer needed */
     }
 
     /** Indicates that the Surface is no longer needed */
@@ -277,14 +271,8 @@ public abstract class Surface extends PixelBuffer {
     }
 
     public Surface(Box root) {
     }
 
     public Surface(Box root) {
+
         this.root = root;
         this.root = root;
-        scarBox = new Box();
-        try {
-            scarBox.put("image", ((Res)Main.builtin.get("org/xwt/builtin/scar.png")).getInputStream());
-        } catch (Exception e) {
-            Log.log(this, e);
-        }
-        scarBox.surface = this;
         if (root.surface != null && root.surface.root == root) root.surface.dispose(false);
         else root.remove();
         root.surface = this;
         if (root.surface != null && root.surface.root == root) root.surface.dispose(false);
         else root.remove();
         root.surface = this;
@@ -296,11 +284,6 @@ public abstract class Surface extends PixelBuffer {
         Refresh();
     }
 
         Refresh();
     }
 
-    public void paintRegion(int x, int y, int w, int h) {
-        root.render(0, 0, x, y, w, h, this);
-        scarBox.render(0, 0, x, y, w, h, this);
-    }
-
     /** runs the prerender() and render() pipelines in the root Box to regenerate the backbuffer, then blits it to the screen */
     public synchronized void render() {
 
     /** runs the prerender() and render() pipelines in the root Box to regenerate the backbuffer, then blits it to the screen */
     public synchronized void render() {
 
@@ -326,7 +309,7 @@ public abstract class Surface extends PixelBuffer {
             if (y+h > root.height) h = root.height - y;
             if (w <= 0 || h <= 0) continue;
 
             if (y+h > root.height) h = root.height - y;
             if (w <= 0 || h <= 0) continue;
 
-            paintRegion(x, y, w, h);
+            root.render(0, 0, x, y, w, h, this);
             
             if (abort) {
 
             
             if (abort) {
 
@@ -370,29 +353,17 @@ public abstract class Surface extends PixelBuffer {
 
     public static abstract class DoubleBufferedSurface extends Surface {
 
 
     public static abstract class DoubleBufferedSurface extends Surface {
 
-        public DoubleBufferedSurface(Box root) {
-            super(root);
-
-            // this is a bit dangerous since we're passing ourselves to another method before subclasses' ctors have run...        
-            backbuffer = Platform.createPixelBuffer(Platform.getScreenWidth(), Platform.getScreenHeight(), this);
-        }
-
-        /** The automatic double buffer for the root box */
-        PixelBuffer backbuffer = null;
-
-        /** Dirty regions on the screen which need to be rebuilt using Surface.blit() */
+        public DoubleBufferedSurface(Box root) { super(root); }
+        PixelBuffer backbuffer = Platform.createPixelBuffer(Platform.getScreenWidth(), Platform.getScreenHeight(), this);
         DirtyList screenDirtyRegions = new DirtyList();
 
         public void drawPicture(Picture source, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2) {
         DirtyList screenDirtyRegions = new DirtyList();
 
         public void drawPicture(Picture source, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2) {
+            screenDirtyRegions.dirty(dx1, dy1, dx2 - dx1, dy2 - dy1);
             backbuffer.drawPicture(source, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2); }
 
         public void fillRect(int x1, int y1, int x2, int y2, int color) {
             backbuffer.drawPicture(source, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2); }
 
         public void fillRect(int x1, int y1, int x2, int y2, int color) {
+            screenDirtyRegions.dirty(x1, y1, x2 - x1, y2 - y1);
             backbuffer.fillRect(x1, y1, x2, y2, color); }
             backbuffer.fillRect(x1, y1, x2, y2, color); }
-        
-        public void paintRegion(int x, int y, int w, int h) {
-            super.paintRegion(x, y, w, h);
-            screenDirtyRegions.dirty(x, y, w, h);
-        }
 
         public void render() {
             super.render();
 
         public void render() {
             super.render();
index 363886c..95846c1 100644 (file)
@@ -149,8 +149,10 @@ public class Template {
         }
 
         for (int i=0; children != null && i<children.length; i++) {
         }
 
         for (int i=0; children != null && i<children.length; i++) {
-            children[i].apply(new Box(), callback, numerator, denominator, resourceRoot);
+            Box kid = new Box();
+            children[i].apply(kid, callback, numerator, denominator, resourceRoot);
             numerator += children[i].numUnits();
             numerator += children[i].numUnits();
+            b.put(b.numChildren(), kid);
         }
 
         // whom to redirect to; doesn't take effect until after script runs
         }
 
         // whom to redirect to; doesn't take effect until after script runs
@@ -309,14 +311,18 @@ public class Template {
 
             }
 
 
             }
 
-            // TODO: Sort contents straight from one array to another
-            // FIXME: height must come after image
-            // FIXME: use Vec here
             t.keys = new String[c.len];
             t.vals = new Object[c.len];
             t.keys = new String[c.len];
             t.vals = new Object[c.len];
-            System.arraycopy(c.keys, 0, t.keys, 0, c.len);
-            System.arraycopy(c.vals, 0, t.vals, 0, c.len);
-            quickSortAttributes(0, t.keys.length - 1);
+            Hash h = new Hash(c.len * 2, 3);
+            for(int i=0; i<c.len; i++) h.put(c.keys[i], c.vals[i]);
+            Vec v = new Vec(c.len, c.keys);
+            v.sort(new Vec.CompareFunc() { public int compare(Object a, Object b) { return ((String)a).compareTo((String)b); } });
+            for(int i=0; i<c.len; i++) {
+                // FIXME: height must come after image
+                // FIXME: thisbox must come first
+                t.keys[i] = (String)v.elementAt(i);
+                t.vals[i] = h.get(t.keys[i]);
+            }
 
             for(int i=0; i<t.keys.length; i++) {
                 if (t.keys[i].equals("id")) {
 
             for(int i=0; i<t.keys.length; i++) {
                 if (t.keys[i].equals("id")) {
@@ -358,37 +364,26 @@ public class Template {
             }
         }
 
             }
         }
 
-        /** simple quicksort, from http://sourceforge.net/snippet/detail.php?type=snippet&id=100240 */
-        private int partitionAttributes(int left, int right) {
-            int i, j, middle;
-            middle = (left + right) / 2;
-            String s = t.keys[right]; t.keys[right] = t.keys[middle]; t.keys[middle] = s;
-            Object o = t.vals[right]; t.vals[right] = t.vals[middle]; t.vals[middle] = o;
-            for (i = left - 1, j = right; ; ) {
-                while (t.keys[++i].compareTo(t.keys[right]) < 0);
-                while (j > left && t.keys[--j].compareTo(t.keys[right]) > 0);
-                if (i >= j) break;
-                s = t.keys[i]; t.keys[i] = t.keys[j]; t.keys[j] = s;
-                o = t.vals[i]; t.vals[i] = t.vals[j]; t.vals[j] = o;
+        private JS.CompiledFunction genscript(boolean isstatic) {
+            JS.CompiledFunction thisscript = null;
+            try {
+                thisscript = JS.parse(t.fileName + (isstatic ? "._" : ""), t.content_start, new StringReader(t.content.toString()));
+            } catch (IOException ioe) {
+                if (Log.on) Log.log(this, "  ERROR: " + ioe.getMessage());
+                thisscript = null;
             }
             }
-            s = t.keys[right]; t.keys[right] = t.keys[i]; t.keys[i] = s;
-            o = t.vals[right]; t.vals[right] = t.vals[i]; t.vals[i] = o;
-            return i;
-        }
 
 
-        /** simple quicksort, from http://sourceforge.net/snippet/detail.php?type=snippet&id=100240 */
-        private void quickSortAttributes(int left, int right) {
-            if (left >= right) return;
-            int p = partitionAttributes(left, right);
-            quickSortAttributes(left, p - 1);
-            quickSortAttributes(p + 1, right);
+            t.content = null;
+            t.content_start = 0;
+            t.content_lines = 0;
+            return thisscript;
         }
 
         public void endElement(XML.Element c) throws XML.SchemaException {
             if (rootNodeHasBeenEncountered && !templateNodeHasBeenEncountered) {
                 if ("static".equals(nameOfHeaderNodeBeingProcessed) && t.content != null) t.staticscript = genscript(true);
                 nameOfHeaderNodeBeingProcessed = null;
         }
 
         public void endElement(XML.Element c) throws XML.SchemaException {
             if (rootNodeHasBeenEncountered && !templateNodeHasBeenEncountered) {
                 if ("static".equals(nameOfHeaderNodeBeingProcessed) && t.content != null) t.staticscript = genscript(true);
                 nameOfHeaderNodeBeingProcessed = null;
-
+                
             } else if (templateNodeHasBeenEncountered && !templateNodeHasBeenFinished) {
                 // turn our childvect into a Template[]
                 t.childvect.copyInto(t.children = new Template[t.childvect.size()]);
             } else if (templateNodeHasBeenEncountered && !templateNodeHasBeenFinished) {
                 // turn our childvect into a Template[]
                 t.childvect.copyInto(t.children = new Template[t.childvect.size()]);
@@ -398,7 +393,7 @@ public class Template {
                 if (nodeStack.size() == 0) {
                     // </template>
                     templateNodeHasBeenFinished = true;
                 if (nodeStack.size() == 0) {
                     // </template>
                     templateNodeHasBeenFinished = true;
-
+                    
                 } else {
                     // add this template as a child of its parent
                     Template oldt = t;
                 } else {
                     // add this template as a child of its parent
                     Template oldt = t;
@@ -406,24 +401,8 @@ public class Template {
                     nodeStack.setSize(nodeStack.size() - 1);
                     t.childvect.addElement(oldt);
                 }
                     nodeStack.setSize(nodeStack.size() - 1);
                     t.childvect.addElement(oldt);
                 }
-
             }
             }
-        }
-
-        private JS.CompiledFunction genscript(boolean isstatic) {
-            JS.CompiledFunction thisscript = null;
-            try {
-                thisscript = JS.parse(t.fileName + (isstatic ? "._" : ""), t.content_start, new StringReader(t.content.toString()));
-            } catch (IOException ioe) {
-                if (Log.on) Log.log(this, "  ERROR: " + ioe.getMessage());
-                thisscript = null;
-            }
-
-            t.content = null;
-            t.content_start = 0;
-            t.content_lines = 0;
-            return thisscript;
-        }
+         }
 
         public void characters(char[] ch, int start, int length) throws XML.SchemaException {
             // invoke the no-tab crusade
 
         public void characters(char[] ch, int start, int length) throws XML.SchemaException {
             // invoke the no-tab crusade
index c6c6a47..196c445 100644 (file)
@@ -19,16 +19,14 @@ public class Trap {
     private static final Hash PROHIBITED = new Hash(120, 3);
 
     static {
     private static final Hash PROHIBITED = new Hash(120, 3);
 
     static {
-        // FIXME: review
         String[] p = new String[] {
         String[] p = new String[] {
-            "sizetoimage", "shrink", "hshrink", "vshrink", "x", "y",
-            "width", "height", "flex", "hflex", "vflex", "cols",
+            "shrink", "hshrink", "vshrink", "x", "y",
+            "width", "height", "flex", "colspan", "rowspan", "cols",
             "rows", "align", "invisible", "absolute", "globalx",
             "globaly", "minwidth", "minheight", "height", "width",
             "maxwidth", "maxheight", "numchildren", "hpad", "vpad",
             "rows", "align", "invisible", "absolute", "globalx",
             "globaly", "minwidth", "minheight", "height", "width",
             "maxwidth", "maxheight", "numchildren", "hpad", "vpad",
-            "doublebuffered", "cursor", "mousex", "mousey", "xwt",
-            "static", "mouseinside", "root", "thisbox", "indexof",
-            "path"
+            "buffered", "cursor", "mousex", "mousey",
+            "mouseinside", "thisbox", "indexof", "path", "font", "fontsize"
         };
         for(int i=0; i<p.length; i++) PROHIBITED.put(p[i], Boolean.TRUE);
     };
         };
         for(int i=0; i<p.length; i++) PROHIBITED.put(p[i], Boolean.TRUE);
     };
index 40fbb23..12c6466 100644 (file)
@@ -243,7 +243,6 @@ class XMLRPC extends JS.Callable {
             /*
         } else if (o instanceof org.xwt.js.Date) {
             sb.append("                <value><dateTime.iso8601>");
             /*
         } else if (o instanceof org.xwt.js.Date) {
             sb.append("                <value><dateTime.iso8601>");
-              FIXME
             org.xwt.js.Date d = (org.xwt.js.Date)o;
             Date d = new Date(nd.getRawTime());
             sb.append(d.getYear() + 1900);
             org.xwt.js.Date d = (org.xwt.js.Date)o;
             Date d = new Date(nd.getRawTime());
             sb.append(d.getYear() + 1900);
@@ -308,7 +307,7 @@ class XMLRPC extends JS.Callable {
             while ((s = br2.readLine()) != null) Log.log(this, "send: " + s);
         }
 
             while ((s = br2.readLine()) != null) Log.log(this, "send: " + s);
         }
 
-        HTTP.HTTPInputStream is = http.POST("text/xml", content);
+        InputStream is = http.POST("text/xml", content);
         try {
             BufferedReader br = !Log.verbose ?
                 new BufferedReader(new InputStreamReader(new Filter(is))) :
         try {
             BufferedReader br = !Log.verbose ?
                 new BufferedReader(new InputStreamReader(new Filter(is))) :
index f3368c4..22d20a9 100644 (file)
@@ -27,9 +27,6 @@ public final class XWT extends JS.Obj {
         else if (name.equals("control")) return Surface.control ? Boolean.TRUE : Boolean.FALSE;
         else if (name.equals("shift")) return Surface.shift ? Boolean.TRUE : Boolean.FALSE;
         else if (name.equals("clipboard")) return Platform.getClipBoard();
         else if (name.equals("control")) return Surface.control ? Boolean.TRUE : Boolean.FALSE;
         else if (name.equals("shift")) return Surface.shift ? Boolean.TRUE : Boolean.FALSE;
         else if (name.equals("clipboard")) return Platform.getClipBoard();
-        /* FIXME
-        else if (name.equals("static")) return .getStatic("");
-        */
         else if (name.equals("origin")) return Main.origin;
         else if (name.equals("maxdim")) return new Integer(Short.MAX_VALUE);
         else if (name.equals("altKeyName")) return Platform.altKeyName();
         else if (name.equals("origin")) return Main.origin;
         else if (name.equals("maxdim")) return new Integer(Short.MAX_VALUE);
         else if (name.equals("altKeyName")) return Platform.altKeyName();
@@ -86,7 +83,6 @@ public final class XWT extends JS.Obj {
 
         } else if (method.equals("date")) {
             if (checkOnly) return Boolean.TRUE;
 
         } else if (method.equals("date")) {
             if (checkOnly) return Boolean.TRUE;
-            // FIXME
             Log.log(XWT.class, "date not implemented");
             return null;
 
             Log.log(XWT.class, "date not implemented");
             return null;
 
@@ -120,13 +116,10 @@ public final class XWT extends JS.Obj {
             return null;
 
         } else if (method.equals("openFile")) {
             return null;
 
         } else if (method.equals("openFile")) {
-            //FIXME
-            /*
             if (checkOnly) return Boolean.TRUE;
             if (args.length() != 1) return null;
             String file = Platform.fileDialog(args.elementAt(0).toString(), false);
             if (checkOnly) return Boolean.TRUE;
             if (args.length() != 1) return null;
             String file = Platform.fileDialog(args.elementAt(0).toString(), false);
-            return file == null ? null : new ByteStream(file);
-            */
+            return file == null ? null : new Res.stringToResource("file:" + file);
 
         } else if (method.equals("saveFile")) {
             if (checkOnly) return Boolean.TRUE;
 
         } else if (method.equals("saveFile")) {
             if (checkOnly) return Boolean.TRUE;
@@ -213,9 +206,10 @@ public final class XWT extends JS.Obj {
             JS s = (JS)o;
             Object[] keys = s.keys();
             for(int i=0; i<keys.length; i++)
             JS s = (JS)o;
             Object[] keys = s.keys();
             for(int i=0; i<keys.length; i++)
-                recurse(indent + "  ", keys[i].toString(),
-                        (keys[i] instanceof Integer) ?
-                        s.get(((Integer)keys[i])) : s.get(keys[i].toString()));
+                if (keys[i] != null)
+                    recurse(indent + "  ", keys[i].toString(),
+                            (keys[i] instanceof Integer) ?
+                            s.get(((Integer)keys[i])) : s.get(keys[i].toString()));
 
         } else {
             Log.logJS(indent + name + o);
 
         } else {
             Log.logJS(indent + name + o);
index f76e29a..84b33d1 100644 (file)
@@ -5,8 +5,6 @@ import org.xwt.util.*;
 import java.io.*;
 import java.util.*;
 
 import java.io.*;
 import java.util.*;
 
-// FIXME: could use some cleaning up...
-
 /** A JavaScript Array */
 class ArrayImpl extends JS.Obj {
     private Vec vec = new Vec();
 /** A JavaScript Array */
 class ArrayImpl extends JS.Obj {
     private Vec vec = new Vec();
@@ -47,7 +45,7 @@ class ArrayImpl extends JS.Obj {
         }
         if(method.equals("unshift")) {
             if(justChecking) return Boolean.TRUE;
         }
         if(method.equals("unshift")) {
             if(justChecking) return Boolean.TRUE;
-            // FIXME: could be optimized a bit with some help from Vec
+            // FEATURE: could be optimized a bit with some help from Vec
             for(int i=0;i<args.length();i++)
                 vec.insertElementAt(args.elementAt(i),i);
             return new Integer(vec.size());
             for(int i=0;i<args.length();i++)
                 vec.insertElementAt(args.elementAt(i),i);
             return new Integer(vec.size());
index 87c527c..f118b76 100644 (file)
@@ -4,7 +4,6 @@ package org.xwt.js;
 import org.xwt.util.*;
 import java.io.*;
 
 import org.xwt.util.*;
 import java.io.*;
 
-// FIXME: could use some cleaning up
 /** a JavaScript function, compiled into bytecode */
 class CompiledFunctionImpl extends JS.Callable implements ByteCodes, Tokens {
 
 /** a JavaScript function, compiled into bytecode */
 class CompiledFunctionImpl extends JS.Callable implements ByteCodes, Tokens {
 
index f317d31..8fbd02d 100644 (file)
@@ -7,5 +7,4 @@ import java.util.*;
 
 /** a JavaScript Date object */
 class Date extends JS.Obj {
 
 /** a JavaScript Date object */
 class Date extends JS.Obj {
-    // FIXME: implement    
 }
 }
index ea12dfb..2ed9755 100644 (file)
@@ -51,8 +51,9 @@ public abstract class JS {
     public static Number toNumber(Object o) {
         if (o == null) return new Long(0);
         if (o instanceof Number) return ((Number)o);
     public static Number toNumber(Object o) {
         if (o == null) return new Long(0);
         if (o instanceof Number) return ((Number)o);
-        // FIXME: There are about 3 pages of rules in ecma262 about string to number conversions
-        // We aren't even close to following all those rules
+
+        // NOTE: There are about 3 pages of rules in ecma262 about string to number conversions
+        //       We aren't even close to following all those rules.  We probably never will be.
         if (o instanceof String) try { return new Double((String)o); } catch (NumberFormatException e) { return new Double(Double.NaN); }
         if (o instanceof Boolean) return ((Boolean)o).booleanValue() ? new Long(1) : new Long(0);
         if (o instanceof JS) return ((JS)o).coerceToNumber();
         if (o instanceof String) try { return new Double((String)o); } catch (NumberFormatException e) { return new Double(Double.NaN); }
         if (o instanceof Boolean) return ((Boolean)o).booleanValue() ? new Long(1) : new Long(0);
         if (o instanceof JS) return ((JS)o).coerceToNumber();
index dd77580..18c6aeb 100644 (file)
@@ -35,13 +35,21 @@ public class Regexp extends JS.Obj {
             _put("ignoreCase",wrapBool(flags & RE.REG_ICASE));
             _put("multiline",wrapBool(flags & RE.REG_MULTILINE));
         }
             _put("ignoreCase",wrapBool(flags & RE.REG_ICASE));
             _put("multiline",wrapBool(flags & RE.REG_MULTILINE));
         }
-        // FIXME: Do whatever we need to do to take advantage of the GETCALL bytecode when its available
-        final JS.Callable execFN = new JS.Callable() { public Object call(JS.Array args) { return exec(args); } };
-        final JS.Callable testFN = new JS.Callable() { public Object call(JS.Array args) { return test(args); } };
-        final JS.Callable toStringFN = new JS.Callable() { public Object call(JS.Array args) { return Regexp.this.toString(); } };
-        _put("exec",execFN);
-        _put("test",testFN);
-        _put("toString",toStringFN);
+    }
+
+    public Object callMethod(Object method, Array args, boolean checkOnly) throws JS.Exn {
+        if (method.equals("exec")) {
+            if (checkOnly) return Boolean.TRUE;
+            return exec(args);
+        } else if (method.equals("test")) {
+            if (checkOnly) return Boolean.TRUE;
+            return test(args);
+        } else if (method.equals("toString")) {
+            if (checkOnly) return Boolean.TRUE;
+            return toString();
+        }
+        if (checkOnly) return Boolean.FALSE;
+        return null;
     }
     
     // gcj bug...
     }
     
     // gcj bug...
index 6850927..6fe9be4 100644 (file)
@@ -20,9 +20,10 @@ public class AWT extends JVM {
     protected int _getScreenWidth() { return Toolkit.getDefaultToolkit().getScreenSize().width; }
     protected int _getScreenHeight() { return Toolkit.getDefaultToolkit().getScreenSize().height; }
     protected Surface _createSurface(Box b, boolean framed) { return new AWTSurface(b, framed); }
     protected int _getScreenWidth() { return Toolkit.getDefaultToolkit().getScreenSize().width; }
     protected int _getScreenHeight() { return Toolkit.getDefaultToolkit().getScreenSize().height; }
     protected Surface _createSurface(Box b, boolean framed) { return new AWTSurface(b, framed); }
-    protected boolean _supressDirtyOnResize() { return false; }
 
     protected void postInit() {
 
     protected void postInit() {
+        System.setProperty("com.apple.mrj.application.live-resize", "true");
+        System.setProperty("com.apple.mrj.application.growbox.intrudes", "false");
         if (Log.on) Log.log(Platform.class, "               color depth = " + Toolkit.getDefaultToolkit().getColorModel().getPixelSize() + "bpp");
     }
 
         if (Log.on) Log.log(Platform.class, "               color depth = " + Toolkit.getDefaultToolkit().getColorModel().getPixelSize() + "bpp");
     }
 
@@ -108,7 +109,7 @@ public class AWT extends JVM {
         final Semaphore s = new Semaphore();
         FileDialogHelper fd = new FileDialogHelper(suggestedFileName, s, write);
         s.block();
         final Semaphore s = new Semaphore();
         FileDialogHelper fd = new FileDialogHelper(suggestedFileName, s, write);
         s.block();
-        return fd.getDirectory() + File.separatorChar + fd.getFile();
+        return fd.getDirectory() == null ? null : (fd.getDirectory() + File.separatorChar + fd.getFile());
     }
 
 
     }
 
 
@@ -181,7 +182,12 @@ public class AWT extends JVM {
 
         public void blit(PixelBuffer s, int sx, int sy, int dx, int dy, int dx2, int dy2) {
             if (ourGraphics == null) ourGraphics = window.getGraphics();
 
         public void blit(PixelBuffer s, int sx, int sy, int dx, int dy, int dx2, int dy2) {
             if (ourGraphics == null) ourGraphics = window.getGraphics();
-            ourGraphics.drawImage(((AWTPixelBuffer)s).i, dx + insets.left, dy + insets.top, dx2 + insets.left, dy2 + insets.top,
+            insets = (frame == null ? window : frame).getInsets();
+            ourGraphics.drawImage(((AWTPixelBuffer)s).i,
+                                  dx + insets.left,
+                                  dy + insets.top,
+                                  dx2 + insets.left,
+                                  dy2 + insets.top,
                                   sx, sy, sx + (dx2 - dx), sy + (dy2 - dy), null);
         }
         
                                   sx, sy, sx + (dx2 - dx), sy + (dy2 - dy), null);
         }
         
@@ -314,7 +320,7 @@ public class AWT extends JVM {
         public void windowDeiconified(WindowEvent e) { dirty(0, 0, root.width, root.height); Minimized(false); }
         public void windowActivated(WindowEvent e) { Focused(true); }
         public void windowDeactivated(WindowEvent e) { Focused(false); }
         public void windowDeiconified(WindowEvent e) { dirty(0, 0, root.width, root.height); Minimized(false); }
         public void windowActivated(WindowEvent e) { Focused(true); }
         public void windowDeactivated(WindowEvent e) { Focused(false); }
-    public void componentMoved(ComponentEvent e) { PosChange(window.getLocation().x + insets.left, window.getLocation().y + insets.top); }
+        public void componentMoved(ComponentEvent e) { PosChange(window.getLocation().x + insets.left, window.getLocation().y + insets.top); }
 
         public void componentResized(ComponentEvent e) {
             // we have to periodically do this; I don't know why
 
         public void componentResized(ComponentEvent e) {
             // we have to periodically do this; I don't know why
@@ -374,7 +380,7 @@ public class AWT extends JVM {
             case KeyEvent.VK_F3: return "f3";
             case KeyEvent.VK_F4: return "f4";
             case KeyEvent.VK_F5: return "f5";
             case KeyEvent.VK_F3: return "f3";
             case KeyEvent.VK_F4: return "f4";
             case KeyEvent.VK_F5: return "f5";
-            case KeyEvent.VK_F6: return "f6";
+            case KeyEvent.VK_F6: return "f6"; 
             case KeyEvent.VK_F7: return "f7";
             case KeyEvent.VK_F8: return "f8";
             case KeyEvent.VK_F9: return "f9";
             case KeyEvent.VK_F7: return "f7";
             case KeyEvent.VK_F8: return "f8";
             case KeyEvent.VK_F9: return "f9";