2003/10/31 09:50:08
[org.ibex.core.git] / src / org / xwt / Platform.java
index 850e1dc..5b1f0ac 100644 (file)
@@ -34,7 +34,7 @@ public class Platform {
     static boolean alreadyDetectedProxy = false;
 
     /** the result of proxy autodetection */
-    static HTTP.Proxy cachedProxyInfo = null;
+    static org.xwt.HTTP.Proxy cachedProxyInfo = null;
 
     /** the current build */
     public static String build = "unknown";
@@ -66,10 +66,9 @@ public class Platform {
             else if (!version.startsWith("1.0") && !version.startsWith("1.1")) platform_class = "Java2";
 
             /*
-        // Disable 2d hardware acceleration on Jaguar
-        if (os_name.equals("Mac OS X") && os_version.equals("10.2"))
+            // Disable 2d hardware acceleration on Jaguar
+            if (os_name.equals("Mac OS X") && os_version.startsWith("10.2")) System.setProperty("com.apple.hwaccel", "false");
             */
-        System.setProperty("com.apple.hwaccel", "false");
 
             if (platform_class != null) {
                 platform = (Platform)Class.forName("org.xwt.plat." + platform_class).newInstance();
@@ -124,7 +123,14 @@ public class Platform {
     
     /** creates and returns a picture */
     public static Picture createPicture(int[] data, int w, int h) { return platform._createPicture(data, w, h); }
+    public static Picture createAlphaOnlyPicture(byte[] data, int w, int h) { return platform._createAlphaOnlyPicture(data, w, h); }
+    
     protected Picture _createPicture(int[] b, int w, int h) { return null; }
+    protected Picture _createAlphaOnlyPicture(byte[] b, int w, int h) {
+        int[] b2 = new int[b.length];
+        for(int i=0;i<b.length;i++) b2[i] = (b[i]&0xff) << 24;
+        return _createPicture(b2,w,h);
+    }
 
     /** creates a socket object */
     public static Socket getSocket(String host, int port, boolean ssl, boolean negotiate) throws IOException {
@@ -221,11 +227,18 @@ public class Platform {
     /** displays a platform-specific "open file" dialog and returns the chosen filename, or null if the user hit cancel */
     protected String _fileDialog(String suggestedFileName, boolean write) { return null; }
     public static String fileDialog(String suggestedFileName, boolean write) {
-        if (!ThreadMessage.suspendThread()) return null;
+        // FIXME: put self in background
+        return platform._fileDialog(suggestedFileName, write);
+    }
+
+    /** default implementation is Eric Albert's BrowserLauncher.java */
+    protected void _newBrowserWindow(String url) {
         try {
-            return platform._fileDialog(suggestedFileName, write);
-        } finally {
-            ThreadMessage.resumeThread();
+            Class c = Class.forName("edu.stanford.ejalbert.BrowserLauncher");
+            Method m = c.getMethod("openURL", new Class[] { String.class });
+            m.invoke(null, new String[] { url });
+        } catch (Exception e) {
+            Log.log(this, e);
         }
     }
 
@@ -249,9 +262,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) {
@@ -264,21 +274,20 @@ public class Platform {
     protected Surface _createSurface(Box b, boolean framed) { return null; }
     public static Surface createSurface(Box b, boolean framed, boolean refreshable) {
         Surface ret = platform._createSurface(b, framed);
-        b.width = b.height < Surface.scarPicture.getWidth() ? Surface.scarPicture.getWidth() : b.width;
-        b.height = b.height < Surface.scarPicture.getHeight() ? Surface.scarPicture.getHeight() : b.height;
         ret.setInvisible(false);
 
         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) {
+            /*
+              FIXME
+            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);
 
@@ -291,15 +300,15 @@ public class Platform {
     }
 
     /** detects proxy settings */
-    protected synchronized HTTP.Proxy _detectProxy() { return null; }
-    public static synchronized HTTP.Proxy detectProxy() {
+    protected synchronized org.xwt.HTTP.Proxy _detectProxy() { return null; }
+    public static synchronized org.xwt.HTTP.Proxy detectProxy() {
 
         if (cachedProxyInfo != null) return cachedProxyInfo;
         if (alreadyDetectedProxy) return null;
         alreadyDetectedProxy = true;
 
         if (Log.on) Log.log(Platform.class, "attempting environment-variable DNS proxy detection");
-        cachedProxyInfo = HTTP.Proxy.detectProxyViaManual();
+        cachedProxyInfo = org.xwt.HTTP.Proxy.detectProxyViaManual();
         if (cachedProxyInfo != null) return cachedProxyInfo;
 
         if (Log.on) Log.log(Platform.class, "attempting " + platform.getClass().getName() + " proxy detection");
@@ -308,7 +317,9 @@ public class Platform {
 
         return cachedProxyInfo;
     }
-
+    
+    public static void running() { platform._running(); }
+    public void _running() { new Semaphore().block(); }
 }