From: megacz Date: Fri, 30 Jan 2004 07:36:14 +0000 (+0000) Subject: 2003/09/24 07:33:32 X-Git-Tag: RC3~585 X-Git-Url: http://git.megacz.com/?p=org.ibex.core.git;a=commitdiff_plain;h=8235361e8601ae7b36ab707058de3b52225d15a2 2003/09/24 07:33:32 darcs-hash:20040130073614-2ba56-e37e59fe20ff2db5cc28fe75aff03e818a4f88d9.gz --- diff --git a/Makefile b/Makefile index d3a6b13..e38b4c2 100644 --- a/Makefile +++ b/Makefile @@ -68,16 +68,18 @@ build/class/%.class: build/java/%.java .jikes mkdir -p build/class ./.jikes $< +# this forces a clean build every time because jikes is so damn buggy compile: .compile -.compile: $(all_java_sources) +.compile: $(all_java_sources) .jikes @echo -e "\n\033[1mcompiling .java -> .class: src/**/*.java\033[0m" + rm -rf 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) -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 |\ @@ -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) -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 diff --git a/src/edu/stanford/ejalbert/BrowserLauncher.java b/src/edu/stanford/ejalbert/BrowserLauncher.java new file mode 100644 index 0000000..0e2b856 --- /dev/null +++ b/src/edu/stanford/ejalbert/BrowserLauncher.java @@ -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. + *

+ * 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. + *

+ * 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. + *

+ * 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. + *

+ * 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. + *

+ * Credits: + *
Steven Spencer, JavaWorld magazine (Java Tip 66) + *
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 (ejalbert@cs.stanford.edu) + * @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. + *

+ * Note that if this is false, openURL() 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 (int) method of com.apple.MacOS.AETarget */ + private static Constructor aeTargetConstructor; + + /** The (int, int, int) method of com.apple.MacOS.AppleEvent */ + private static Constructor appleEventConstructor; + + /** The (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 true if all intialization succeeded + * false 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 . + 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); +} diff --git a/src/org/xwt/Box.java.pp b/src/org/xwt/Box.java.pp index 554b287..f18182c 100644 --- a/src/org/xwt/Box.java.pp +++ b/src/org/xwt/Box.java.pp @@ -102,10 +102,10 @@ public final class Box extends JS.Scope { //#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; @@ -137,7 +137,7 @@ public final class Box extends JS.Scope { //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 @@ -196,10 +196,11 @@ public final class Box extends JS.Scope { // Reflow //////////////////////////////////////////////////////////////////////////////////////// - void reflow() { + void reflow() { reflow(width, height); } + void reflow(int new_width, int new_height) { 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 */ @@ -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) { @@ -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 (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; } @@ -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 - 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; - 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); @@ -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) { + //if (image != null) System.out.println("hit"); if (value == null) { b.image = null; } else if (value instanceof Res) { diff --git a/src/org/xwt/HTTP.java b/src/org/xwt/HTTP.java index 19fc41c..50c71c9 100644 --- a/src/org/xwt/HTTP.java +++ b/src/org/xwt/HTTP.java @@ -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"); - // FIXME: handle chunking extensions + // FEATURE: handle chunking extensions 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()); - // FIXME - //XWT.recursivePrintObject.call(); } 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(); - /* 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); - */ } }); @@ -804,12 +801,10 @@ public class HTTP { // ProxyAutoConfigRootScope //////////////////////////////////////////////////////////////////// - public static class ProxyAutoConfigRootScope extends JS.Scope { + public static class ProxyAutoConfigRootScope extends JS.GlobalScope { 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; diff --git a/src/org/xwt/Message.java b/src/org/xwt/Message.java index 8162f0c..c8d60cc 100644 --- a/src/org/xwt/Message.java +++ b/src/org/xwt/Message.java @@ -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); - // 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"); } diff --git a/src/org/xwt/Platform.java b/src/org/xwt/Platform.java index accf069..9216dcb 100644 --- a/src/org/xwt/Platform.java +++ b/src/org/xwt/Platform.java @@ -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:"))) { @@ -249,9 +258,6 @@ public class Platform { 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) { @@ -269,14 +275,12 @@ public class Platform { Object titlebar = b.get("titlebar", true); if (titlebar != null) ret.setTitleBarText(titlebar.toString()); - /* FIXME 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); } - */ ret.setLimits(b.minwidth, b.minheight, b.maxwidth, b.maxheight); diff --git a/src/org/xwt/Res.java b/src/org/xwt/Res.java index 20858e6..77b502b 100644 --- a/src/org/xwt/Res.java +++ b/src/org/xwt/Res.java @@ -43,12 +43,13 @@ public abstract class Res extends JS { 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.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"); } @@ -70,7 +71,6 @@ public abstract class Res extends JS { } } - // FIXME: dangerous /** a file */ public static class File extends Res { private String path; diff --git a/src/org/xwt/SOAP.java b/src/org/xwt/SOAP.java index debbc24..2771304 100644 --- a/src/org/xwt/SOAP.java +++ b/src/org/xwt/SOAP.java @@ -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; - + // add a generic struct; we'll change this if our type is different objects.addElement(new JS.Obj()); diff --git a/src/org/xwt/Surface.java b/src/org/xwt/Surface.java index 922f2e3..089480e 100644 --- a/src/org/xwt/Surface.java +++ b/src/org/xwt/Surface.java @@ -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. */ +// FIXME: put the scar box back in 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; - /** 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 @@ -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; - root.width = width; - root.height = height; root.needs_reflow = true; + root.reflow(width, height); }}); 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() { - 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); - scarBox.x = 0; - scarBox.y = root.height - scarBox.minheight; } /** Indicates that the Surface is no longer needed */ @@ -277,14 +271,8 @@ public abstract class Surface extends PixelBuffer { } public Surface(Box 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; @@ -296,11 +284,6 @@ public abstract class Surface extends PixelBuffer { 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() { @@ -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; - paintRegion(x, y, w, h); + root.render(0, 0, x, y, w, h, this); if (abort) { @@ -370,29 +353,17 @@ public abstract class Surface extends PixelBuffer { 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) { + 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) { + screenDirtyRegions.dirty(x1, y1, x2 - x1, y2 - y1); 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(); diff --git a/src/org/xwt/Template.java b/src/org/xwt/Template.java index 363886c..95846c1 100644 --- a/src/org/xwt/Template.java +++ b/src/org/xwt/Template.java @@ -149,8 +149,10 @@ public class Template { } for (int i=0; children != null && i 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; - + } 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) { // templateNodeHasBeenFinished = true; - + } 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); } - } - } - - 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 diff --git a/src/org/xwt/Trap.java b/src/org/xwt/Trap.java index c6c6a47..196c445 100644 --- a/src/org/xwt/Trap.java +++ b/src/org/xwt/Trap.java @@ -19,16 +19,14 @@ public class Trap { private static final Hash PROHIBITED = new Hash(120, 3); static { - // FIXME: review 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", - "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"); - FIXME 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); } - 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))) : diff --git a/src/org/xwt/XWT.java b/src/org/xwt/XWT.java index f3368c4..22d20a9 100644 --- a/src/org/xwt/XWT.java +++ b/src/org/xwt/XWT.java @@ -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(); - /* 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(); @@ -86,7 +83,6 @@ public final class XWT extends JS.Obj { } else if (method.equals("date")) { if (checkOnly) return Boolean.TRUE; - // FIXME 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")) { - //FIXME - /* 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; @@ -213,9 +206,10 @@ public final class XWT extends JS.Obj { JS s = (JS)o; Object[] keys = s.keys(); for(int i=0; i