X-Git-Url: http://git.megacz.com/?p=org.ibex.core.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fcore%2FIbex.java;fp=src%2Forg%2Fibex%2Fcore%2FIbex.java;h=4110a8ddcb0f9f0388a0979c0aa1ab133041ffee;hp=bd133c7c611f2b5ffe5641ddb44440c2cfaa3fa7;hb=890000a10a0ccdc49f62946bddf1c0b840495a94;hpb=1de73c721bbd73f275ba85de292463cdd8a0fbc0 diff --git a/src/org/ibex/core/Ibex.java b/src/org/ibex/core/Ibex.java index bd133c7..4110a8d 100644 --- a/src/org/ibex/core/Ibex.java +++ b/src/org/ibex/core/Ibex.java @@ -19,7 +19,7 @@ public final class Ibex extends JS.Obj implements JS.Cloneable { private final JS rr; private static final JS.Method METHOD = new JS.Method(); - public Ibex(Stream rr) { try { this.rr = bless(rr);} catch(JSExn e) { throw new Error("should never happen: " + e); } } + public Ibex(Fountain rr) { try { this.rr = bless(rr);} catch(JSExn e) { throw new Error("should never happen: " + e); } } public JS resolveString(String str, boolean permitAbsolute) throws JSExn { if (str.indexOf("://") != -1) { @@ -132,7 +132,7 @@ public final class Ibex extends JS.Obj implements JS.Cloneable { public void put(JS name, JS value) throws JSExn { //#switch(JSU.toString(name)) - case "thread": Scheduler.add((Callable)value); return; + case "thread": Platform.Scheduler.add((Callable)value); return; case "ui.clipboard": Platform.setClipBoard(JSU.toString(value)); return; case "ui.frame": Platform.createSurface((Box)value, true, true); return; case "ui.window": Platform.createSurface((Box)value, false, true); return; @@ -173,17 +173,17 @@ public final class Ibex extends JS.Obj implements JS.Cloneable { return new JS.Clone((JS)args[0]); case "bless": return bless((JS)args[0]); case "ui.browser": Platform.newBrowserWindow(JSU.toString(args[0])); return null; - case "stream.unzip": return args[0] == null ? null : new Stream.Zip((Stream)args[0]); + case "stream.unzip": return args[0] == null ? null : new Fountain.Zip((Fountain)args[0]); //case "stream.uncab": return a == null ? null : new Stream.Cab(a); case "stream.cache": - try { return args[0] == null ? null : new Stream.CachedStream((Stream)args[0], "resources", true); } - catch (Stream.NotCacheableException e) { throw new JSExn("this resource cannot be cached"); } + //try { return args[0] == null ? null : new Fountain.CachedStream((Stream)args[0], "resources", true); } + //catch (Stream.NotCacheableException e) { throw new JSExn("this resource cannot be cached"); } case "stream.url": { String url = JSU.toString(args[0]); - if (url.startsWith("http://")) return new Stream.HTTP(url); - else if (url.startsWith("https://")) return new Stream.HTTP(url); - else if (url.startsWith("data:")) return new Stream.ByteArray(Encode.fromBase64(url.substring(5)), null); - else if (url.startsWith("utf8:")) return new Stream.ByteArray(url.substring(5).getBytes(), null); + if (url.startsWith("http://")) return new Fountain.HTTP(url); + else if (url.startsWith("https://")) return new Fountain.HTTP(url); + else if (url.startsWith("data:")) return new Fountain.ByteArray(Encode.fromBase64(url.substring(5)), null); + else if (url.startsWith("utf8:")) return new Fountain.ByteArray(url.substring(5).getBytes(), null); else if (url.startsWith("file:")) { // FIXME Platform.fileDialog(url.substring(5), false); @@ -207,7 +207,15 @@ public final class Ibex extends JS.Obj implements JS.Cloneable { break; case 2: //#switch(JSU.toString(method)) - case "stream.watch": return new Stream.ProgressWatcher((Stream)args[0], args[1]); + case "stream.watch": + final JS func = args[1]; + return new Fountain.ProgressWatcher((Fountain)args[0], + new Callable() { + public Object run(Object o) throws Exception { + JS[] args = (JS[])o; + return func.call(null, args); + } + }); case "regexp": return new JSRegexp(args[0], args[1]); //#end case 3: @@ -228,10 +236,10 @@ public final class Ibex extends JS.Obj implements JS.Cloneable { } public JS url2res(String url) throws JSExn { - if (url.startsWith("http://")) return new Stream.HTTP(url); - else if (url.startsWith("https://")) return new Stream.HTTP(url); - else if (url.startsWith("data:")) return new Stream.ByteArray(Encode.fromBase64(url.substring(5)), null); - else if (url.startsWith("utf8:")) return new Stream.ByteArray(url.substring(5).getBytes(), null); + if (url.startsWith("http://")) return new Fountain.HTTP(url); + else if (url.startsWith("https://")) return new Fountain.HTTP(url); + else if (url.startsWith("data:")) return new Fountain.ByteArray(Encode.fromBase64(url.substring(5)), null); + else if (url.startsWith("utf8:")) return new Fountain.ByteArray(url.substring(5).getBytes(), null); else throw new JSExn("invalid resource specifier " + url); // FIXME support file:// via dialog boxes } @@ -242,7 +250,7 @@ public final class Ibex extends JS.Obj implements JS.Cloneable { // FEATURE use a single sleeper thread new Thread() { public void run() { try { Thread.sleep(i); } catch (InterruptedException e) { } - Scheduler.add(callback); + Platform.Scheduler.add(callback); } }.start(); } catch (Pausable.NotPausableException npe) { throw new JSExn("you cannot sleep or yield in the foreground thread"); @@ -368,7 +376,7 @@ public final class Ibex extends JS.Obj implements JS.Cloneable { public JS parentkey = null; public Blessing parent = null; public JS clonee; - private Basket.Map cache = new Basket.HashMap(); + private Basket.Map cache = new Basket.Hash(); public Blessing(JS clonee, Ibex ibex, Blessing parent, JS parentkey) throws JSExn { this.clonee = clonee; this.ibex = ibex; this.parentkey = parentkey; this.parent = parent; } public JS get(JS key) throws JSExn { @@ -386,16 +394,16 @@ public final class Ibex extends JS.Obj implements JS.Cloneable { } // FEATURE: This is a gross hack public InputStream getImage() throws JSExn { - //try { + try { InputStream in = JSU.getInputStream(this); if (in != null) return in; - //} catch (IOException e) { /* DELIBERATE */ } + } catch (IOException e) { /* DELIBERATE */ } String[] exts = new String[] { ".png", ".jpeg", ".gif" }; for (int i=0; i < exts.length; i++) { - //try { - in = JSU.getInputStream(parent.get(JSU.S(JSU.toString(parentkey) + exts[i]))); + try { + InputStream in = JSU.getInputStream(parent.get(JSU.S(JSU.toString(parentkey) + exts[i]))); if (in != null) return in; - //} catch (IOException f) { /* DELIBERATE */ } + } catch (IOException f) { /* DELIBERATE */ } } return null; }