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;
}
} });
// 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;
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); }
}
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)));
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());
}
}
/** 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();
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;
} });
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));
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;
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>