2003/10/20 01:41:22
authormegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:39:51 +0000 (07:39 +0000)
committermegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:39:51 +0000 (07:39 +0000)
darcs-hash:20040130073951-2ba56-335d7526c056c4b92be6c508462ed255927b2aa5.gz

src/org/xwt/Res.java
src/org/xwt/builtin/splash.xwt

index 896220b..4a8c7ed 100644 (file)
@@ -21,8 +21,30 @@ public abstract class Res extends JS {
 
     public Res getParent() { return null; }
 
+    /** an InputStream that makes sure it is not in the MessageQueue when blocked on a read */
+    private static class BackgroundInputStream extends FilterInputStream {
+        BackgroundInputStream(InputStream i) { super(i); }
+        private void suspend() throws IOException {
+            if (!ThreadMessage.suspendThread())
+                throw new IOException("attempt to perform background-only operation in a foreground thread");
+        }
+        private void resume() {
+            ThreadMessage.resumeThread();
+        }
+        public int read() throws IOException {
+            suspend();
+            try { return super.read(); }
+            finally { resume(); }
+        }
+        public int read(byte[] b, int off, int len) throws IOException {
+            suspend();
+            try { return super.read(b, off, len); }
+            finally { resume(); }
+        }
+    }
+
     /** returns an InputStream containing the Resource's contents */
-    public InputStream getInputStream() throws IOException { return getInputStream(""); }
+    public final InputStream getInputStream() throws IOException { return new BackgroundInputStream(getInputStream("")); }
     public abstract InputStream getInputStream(String path) throws IOException;
 
     /** graft newResource in place of this resource on its parent */
@@ -100,16 +122,6 @@ public abstract class Res extends JS {
             return new FileInputStream((path + rest).replace('/', java.io.File.separatorChar)); }
     }
 
-    /** wrap a Res around a preexisting InputStream */
-    public static class IS extends Res {
-        InputStream parent;
-        IS(InputStream parent) { this.parent = parent; }
-        public InputStream getInputStream(String path) {
-            if (!"".equals(path)) throw new JS.Exn("can't access subresources of IS");
-            return parent;
-        }
-    }
-
     /** "unwrap" a Zip archive */
     public static class Zip extends Res {
         private Res parent;
@@ -119,7 +131,7 @@ public abstract class Res extends JS {
             ZipInputStream zis = new ZipInputStream(parent.getInputStream());
             ZipEntry ze = zis.getNextEntry();
             while(ze != null && !ze.getName().equals(path)) ze = zis.getNextEntry();
-            if (ze == null) throw new JS.Exn("requested file not found in archive");
+            if (ze == null) throw new JS.Exn("requested file (" + path + ") not found in archive");
             return zis;
         }
     }
index dcbc66c..32ceb4c 100644 (file)
@@ -1,66 +1,35 @@
 <xwt>
 
-    <template thisbox="window" orient="vertical">
+    <template thisbox="window" orient="vertical" width="394" height="276">
 
-        minwidth = maxwidth = $inner.width;
-        minheight = maxheight = $inner.height;
-        x = (xwt.screenWidth - width) / 2;
-        y = (xwt.screenHeight - height) / 2;
+        KeyPressed += function(k) { if (k == "escape") thisbox = null; }
 
-        _KeyPressed = function(k) {
-            if (k == "escape") thisbox = null;
+        var progress = function(n, d) {
+            xwt.println("loaded " + 100 * (n/d) + "%");
+            $innerbar.width = $bar.width * n / d;
         }
 
         xwt.thread = function() {
-            try {
-                var origin = xwt.origin;
-                if (origin.substring(0, 21) == "http://launch.xwt.org") {
-                    origin = origin.substring(22);
-                    origin = "http://" + origin.substring(origin.indexOf('/') + 1);
-                }
-                xwt.println("origin is " + origin);
-    
-                xwt.loadArchive(origin, function(num, den) {
-                        $left.flex = 50 * (num / den);
-                        $right.flex = 50 + 50 * (1.0 - num /den);
-                        var pct = xwt.math.ceil(num * 100 / den);
-                        if (1024 > num) {
-                            num = "" + num + " bytes";
-                        } else if (1024 * 1024 > num) {
-                            num = "" + xwt.math.ceil(num / 1024) + "kb";
-                        } else {
-                            num = "" + xwt.math.ceil(num / (1024 * 1024)) + "Mb";
-                        }
-                        $status.text = "Downloading: " + pct + "% [" + num + "]";
-                    });
-    
-                    xwt.newBox().apply("main", function(num, den) {
-                        $left.flex = 50 + 50 * (num / den);
-                        $right.flex = 50 * (1.0 - num / den);
-                        if ($right.flex == 0) $right.width = 0;
-                        $status.text = "Initializing: " + xwt.math.ceil(num * 100 / den) + "%";
-                    });
-                    thisbox = null;
-
-            } catch (e) {
-                $status.text = "Error: " + e;
-                if ($status.text.substring(0, 13) == "Error: Error:") {
-                    $status.text = $status.text.substring(7) +
-                                   " (press Esc to quit)";
-                }
+            var img = xwt.org.xwt.builtin["splash.png"];
+            xwt.println("img is");
+            xwt.println(img);
+            fill = img;
+            xwt.yield();
+            x = (xwt.screenWidth - width) / 2;
+            y = (xwt.screenHeight - height) / 2;
+            var origin = xwt.origin;
+            if (origin.substring(0, 21) == "http://launch.xwt.org") {
+                origin = origin.substring(22);
+                origin = "http://" + origin.substring(origin.indexOf('/') + 1);
             }
-
+            xwt.println("origin is " + origin);
+            var new_rr = xwt.watchProgress(xwt.load(origin), progress);
+            var new_xwt = xwt.clone(new_rr);
         }
 
-        <box absolute="true" sizetoimage="true" id="inner" image="org.xwt.builtin.lithium"/>
-
-        <box/>
-        <box text="Downloading user interface..." vshrink="true" hpad="4" vpad="3" id="status" textcolor="white"/>
-        <box hpad="4" height="10">
-            <box flex="0.0" image="org.xwt.builtin.progress" tile="true" id="left"/>
-            <box flex="100.0" id="right"/>
+        <box packed="false" id="bar" x="20" y="236" width="354" height="19" align="left">
+            <box id="innerbar" fill="blue" width="0"/>
         </box>
-        <box height="5"/>
 
     </template>