From 586485c446bc6870e08cfca8675a41442cca2c54 Mon Sep 17 00:00:00 2001 From: adam Date: Fri, 7 Jan 2005 13:20:13 +0000 Subject: [PATCH] partial update of core for new js stuff darcs-hash:20050107132013-5007d-1f77d365a3cbe54f8eb0b2ea2dcee9590c81679b.gz --- src/org/ibex/core/Box.java | 208 ++++++++++++++++++------------------ src/org/ibex/core/Ibex.java | 107 ++++++++++--------- src/org/ibex/core/Stream.java | 2 +- src/org/ibex/core/Template.java | 18 ++-- src/org/ibex/graphics/HTML.java | 8 +- src/org/ibex/graphics/Surface.java | 32 +++--- src/org/ibex/plat/Platform.java | 2 +- 7 files changed, 190 insertions(+), 187 deletions(-) diff --git a/src/org/ibex/core/Box.java b/src/org/ibex/core/Box.java index a4e95f5..7a332ea 100644 --- a/src/org/ibex/core/Box.java +++ b/src/org/ibex/core/Box.java @@ -41,7 +41,9 @@ import org.ibex.graphics.*; * trigger a Surface.abort; if rendering were done in the same pass, * rendering work done prior to the Surface.abort would be wasted. */ -public final class Box extends JS.O implements Task { +public final class Box extends JS.Obj implements Task { + + private static final JS.Method METHOD = new JS.Method(); // Macros ////////////////////////////////////////////////////////////////////// @@ -49,18 +51,18 @@ public final class Box extends JS.O implements Task { final void RECONSTRAIN() { for(Box b2 = this; b2 != null && !b2.test(RECONSTRAIN); b2 = b2.parent) b2.set(RECONSTRAIN); } final void REPACK() { for(Box b2 = this; b2 != null && !b2.test(REPACK); b2 = b2.parent) b2.set(REPACK); } - //#define CHECKSET_SHORT(prop) short nu = (short)toInt(value); if (nu == prop) break; prop = nu; - //#define CHECKSET_INT(prop) int nu = toInt(value); if (nu == prop) break; prop = nu; - //#define CHECKSET_FLAG(flag) boolean nu = toBoolean(value); if (nu == test(flag)) break; if (nu) set(flag); else clear(flag); - //#define CHECKSET_BOOLEAN(prop) boolean nu = toBoolean(value); if (nu == prop) break; prop = nu; - //#define CHECKSET_STRING(prop) if ((value==null&&prop==null)||(value!=null&&JS.toString(value).equals(prop))) break; prop=JS.toString(value); + //#define CHECKSET_SHORT(prop) short nu = (short)JSU.toInt(value); if (nu == prop) break; prop = nu; + //#define CHECKSET_INT(prop) int nu = JSU.toInt(value); if (nu == prop) break; prop = nu; + //#define CHECKSET_FLAG(flag) boolean nu = JSU.toBoolean(value); if (nu == test(flag)) break; if (nu) set(flag); else clear(flag); + //#define CHECKSET_BOOLEAJSU.N(prop) boolean nu = JSU.toBoolean(value); if (nu == prop) break; prop = nu; + //#define CHECKSET_STRING(prop) if ((value==null&&prop==null)||(value!=null&&JSU.toString(value).equals(prop))) break; prop=JSU.toString(value); // FIXME memory leak static Hash boxToCursor = new Hash(500, 3); static final Font DEFAULT_FONT; static { - try { DEFAULT_FONT = Font.getFont((JS)Main.builtin.get(JS.S("fonts/vera/Vera.ttf")), 10); } + try { DEFAULT_FONT = Font.getFont((JS)Main.builtin.get(JSU.S("fonts/vera/Vera.ttf")), 10); } catch(JSExn e) { throw new Error("Error loading default font: " + e); } } @@ -237,7 +239,7 @@ public final class Box extends JS.O implements Task { set(REPLACE); // FIXME: be smarter / more incremental } - private final static JS SIZECHANGE = JS.S("SizeChange"); + private final static JS SIZECHANGE = JSU.S("SizeChange"); void resize(int x, int y, int width, int height) { if (x == this.x && y == this.y && width == this.width && height == this.height) return; @@ -446,20 +448,20 @@ public final class Box extends JS.O implements Task { public JS callMethod(JS method, JS a0, JS a1, JS a2, JS[] rest, int nargs) throws JSExn { switch (nargs) { case 1: { - //#switch(JS.toString(method)) + //#switch(JSU.toString(method)) case "indexof": Box b = (Box)a0; if (b.parent != this) return (redirect == null || redirect == this) ? - N(-1) : + JSU.N(-1) : redirect.callMethod(method, a0, a1, a2, rest, nargs); - return N(b.getIndexInParent()); + return JSU.N(b.getIndexInParent()); case "distanceto": Box b = (Box)a0; - JS ret = new JS.O(); - ret.put(JS.S("x"), N(b.localToGlobalX(0) - localToGlobalX(0))); - ret.put(JS.S("y"), N(b.localToGlobalY(0) - localToGlobalY(0))); + JS ret = new JS.Obj(); + ret.put(JSU.S("x"), JSU.N(b.localToGlobalX(0) - localToGlobalX(0))); + ret.put(JSU.S("y"), JSU.N(b.localToGlobalY(0) - localToGlobalY(0))); return ret; //#end @@ -469,60 +471,60 @@ public final class Box extends JS.O implements Task { } public JS get(JS name) throws JSExn { - if (JS.isInt(name)) - return redirect == null ? null : redirect == this ? getChild(JS.toInt(name)) : redirect.get(name); + if (JSU.isInt(name)) + return redirect == null ? null : redirect == this ? getChild(JSU.toInt(name)) : redirect.get(name); - //#switch(JS.toString(name)) + //#switch(JSU.toString(name)) case "surface": return parent == null ? null : parent.getAndTriggerTraps(name); case "indexof": return METHOD; case "distanceto": return METHOD; - case "text": return JS.S(text); + case "text": return JSU.S(text); case "path": { - if (path != null) return JS.S(path.toString()); + if (path != null) return JSU.S(path.toString()); if (text == null) return null; if (font == null) return null; String ret = ""; for(int i=0; i 0) { CHECKSET_SHORT(colspan); if (parent != null) parent.REPACK(); } - case "rowspan": if (toInt(value) > 0) { CHECKSET_SHORT(rowspan); if (parent != null) parent.REPACK(); } + case "path": path = Path.parse(JSU.toString(value)); RECONSTRAIN(); dirty(); + case "width": setWidth(JSU.toInt(value), JSU.toInt(value)); + case "height": setHeight(JSU.toInt(value), JSU.toInt(value)); + case "maxwidth": setWidth(minwidth, JSU.toInt(value)); + case "minwidth": setWidth(JSU.toInt(value), maxwidth); + case "maxheight": setHeight(minheight, JSU.toInt(value)); + case "minheight": setHeight(JSU.toInt(value), maxheight); + case "colspan": if (JSU.toInt(value) > 0) { CHECKSET_SHORT(colspan); if (parent != null) parent.REPACK(); } + case "rowspan": if (JSU.toInt(value) > 0) { CHECKSET_SHORT(rowspan); if (parent != null) parent.REPACK(); } case "visible": CHECKSET_FLAG(VISIBLE); RECONSTRAIN(); dirty(); case "packed": CHECKSET_FLAG(PACKED); if (parent != null) { parent.REPACK(); } else { REPACK(); } case "align": clear(ALIGNS); setAlign(value); REPLACE(); - case "cursor": setCursor(JS.toString(value)); + case "cursor": setCursor(JSU.toString(value)); case "fill": setFill(value); case "clip": CHECKSET_FLAG(CLIP); if (parent == null) dirty(); else parent.dirty(); case "rows": CHECKSET_SHORT(rows); if (rows==0){set(FIXED, COLS);if(cols==0)cols=1;} else set(FIXED, ROWS); REPACK(); @@ -587,19 +589,19 @@ public final class Box extends JS.O implements Task { // FIXME: remove case "mouse": - int mousex = toInt(((JS)value).get(JS.S("x"))); - int mousey = toInt(((JS)value).get(JS.S("y"))); + int mousex = JSU.toInt(((JS)value).get(JSU.S("x"))); + int mousey = JSU.toInt(((JS)value).get(JSU.S("y"))); getSurface()._mousex = localToGlobalX(mousex); getSurface()._mousey = localToGlobalY(mousey); - case "Minimized": if (parent == null && getSurface() != null) getSurface().minimized = toBoolean(value); // FEATURE - case "Maximized": if (parent == null && getSurface() != null) getSurface().maximized = toBoolean(value); // FEATURE + case "Minimized": if (parent == null && getSurface() != null) getSurface().minimized = JSU.toBoolean(value); // FEATURE + case "Maximized": if (parent == null && getSurface() != null) getSurface().maximized = JSU.toBoolean(value); // FEATURE case "Close": if (parent == null && getSurface() != null) getSurface().dispose(true); case "redirect": for(Box cur = (Box)value; cur != null || cur == redirect; cur = cur.parent) if (cur == redirect) { redirect = (Box)value; return; } - JS.error("redirect can only be set to a descendant of its current value"); - case "fontsize": font = Font.getFont(font == null ? null : font.stream, toInt(value)); RECONSTRAIN(); dirty(); + JSU.error("redirect can only be set to a descendant of its current value"); + case "fontsize": font = Font.getFont(font == null ? null : font.stream, JSU.toInt(value)); RECONSTRAIN(); dirty(); case "font": if(!(value instanceof Stream)) throw new JSExn("You can only put streams to the font property"); //FIXME: if (font == value) return; // FIXME: unclone() @@ -620,7 +622,7 @@ public final class Box extends JS.O implements Task { CHECKSET_INT(ay); REPLACE(); } - case "titlebar": if (getSurface()!=null) getSurface().setTitleBarText(toString(value)); super.put(name,value); + case "titlebar": if (getSurface()!=null) getSurface().setTitleBarText(JSU.toString(value)); super.put(name,value); // FIXME: icon case "Press1": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.putAndTriggerTraps(name, value); @@ -639,9 +641,9 @@ public final class Box extends JS.O implements Task { case "KeyReleased": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.putAndTriggerTraps(name, value); case "Move": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.putAndTriggerTraps(name, value); case "HScroll": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) - parent.putAndTriggerTraps(name, N(JS.toFloat(value) * ((float)parent.fontSize()) / ((float)fontSize()))); + parent.putAndTriggerTraps(name, JSU.N(JSU.toFloat(value) * ((float)parent.fontSize()) / ((float)fontSize()))); case "VScroll": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) - parent.putAndTriggerTraps(name, N(JS.toFloat(value) * ((float)parent.fontSize()) / ((float)fontSize()))); + parent.putAndTriggerTraps(name, JSU.N(JSU.toFloat(value) * ((float)parent.fontSize()) / ((float)fontSize()))); case "_Move": propagateDownward(name, value, false); case "_Press1": propagateDownward(name, value, false); @@ -687,7 +689,7 @@ public final class Box extends JS.O implements Task { private void setAlign(JS value) throws JSExn { clear(ALIGNS); - //#switch(JS.toString(value)) + //#switch(JSU.toString(value)) case "topleft": set(ALIGN_TOP | ALIGN_LEFT); case "bottomleft": set(ALIGN_BOTTOM | ALIGN_LEFT); case "topright": set(ALIGN_TOP | ALIGN_RIGHT); @@ -696,7 +698,7 @@ public final class Box extends JS.O implements Task { case "bottom": set(ALIGN_BOTTOM); case "left": set(ALIGN_LEFT); case "right": set(ALIGN_RIGHT); - default: JS.log("invalid alignment \"" + JS.debugToString(value) + "\""); + default: JSU.log("invalid alignment \"" + JSU.debugToString(value) + "\""); //#end } @@ -717,8 +719,8 @@ public final class Box extends JS.O implements Task { if (texture == null && fillcolor == 0) return; texture = null; fillcolor = 0; - } else if (JS.isString(value)) { - int newfillcolor = Color.stringToColor(JS.toString(value)); + } else if (JSU.isString(value)) { + int newfillcolor = Color.stringToColor(JSU.toString(value)); if (newfillcolor == fillcolor) return; fillcolor = newfillcolor; texture = null; @@ -738,7 +740,7 @@ public final class Box extends JS.O implements Task { */ private void propagateDownward(JS name_, JS value, boolean obscured) throws JSExn { - String name = JS.toString(name_); + String name = JSU.toString(name_); if (getSurface() == null) return; int x = globalToLocalX(getSurface()._mousex); int y = globalToLocalY(getSurface()._mousey); @@ -746,12 +748,12 @@ public final class Box extends JS.O implements Task { boolean isinside = test(VISIBLE) && inside(x, y) && !obscured; if (!wasinside && isinside) { set(MOUSEINSIDE); - putAndTriggerTrapsAndCatchExceptions(JS.S("Enter"), T); + putAndTriggerTrapsAndCatchExceptions(JSU.S("Enter"), T); } if (isinside && test(CURSOR)) getSurface().cursor = (String)boxToCursor.get(this); if (wasinside && !isinside) { clear(MOUSEINSIDE); - putAndTriggerTrapsAndCatchExceptions(JS.S("Leave"), T); + putAndTriggerTrapsAndCatchExceptions(JSU.S("Leave"), T); } boolean found = false; @@ -760,7 +762,7 @@ public final class Box extends JS.O implements Task { boolean save_stop = child.test(STOP_UPWARD_PROPAGATION); JS value2 = value; if (name.equals("_HScroll") || name.equals("_VScroll")) - value2 = N(JS.toFloat(value) * ((float)child.fontSize()) / (float)fontSize()); + value2 = JSU.N(JSU.toFloat(value) * ((float)child.fontSize()) / (float)fontSize()); if (obscured || !child.inside(x - child.x, y - child.y)) { child.propagateDownward(name_, value2, true); } else try { @@ -779,7 +781,7 @@ public final class Box extends JS.O implements Task { if (!obscured && !found) if ("_Move".equals(name) || name.startsWith("_Release") || wasinside) if (name != null) - putAndTriggerTrapsAndCatchExceptions(JS.S(name.substring(1)), value); + putAndTriggerTrapsAndCatchExceptions(JSU.S(name.substring(1)), value); } /** figures out what box in this subtree of the Box owns the pixel at x,y relitave to the Surface */ @@ -870,34 +872,34 @@ public final class Box extends JS.O implements Task { deleteNode(i); b.parent = null; REPACK(); - putAndTriggerTrapsAndCatchExceptions(JS.S("ChildChange"), b); + putAndTriggerTrapsAndCatchExceptions(JSU.S("ChildChange"), b); } public void put(int i, JS value) throws JSExn { if (i < 0) return; if (value != null && !(value instanceof Box)) { - if (Log.on) JS.warn("attempt to set a numerical property on a box to a non-box"); + if (Log.on) JSU.warn("attempt to set a numerical property on a box to a non-box"); return; } if (redirect == null) { - if (value == null) putAndTriggerTrapsAndCatchExceptions(JS.S("ChildChange"), getChild(i)); - else JS.warn("attempt to add/remove children to/from a node with a null redirect"); + if (value == null) putAndTriggerTrapsAndCatchExceptions(JSU.S("ChildChange"), getChild(i)); + else JSU.warn("attempt to add/remove children to/from a node with a null redirect"); } else if (redirect != this) { - if (value != null) putAndTriggerTrapsAndCatchExceptions(JS.S("ChildChange"), value); + if (value != null) putAndTriggerTrapsAndCatchExceptions(JSU.S("ChildChange"), value); redirect.put(i, value); if (value == null) { - Box b = (Box)redirect.get(JS.N(i)); - if (b != null) putAndTriggerTrapsAndCatchExceptions(JS.S("ChildChange"), b); + Box b = (Box)redirect.get(JSU.N(i)); + if (b != null) putAndTriggerTrapsAndCatchExceptions(JSU.S("ChildChange"), b); } } else if (value == null) { if (i < 0 || i > treeSize()) return; Box b = getChild(i); removeChild(i); - putAndTriggerTrapsAndCatchExceptions(JS.S("ChildChange"), b); + putAndTriggerTrapsAndCatchExceptions(JSU.S("ChildChange"), b); } else { Box b = (Box)value; @@ -905,14 +907,14 @@ public final class Box extends JS.O implements Task { // check if box being moved is currently target of a redirect for(Box cur = b.parent; cur != null; cur = cur.parent) if (cur.redirect == b) { - if (Log.on) JS.warn("attempt to move a box that is the target of a redirect"); + if (Log.on) JSU.warn("attempt to move a box that is the target of a redirect"); return; } // check for recursive ancestor violation for(Box cur = this; cur != null; cur = cur.parent) if (cur == b) { - if (Log.on) JS.warn("attempt to make a node a parent of its own ancestor"); + if (Log.on) JSU.warn("attempt to make a node a parent of its own ancestor"); if (Log.on) Log.info(this, "box == " + this + " ancestor == " + b); return; } @@ -926,7 +928,7 @@ public final class Box extends JS.O implements Task { REPACK(); b.dirty(); - putAndTriggerTrapsAndCatchExceptions(JS.S("ChildChange"), b); + putAndTriggerTrapsAndCatchExceptions(JSU.S("ChildChange"), b); } } @@ -934,11 +936,11 @@ public final class Box extends JS.O implements Task { try { putAndTriggerTraps(name, val); } catch (JSExn e) { - JS.log("caught js exception while putting to trap \""+ JS.debugToString(name)+"\""); - JS.log(e); + JSU.log("caught js exception while putting to trap \""+ JSU.debugToString(name)+"\""); + JSU.log(e); } catch (Exception e) { - JS.log("caught exception while putting to trap \""+ JS.debugToString(name)+"\""); - JS.log(e); + JSU.log("caught exception while putting to trap \""+ JSU.debugToString(name)+"\""); + JSU.log(e); } } diff --git a/src/org/ibex/core/Ibex.java b/src/org/ibex/core/Ibex.java index 270e138..57fe96d 100644 --- a/src/org/ibex/core/Ibex.java +++ b/src/org/ibex/core/Ibex.java @@ -13,10 +13,11 @@ import org.ibex.net.*; import org.ibex.crypto.*; /** Singleton class that provides all functionality in the ibex.* namespace */ -public final class Ibex extends JS implements JS.Cloneable { +public final class Ibex extends JS.Obj implements JS.Cloneable { // FIXME remove this 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); } } @@ -32,23 +33,23 @@ public final class Ibex extends JS implements JS.Cloneable { while(str.indexOf('.') != -1) { String path = str.substring(0, str.indexOf('.')); str = str.substring(str.indexOf('.') + 1); - ret = ret.get(JS.S(path)); + ret = ret.get(JSU.S(path)); } - if (!"".equals(str)) ret = ret.get(JS.S(str)); + if (!"".equals(str)) ret = ret.get(JSU.S(str)); return ret; } /** lets us put multi-level get/put/call keys all in the same method */ - private class Sub extends JS { + private class Sub extends JS.Obj { JS key; Sub(JS key) { this.key = key; } - public void put(JS key, JS val) throws JSExn { Ibex.this.put(JS.S(JS.toString(this.key) + "." + JS.toString(key)), val); } - public JS get(JS key) throws JSExn { return Ibex.this.get(JS.S(JS.toString(this.key) + "." + JS.toString(key))); } + public void put(JS key, JS val) throws JSExn { Ibex.this.put(JSU.S(JSU.toString(this.key) + "." + JSU.toString(key)), val); } + public JS get(JS key) throws JSExn { return Ibex.this.get(JSU.S(JSU.toString(this.key) + "." + JSU.toString(key))); } public JS call(JS a0, JS a1, JS a2, JS[] rest, int nargs) throws JSExn { return Ibex.this.callMethod(this.key, a0, a1, a2, rest, nargs); } public JS callMethod(JS method, JS a0, JS a1, JS a2, JS[] rest, int nargs) throws JSExn { - return Ibex.this.callMethod(JS.S(JS.toString(this.key) + "." + JS.toString(method)), a0, a1, a2, rest, nargs); + return Ibex.this.callMethod(JSU.S(JSU.toString(this.key) + "." + JSU.toString(method)), a0, a1, a2, rest, nargs); } } private Cache subCache = new Cache(20); @@ -60,9 +61,9 @@ public final class Ibex extends JS implements JS.Cloneable { public JS get(JS name) throws JSExn { // FIXME: SHouldn't need this (just trap [""]) - if (JS.isString(name) && JS.toString(name).length() == 0) return rr; + if (JS.isString(name) && JSU.toString(name).length() == 0) return rr; // FEATURE: Preprocessor hack to generate specialized JS instances (avoid all this string concatenation) - //#switch(JS.toString(name)) + //#switch(JSU.toString(name)) case "math": return ibexMath; case "string": return ibexString; case "date": return METHOD; @@ -75,9 +76,9 @@ public final class Ibex extends JS implements JS.Cloneable { case "ui.font.wait": return METHOD; case "ui.font.width": return METHOD; case "ui.font.height": return METHOD; - case "ui.font.sansserif": return Main.builtin.get(JS.S("fonts/vera/Vera.ttf")); - case "ui.font.monospace": return Main.builtin.get(JS.S("fonts/vera/VeraMono.ttf")); - case "ui.font.serif": return Main.builtin.get(JS.S("fonts/vera/VeraSe.ttf")); + case "ui.font.sansserif": return Main.builtin.get(JSU.S("fonts/vera/Vera.ttf")); + case "ui.font.monospace": return Main.builtin.get(JSU.S("fonts/vera/VeraMono.ttf")); + case "ui.font.serif": return Main.builtin.get(JSU.S("fonts/vera/VeraSe.ttf")); case "ui.browser": return METHOD; case "ui.mouse": return getSub(name); case "ui.mouse.button": @@ -87,18 +88,18 @@ public final class Ibex extends JS implements JS.Cloneable { else return ZERO; case "ui.key": return getSub(name); case "ui.key.name": return getSub(name); - case "ui.key.name.alt": return JS.S(Platform.altKeyName()); - case "ui.key.alt": return Surface.alt ? T : F; - case "ui.key.control": return Surface.control ? T : F; - case "ui.key.shift": return Surface.shift ? T : F; - case "ui.clipboard": return JS.S((String)Platform.getClipBoard()); + case "ui.key.name.alt": return JSU.S(Platform.altKeyName()); + case "ui.key.alt": return Surface.alt ? JSU.T : JSU.F; + case "ui.key.control": return Surface.control ? JSU.T : JSU.F; + case "ui.key.shift": return Surface.shift ? JSU.T : JSU.F; + case "ui.clipboard": return JSU.S((String)Platform.getClipBoard()); case "ui.maxdim": return N(Short.MAX_VALUE); case "ui.screen": return getSub(name); case "ui.screen.width": return N(Platform.getScreenWidth()); case "ui.screen.height": return N(Platform.getScreenHeight()); case "undocumented": return getSub(name); - case "undocumented.initialOrigin": return JS.S(Main.origin); - case "undocumented.initialTemplate": return JS.S(Main.initialTemplate); + case "undocumented.initialOrigin": return JSU.S(Main.origin); + case "undocumented.initialTemplate": return JSU.S(Main.initialTemplate); case "thread": return getSub(name); case "thread.yield": return METHOD; case "thread.sleep": return METHOD; @@ -132,9 +133,9 @@ public final class Ibex extends JS implements JS.Cloneable { } public void put(JS name, JS value) throws JSExn { - //#switch(JS.toString(name)) + //#switch(JSU.toString(name)) case "thread": Scheduler.add((Task)value); return; - case "ui.clipboard": Platform.setClipBoard(JS.toString(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; case "undocumented.proxyAuthorization": @@ -147,9 +148,9 @@ public final class Ibex extends JS implements JS.Cloneable { public JS callMethod(JS name, JS a, JS b, JS c, JS[] rest, int nargs) throws JSExn { try { - //#switch(JS.toString(name)) + //#switch(JSU.toString(name)) case "date": return new JSDate(a, b, c, rest, nargs); - case "net.rpc.soap": return new SOAP(JS.toString(a), "", JS.toString(b), JS.toString(c)); + case "net.rpc.soap": return new SOAP(JSU.toString(a), "", JSU.toString(b), JSU.toString(c)); // FIXME support object dumping case "log.debug": JS.debug(a== null ? "**null**" : JS.debugToString(a)); return null; case "log.info": JS.info(a== null ? "**null**" : JS.debugToString(a)); return null; @@ -159,24 +160,24 @@ public final class Ibex extends JS implements JS.Cloneable { switch (nargs) { case 0: - //#switch(JS.toString(name)) + //#switch(JSU.toString(name)) case "thread.yield": sleep(0); return null; //#end break; case 1: - //#switch(JS.toString(name)) + //#switch(JSU.toString(name)) case "clone": if(a == null) throw new JSExn("can't clone the null value"); return ((JS)a).jsclone(); case "bless": return bless((JS)a); - case "ui.browser": Platform.newBrowserWindow(JS.toString(a)); return null; + case "ui.browser": Platform.newBrowserWindow(JSU.toString(a)); return null; case "stream.unzip": return a == null ? null : new Stream.Zip((Stream)a); //case "stream.uncab": return a == null ? null : new Stream.Cab(a); case "stream.cache": try { return a == null ? null : new Stream.CachedStream((Stream)a, "resources", true); } catch (Stream.NotCacheableException e) { throw new JSExn("this resource cannot be cached"); } case "stream.url": { - String url = JS.toString(a); + String url = JSU.toString(a); 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(Base64.decode(url.substring(5)), null); @@ -189,7 +190,7 @@ public final class Ibex extends JS implements JS.Cloneable { } case "thread.sleep": sleep(JS.toInt(a)); return null; case "regexp": return new JSRegexp(a, null); - case "net.rpc.xml": return new XMLRPC(JS.toString(a), ""); + case "net.rpc.xml": return new XMLRPC(JSU.toString(a), ""); case "crypto.rsa": /* FEATURE */ return null; case "crypto.md5": /* FEATURE */ return null; case "crypto.sha1": /* FEATURE */ return null; @@ -198,20 +199,20 @@ public final class Ibex extends JS implements JS.Cloneable { case "stream.parse.xml": if(a == null) return null; new XMLHelper(b).doParse(a); return null; // FIXME backgrounding case "stream.parse.utf8": if(a == null) return null; - try { return JS.S(new String(InputStreamToByteArray.convert(a.getInputStream()))); } + try { return JSU.S(new String(InputStreamToByteArray.convert(a.getInputStream()))); } catch (Exception e) { Log.warn(this, e); } //#end break; case 2: - //#switch(JS.toString(name)) + //#switch(JSU.toString(name)) case "stream.watch": return new Stream.ProgressWatcher((Stream)a, b); case "regexp": return new JSRegexp(a, b); //#end case 3: - //#switch(JS.toString(name)) - case "ui.font.height": return N(Font.getFont(a, JS.toInt(b)).textheight(JS.toString(c))); + //#switch(JSU.toString(name)) + case "ui.font.height": return N(Font.getFont(a, JS.toInt(b)).textheight(JSU.toString(c))); case "ui.font.wait": throw new Error("FIXME: ibex.ui.font.wait not implemented"); - case "ui.font.width": return N(Font.getFont(a, JS.toInt(b)).textwidth(JS.toString(c))); + case "ui.font.width": return N(Font.getFont(a, JS.toInt(b)).textwidth(JSU.toString(c))); //#end break; } @@ -241,16 +242,16 @@ public final class Ibex extends JS implements JS.Cloneable { try { Thread.sleep(i); } catch (InterruptedException e) { } Scheduler.add(callback); } }.start(); - } catch (JS.NotPauseableException npe) { + } catch (JSU.NotPauseableException npe) { throw new JSExn("you cannot sleep or yield in the foreground thread"); } } - public static final JS ibexMath = new JS() { + public static final JS ibexMath = new JS.Obj() { // FEATURE: find a cleaner way to do this private JS gs = /*new JSScope.Global();*/ null; // FIXME: Global scope public JS get(JS key) throws JSExn { - //#switch(JS.toString(key)) + //#switch(JSU.toString(key)) case "isNaN": return METHOD; case "isFinite": return METHOD; case "NaN": return METHOD; @@ -259,7 +260,7 @@ public final class Ibex extends JS implements JS.Cloneable { return MATH.get(key); } public JS callMethod(JS name, JS a, JS b, JS c, JS[] rest, int nargs) throws JSExn { - //#switch(JS.toString(name)) + //#switch(JSU.toString(name)) case "isNaN": return gs.callMethod(name,a,b,c,rest,nargs); case "isFinite": return gs.callMethod(name,a,b,c,rest,nargs); case "NaN": return gs.callMethod(name,a,b,c,rest,nargs); @@ -269,10 +270,10 @@ public final class Ibex extends JS implements JS.Cloneable { } }; - public static final JS ibexString = new JS() { + public static final JS ibexString = new JS.Obj() { private JS gs = /*new JSScope.Global();*/ null; // FIXME: Global scope public JS get(JS key) throws JSExn { - //#switch(JS.toString(key)) + //#switch(JSU.toString(key)) case "parseInt": return METHOD; case "parseFloat": return METHOD; case "decodeURI": return METHOD; @@ -286,7 +287,7 @@ public final class Ibex extends JS implements JS.Cloneable { return super.get(key); } public JS callMethod(JS name, JS a, JS b, JS c, JS[] rest, int nargs) throws JSExn { - //#switch(JS.toString(name)) + //#switch(JSU.toString(name)) case "parseInt": return gs.callMethod(name,a,b,c,rest,nargs); case "parseFloat": return gs.callMethod(name,a,b,c,rest,nargs); case "decodeURI": return gs.callMethod(name,a,b,c,rest,nargs); @@ -306,29 +307,29 @@ public final class Ibex extends JS implements JS.Cloneable { private JS characters, whitespace, endElement, startElement; public XMLHelper(JS b) throws JSExn { super(BUFFER_SIZE); - startElement = b.getAndTriggerTraps(JS.S("startElement")); - endElement = b.getAndTriggerTraps(JS.S("endElement")); - characters = b.getAndTriggerTraps(JS.S("characters")); - whitespace = b.getAndTriggerTraps(JS.S("whitespace")); + startElement = b.getAndTriggerTraps(JSU.S("startElement")); + endElement = b.getAndTriggerTraps(JSU.S("endElement")); + characters = b.getAndTriggerTraps(JSU.S("characters")); + whitespace = b.getAndTriggerTraps(JSU.S("whitespace")); } public void startElement(XML.Element c) throws XML.Exn { try { JS attrs = new JS.O(); // FIXME attribute URIs? add an additional hash? - for(int i=0; i 0 && !hasNonNumeral) t.vals[i] = JS.N(Double.parseDouble((valString))); - else t.vals[i] = JS.S(valString.intern()); // FEATURE: JS.intern() ? + if (valString.length() > 0 && !hasNonNumeral) t.vals[i] = JSU.N(Double.parseDouble((valString))); + else t.vals[i] = JSU.S(valString.intern()); // FEATURE: JS.intern() ? } } } @@ -337,7 +337,7 @@ public class Template { JS box; void putDollar(String key, Box target) throws JSExn { if (parentBoxPis != null) parentBoxPis.putDollar(key, target); - JS jskey = JS.S("$" + key); + JS jskey = JSU.S("$" + key); //declare(jskey); sput(jskey, target); } diff --git a/src/org/ibex/graphics/HTML.java b/src/org/ibex/graphics/HTML.java index e8c4799..39079a3 100644 --- a/src/org/ibex/graphics/HTML.java +++ b/src/org/ibex/graphics/HTML.java @@ -56,13 +56,13 @@ public class HTML { // FEATURE: This is ugly private static class JS extends org.ibex.js.JS.O { public void put(String key, Object value) throws JSExn { - if(value instanceof String) put(JS.S(key),JS.S((String)value)); - else if(value instanceof Number) put(JS.S(key), JS.N((Number)value)); - else if(value == null) put(JS.S(key),null); + if(value instanceof String) put(JSU.S(key),JSU.S((String)value)); + else if(value instanceof Number) put(JSU.S(key), JSU.N((Number)value)); + else if(value == null) put(JSU.S(key),null); else throw new Error("FIXME"); } public Object _get(String key) throws JSExn { - org.ibex.js.JS js = get(JS.S(key)); + org.ibex.js.JS js = get(JSU.S(key)); if(JS.isInt(js)) return new Integer(JS.toInt(js)); return JS.toString(js); } diff --git a/src/org/ibex/graphics/Surface.java b/src/org/ibex/graphics/Surface.java index ced451a..a6b8447 100644 --- a/src/org/ibex/graphics/Surface.java +++ b/src/org/ibex/graphics/Surface.java @@ -20,8 +20,8 @@ public abstract class Surface extends PixelBuffer implements Task { // Static Data //////////////////////////////////////////////////////////////////////////////// - private static final JS T = JS.T; - private static final JS F = JS.F; + private static final JS T = JSU.T; + private static final JS F = JSU.F; /** all instances of Surface which need to be refreshed by the Scheduler */ public static Vec allSurfaces = new Vec(); @@ -99,7 +99,7 @@ public abstract class Surface extends PixelBuffer implements Task { Scheduler.add(new Task() { public void perform() throws JSExn { Platform.clipboardReadEnabled = true; try { - root.putAndTriggerTraps(JS.S("_Press3"), T); + root.putAndTriggerTraps(JSU.S("_Press3"), T); } finally { Platform.clipboardReadEnabled = false; } @@ -133,7 +133,7 @@ public abstract class Surface extends PixelBuffer implements Task { } } - private final static JS MOVE = JS.S("_Move"); + private final static JS MOVE = JSU.S("_Move"); /** we enqueue ourselves in the Scheduler when we have a Move message to deal with */ private Task mover = new Task() { public void perform() { @@ -159,10 +159,10 @@ public abstract class Surface extends PixelBuffer implements Task { Scheduler.add(mover); } - protected final void HScroll(int pixels) { new Message("_HScroll", JS.N(pixels), root); } - protected final void VScroll(int pixels) { new Message("_VScroll", JS.N(pixels), root); } - protected final void HScroll(float lines) { new Message("_HScroll", JS.N(lines), root); } - protected final void VScroll(float lines) { new Message("_VScroll", JS.N(lines), root); } + protected final void HScroll(int pixels) { new Message("_HScroll", JSU.N(pixels), root); } + protected final void VScroll(int pixels) { new Message("_VScroll", JSU.N(pixels), root); } + protected final void HScroll(float lines) { new Message("_HScroll", JSU.N(lines), root); } + protected final void VScroll(float lines) { new Message("_VScroll", JSU.N(lines), root); } /** subclasses should invoke this method when the user resizes the window */ protected final void SizeChange(final int width, final int height) { @@ -179,14 +179,14 @@ public abstract class Surface extends PixelBuffer implements Task { Scheduler.add(new Task() { public void perform() throws JSExn { root.x = x; root.y = y; - root.putAndTriggerTrapsAndCatchExceptions(JS.S("PosChange"), T); + root.putAndTriggerTrapsAndCatchExceptions(JSU.S("PosChange"), T); }}); } private final String[] doubleClick = new String[] { null, "_DoubleClick1", "_DoubleClick2", "_DoubleClick3" }; protected final void DoubleClick(int button) { new Message(doubleClick[button], T, root); } - protected final void KeyPressed(String key) { new Message("_KeyPressed", JS.S(key), root); } - protected final void KeyReleased(String key) { new Message("_KeyReleased", JS.S(key), root); } + protected final void KeyPressed(String key) { new Message("_KeyPressed", JSU.S(key), root); } + protected final void KeyReleased(String key) { new Message("_KeyReleased", JSU.S(key), root); } protected final void Close() { new Message("Close", T, root); } protected final void Minimized(boolean b) { minimized = b; new Message("Minimized", b ? T : F, root); } protected final void Maximized(boolean b) { maximized = b; new Message("Maximized", b ? T : F, root); } @@ -273,7 +273,7 @@ public abstract class Surface extends PixelBuffer implements Task { setSize(rootwidth, rootheight); /*String oldcursor = cursor; cursor = "default"; - root.putAndTriggerTrapsAndCatchExceptions("_Move", JS.T); + root.putAndTriggerTrapsAndCatchExceptions("_Move", JSU.T); if (!cursor.equals(oldcursor)) syncCursor();*/ } while(abort); @@ -325,20 +325,20 @@ public abstract class Surface extends PixelBuffer implements Task { if (value.toLowerCase().equals("alt")) alt = true; else if (alt) value = "A-" + value; if (value.toLowerCase().endsWith("control")) control = true; else if (control) value = "C-" + value; if (value.equals("C-v") || value.equals("A-v")) Platform.clipboardReadEnabled = true; - this.value = JS.S(value); + this.value = JSU.S(value); } else if (name.equals("_KeyReleased")) { String value = JS.toString(this.value); if (value.toLowerCase().equals("alt")) alt = false; else if (value.toLowerCase().equals("control")) control = false; else if (value.toLowerCase().equals("shift")) shift = false; - this.value = JS.S(value); + this.value = JSU.S(value); } else if (name.equals("_HScroll") || name.equals("_VScroll")) { // FIXME: technically points != pixels if (JS.isInt(value)) - value = JS.N(JS.toInt(value) * root.fontSize()); + value = JSU.N(JS.toInt(value) * root.fontSize()); } try { - boxContainingMouse.putAndTriggerTrapsAndCatchExceptions(JS.S(name), value); + boxContainingMouse.putAndTriggerTrapsAndCatchExceptions(JSU.S(name), value); } finally { Platform.clipboardReadEnabled = false; } diff --git a/src/org/ibex/plat/Platform.java b/src/org/ibex/plat/Platform.java index 27feca8..e9f6589 100644 --- a/src/org/ibex/plat/Platform.java +++ b/src/org/ibex/plat/Platform.java @@ -122,7 +122,7 @@ public abstract class Platform { ret.Refresh(); } try { - if (b.get(JS.S("titlebar")) != null) ret.setTitleBarText(JS.toString(b.get(JS.S("titlebar")))); + if (b.get(JSU.S("titlebar")) != null) ret.setTitleBarText(JS.toString(b.get(JSU.S("titlebar")))); } catch (JSExn e) { Log.warn(Platform.class, e); } -- 1.7.10.4