2003/10/25 07:50:20
authormegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:40:01 +0000 (07:40 +0000)
committermegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:40:01 +0000 (07:40 +0000)
darcs-hash:20040130074001-2ba56-a8ddded92fda0b881fc54a7ec1d3ff335ca5cd95.gz

src/org/xwt/Box.java.pp
src/org/xwt/HTTP.java
src/org/xwt/Res.java
src/org/xwt/XWT.java
src/org/xwt/builtin/splash.xwt

index 9699421..2df28b0 100644 (file)
@@ -1182,13 +1182,14 @@ public final class Box extends JS.Scope {
             specialBoxProperties.put("width", new SpecialBoxProperty() {
                     public Object get(Box b) { return new Integer(b.width); }
                     public void put(Box b, Object value) {
-                        b.width = stoi(value);
+                        int width = stoi(value);
                         if (b.parent == null && b.surface != null) {
+                            b.width = width;
                             b.surface.setSize();
                             MARK_FOR_REFLOW_b;
                         } else {
-                            if (b.minwidth == b.width && b.maxwidth == b.width) return;
-                            b.minwidth = b.maxwidth = b.width;
+                            if (b.minwidth == width && b.maxwidth == width) return;
+                            b.minwidth = b.maxwidth = width;
                             MARK_FOR_REFLOW_b;
                         }
                     } });
index 2980ed5..3bd0a6b 100644 (file)
@@ -498,7 +498,7 @@ public class HTTP {
     // HTTPInputStream ///////////////////////////////////////////////////////////////////////////////////
 
     /** An input stream that represents a subset of a longer input stream. Supports HTTP chunking as well */
-    public class HTTPInputStream extends FilterInputStream {
+    public class HTTPInputStream extends FilterInputStream implements KnownLength {
 
         /** if chunking, the number of bytes remaining in this subset; otherwise the remainder of the chunk */
         private int length = 0;
@@ -523,6 +523,7 @@ public class HTTP {
             this.length = length == -1 ? 0 : length;
         }
 
+        public int getLength() { return contentLength; }
         public boolean markSupported() { return false; }
         public int read(byte[] b) throws IOException { return read(b, 0, b.length); }
         public long skip(long n) throws IOException { return read(null, -1, (int)n); }
index 60a9437..3f34f82 100644 (file)
@@ -69,9 +69,12 @@ public abstract class Res extends JS {
     }
 
     public static Res stringToRes(String url) {
-        if (url.indexOf('!') != -1)
-            return (Res)(new Zip(stringToRes(url.substring(0, url.lastIndexOf('!')))).
-                         get(url.substring(url.lastIndexOf('!') + 1)));
+        if (url.indexOf('!') != -1) {
+            Res ret = new Zip(stringToRes(url.substring(0, url.lastIndexOf('!'))));
+            String subpath = url.substring(url.lastIndexOf('!') + 1);
+            if (subpath.length() > 0) ret = (Res)ret.get(subpath);
+            return ret;
+        }
         if (url.startsWith("http://")) return new HTTP(url);
         if (url.startsWith("https://")) return new HTTP(url);
         if (url.startsWith("cab:")) return new CAB(stringToRes(url.substring(4)));
@@ -130,7 +133,7 @@ public abstract class Res extends JS {
             ZipEntry ze = zis.getNextEntry();
             while(ze != null && !ze.getName().equals(path)) ze = zis.getNextEntry();
             if (ze == null) throw new JS.Exn("requested file (" + path + ") not found in archive");
-            return zis;
+            return new KnownLength.KnownLengthInputStream(zis, (int)ze.getSize());
         }
     }
 
@@ -180,11 +183,12 @@ public abstract class Res extends JS {
 
     /** shadow resource which replaces the graft */
     public static class ProgressWatcher extends Res {
-        Res watchee;
+        final Res watchee;
         JS.Callable callback;
         ProgressWatcher(Res watchee, JS.Callable callback) { this.watchee = watchee; this.callback = callback; }
         public InputStream getInputStream(String s) throws IOException {
-            return new FilterInputStream(watchee.getInputStream(s)) {
+            final InputStream is = watchee.getInputStream(s);
+            return new FilterInputStream(is) {
                     int bytesDownloaded = 0;
                     public int read() throws IOException {
                         int ret = super.read();
@@ -197,6 +201,7 @@ public abstract class Res extends JS {
                         ThreadMessage.newthread(new JS.Callable() { public Object call(JS.Array a) {
                             JS.Array args = new JS.Array();
                             args.addElement(new Integer(bytesDownloaded));
+                            args.addElement(new Integer(is instanceof KnownLength ? ((KnownLength)is).getLength() : 0));
                             callback.call(args);
                             return null;
                         } });
index 3c4d99f..9738c06 100644 (file)
@@ -80,6 +80,10 @@ public final class XWT extends JS.Obj {
                 return new Res.Graft((Res)args.elementAt(0), args.elementAt(1), args.elementAt(2));
             return new JS.Graft((JS)args.elementAt(0), args.elementAt(1), args.elementAt(2));
 
+        } else if (method.equals("unzip")) {
+            if (checkOnly) return Boolean.TRUE;
+            return new Res.Zip((Res)args.elementAt(0));
+
         } else if (method.equals("watchProgress")) {
             if (checkOnly) return Boolean.TRUE;
             return new Res.ProgressWatcher((Res)args.elementAt(0), (JS.Callable)args.elementAt(1));
@@ -108,6 +112,12 @@ public final class XWT extends JS.Obj {
             if (checkOnly) return Boolean.TRUE;
             return new Regexp(args);
 
+        } else if (method.equals("apply")) {
+            if (checkOnly) return Boolean.TRUE;
+            Box b = (Box)args.elementAt(0);
+            Template.getTemplate((Res)args.elementAt(1)).apply(b, null, this);
+            return b;
+
         } else if (method.equals("xmlrpc")) {
             if (checkOnly) return Boolean.TRUE;
             if (args.length() != 1 || args.elementAt(0) == null) return null;
index 32ceb4c..9d6ef80 100644 (file)
@@ -5,14 +5,12 @@
         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.yield();
         }
 
         xwt.thread = function() {
             var img = xwt.org.xwt.builtin["splash.png"];
-            xwt.println("img is");
-            xwt.println(img);
             fill = img;
             xwt.yield();
             x = (xwt.screenWidth - width) / 2;
                 origin = "http://" + origin.substring(origin.indexOf('/') + 1);
             }
             xwt.println("origin is " + origin);
-            var new_rr = xwt.watchProgress(xwt.load(origin), progress);
+            var new_rr = xwt.unzip(xwt.watchProgress(xwt.load(origin), progress));
             var new_xwt = xwt.clone(new_rr);
+            new_xwt.apply(xwt.box, new_xwt["main.xwt"]);
         }
 
-        <box packed="false" id="bar" x="20" y="236" width="354" height="19" align="left">
-            <box id="innerbar" fill="blue" width="0"/>
+        <box packed="false" id="bar" x="20" y="236" width="354" height="18" align="left">
+            <box id="innerbar" fill="blue" width="10"/>
         </box>
 
     </template>