- static final Font DEFAULT_FONT = Font.getFont((Stream)Main.builtin.get("fonts/vera/Vera.ttf"), 10);
+ static final Font DEFAULT_FONT;
+ static {
+ try { DEFAULT_FONT = Font.getFont(Main.builtin.get(JS.S("fonts/vera/Vera.ttf")), 10); }
+ catch(JSExn e) { throw new Error("Error loading default font: " + e); }
+ }
void resize(int x, int y, int width, int height) {
if (x == this.x && y == this.y && width == this.width && height == this.height) return;
void resize(int x, int y, int width, int height) {
if (x == this.x && y == this.y && width == this.width && height == this.height) return;
int thisx = parent == null ? 0 : this.x;
int thisy = parent == null ? 0 : this.y;
Box who = (parent == null ? this : parent);
int thisx = parent == null ? 0 : this.x;
int thisy = parent == null ? 0 : this.y;
Box who = (parent == null ? this : parent);
- public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn {
+ public JS callMethod(JS method, JS a0, JS a1, JS a2, JS[] rest, int nargs) throws JSExn {
- JS ret = new JS();
- ret.put("x", N(b.localToGlobalX(0) - localToGlobalX(0)));
- ret.put("y", N(b.localToGlobalY(0) - localToGlobalY(0)));
+ 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)));
return super.callMethod(method, a0, a1, a2, rest, nargs);
}
return super.callMethod(method, a0, a1, a2, rest, nargs);
}
- public Object get(Object name) throws JSExn {
- if (name instanceof Number)
- return redirect == null ? null : redirect == this ? getChild(toInt(name)) : redirect.get(name);
+ 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 (text == null) return null;
if (font == null) return null;
String ret = "";
for(int i=0; i<text.length(); i++) ret += font.glyphs[text.charAt(i)].path;
if (text == null) return null;
if (font == null) return null;
String ret = "";
for(int i=0; i<text.length(); i++) ret += font.glyphs[text.charAt(i)].path;
- return ret;
- case "fill": return Color.colorToString(fillcolor);
- case "strokecolor": return Color.colorToString(strokecolor);
- case "textcolor": return Color.colorToString(strokecolor);
+ return JS.S(ret);
+ }
+ case "fill": return JS.S(Color.colorToString(fillcolor));
+ case "strokecolor": return JS.S(Color.colorToString(strokecolor));
+ case "textcolor": return JS.S(Color.colorToString(strokecolor));
case "font": return font == null ? null : font.stream;
case "fontsize": return font == null ? N(10) : N(font.pointsize);
case "strokewidth": return N(strokewidth);
case "font": return font == null ? null : font.stream;
case "fontsize": return font == null ? N(10) : N(font.pointsize);
case "strokewidth": return N(strokewidth);
case "thisbox": return this;
case "shrink": return B(test(HSHRINK) || test(VSHRINK));
case "hshrink": return B(test(HSHRINK));
case "thisbox": return this;
case "shrink": return B(test(HSHRINK) || test(VSHRINK));
case "hshrink": return B(test(HSHRINK));
case "minheight": return N(minheight);
case "maxheight": return N(maxheight);
case "clip": return B(test(CLIP));
case "minheight": return N(minheight);
case "maxheight": return N(maxheight);
case "clip": return B(test(CLIP));
case "packed": return B(test(PACKED));
case "globalx": return N(localToGlobalX(0));
case "globaly": return N(localToGlobalY(0));
case "packed": return B(test(PACKED));
case "globalx": return N(localToGlobalX(0));
case "globaly": return N(localToGlobalY(0));
case "mouse":
if (getSurface() == null) return null;
if (getSurface()._mousex == Integer.MAX_VALUE)
throw new JSExn("you cannot read from the box.mouse property in background thread context");
return new Mouse();
case "mouse":
if (getSurface() == null) return null;
if (getSurface()._mousex == Integer.MAX_VALUE)
throw new JSExn("you cannot read from the box.mouse property in background thread context");
return new Mouse();
- case "numchildren": return redirect == null ? N(0) : redirect == this ? N(treeSize()) : redirect.get("numchildren");
- case "redirect": return redirect == null ? null : redirect == this ? T : redirect.get("redirect");
+ case "numchildren": return redirect == null ? N(0) : redirect == this ? N(treeSize()) : redirect.get(JS.S("numchildren"));
+ case "redirect": return redirect == null ? null : redirect == this ? T : redirect.get(JS.S("redirect"));
case "Minimized": if (parent == null && getSurface() != null) return B(getSurface().minimized);
default: return super.get(name);
//#end
throw new Error("unreachable"); // unreachable
}
case "Minimized": if (parent == null && getSurface() != null) return B(getSurface().minimized);
default: return super.get(name);
//#end
throw new Error("unreachable"); // unreachable
}
- private class Mouse extends JS.Cloneable {
- public Object get(Object key) {
- //#switch(key)
+ private class Mouse extends JS implements JS.Cloneable {
+ public JS get(JS key) throws JSExn {
+ //#switch(JS.toString(key))
case "x": return N(globalToLocalX(getSurface()._mousex));
case "y": return N(globalToLocalY(getSurface()._mousey));
case "x": return N(globalToLocalX(getSurface()._mousex));
case "y": return N(globalToLocalY(getSurface()._mousey));
- public void put(Object name, Object value) throws JSExn {
- if (name instanceof Number) { put(toInt(name), value); return; }
- //#switch(name)
+ public void put(JS name, JS value) throws JSExn {
+ if (JS.isInt(name)) { put(JS.toInt(name), value); return; }
+ //#switch(JS.toString(name))
- case "text": if (value == null) value = ""; CHECKSET_STRING(text); RECONSTRAIN(); dirty();
- case "strokecolor": value = N(Color.stringToColor((String)value)); CHECKSET_INT(strokecolor); dirty();
- case "textcolor": value = N(Color.stringToColor((String)value)); CHECKSET_INT(strokecolor); dirty();
+ case "text": { String s = value == null ? "" : JS.toString(value); CHECKSET_STRING(text); RECONSTRAIN(); dirty(); }
+ case "strokecolor": value = N(Color.stringToColor(JS.toString(value))); CHECKSET_INT(strokecolor); dirty();
+ case "textcolor": value = N(Color.stringToColor(JS.toString(value))); CHECKSET_INT(strokecolor); dirty();
case "strokewidth": CHECKSET_SHORT(strokewidth); dirty();
case "shrink": CHECKSET_FLAG(HSHRINK | VSHRINK); RECONSTRAIN();
case "hshrink": CHECKSET_FLAG(HSHRINK); RECONSTRAIN();
case "strokewidth": CHECKSET_SHORT(strokewidth); dirty();
case "shrink": CHECKSET_FLAG(HSHRINK | VSHRINK); RECONSTRAIN();
case "hshrink": CHECKSET_FLAG(HSHRINK); RECONSTRAIN();
case "rowspan": if (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 "rowspan": if (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 == null ? "center" : value); REPLACE();
- case "cursor": setCursor(value);
+ case "align": clear(ALIGNS); setAlign(value == null ? "center" : JS.toString(value)); REPLACE();
+ case "cursor": setCursor(JS.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();
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();
case "fontsize": font = Font.getFont(font == null ? null : font.stream, toInt(value)); RECONSTRAIN(); dirty();
case "font":
if(!(value instanceof Stream)) throw new JSExn("You can only put streams to the font property");
case "fontsize": font = Font.getFont(font == null ? null : font.stream, toInt(value)); RECONSTRAIN(); dirty();
case "font":
if(!(value instanceof Stream)) throw new JSExn("You can only put streams to the font property");
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)
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)
case "_Move": propagateDownward(name, value, false);
case "_Press1": propagateDownward(name, value, false);
case "_Move": propagateDownward(name, value, false);
case "_Press1": propagateDownward(name, value, false);
if (value == null) { clear(CURSOR); boxToCursor.remove(this); return; }
if (value.equals(boxToCursor.get(this))) return;
set(CURSOR);
if (value == null) { clear(CURSOR); boxToCursor.remove(this); return; }
if (value.equals(boxToCursor.get(this))) return;
set(CURSOR);
Picture newtex = Picture.load((JS)value, this);
if (texture == newtex) return;
texture = newtex;
fillcolor = 0;
if (texture != null && texture.isLoaded) perform();
Picture newtex = Picture.load((JS)value, this);
if (texture == newtex) return;
texture = newtex;
fillcolor = 0;
if (texture != null && texture.isLoaded) perform();
* Handles events which propagate down the box tree. If obscured
* is set, then we merely check for Enter/Leave.
*/
* Handles events which propagate down the box tree. If obscured
* is set, then we merely check for Enter/Leave.
*/
if (getSurface() == null) return;
int x = globalToLocalX(getSurface()._mousex);
int y = globalToLocalY(getSurface()._mousey);
if (getSurface() == null) return;
int x = globalToLocalX(getSurface()._mousex);
int y = globalToLocalY(getSurface()._mousey);
boolean isinside = test(VISIBLE) && inside(x, y) && !obscured;
if (!wasinside && isinside) {
set(MOUSEINSIDE);
boolean isinside = test(VISIBLE) && inside(x, y) && !obscured;
if (!wasinside && isinside) {
set(MOUSEINSIDE);
}
if (isinside && test(CURSOR)) getSurface().cursor = (String)boxToCursor.get(this);
if (wasinside && !isinside) {
clear(MOUSEINSIDE);
}
if (isinside && test(CURSOR)) getSurface().cursor = (String)boxToCursor.get(this);
if (wasinside && !isinside) {
clear(MOUSEINSIDE);
}
boolean found = false;
if (wasinside || isinside)
for(Box child = getChild(treeSize() - 1); child != null; child = child.prevSibling()) {
boolean save_stop = child.test(STOP_UPWARD_PROPAGATION);
}
boolean found = false;
if (wasinside || isinside)
for(Box child = getChild(treeSize() - 1); child != null; child = child.prevSibling()) {
boolean save_stop = child.test(STOP_UPWARD_PROPAGATION);
- if (name != null) child.putAndTriggerTrapsAndCatchExceptions(name, value2);
- else child.propagateDownward(name, value2, obscured);
+ if (name != null) child.putAndTriggerTrapsAndCatchExceptions(name_, value2);
+ else child.propagateDownward(name_, value2, obscured);
else JS.warn("attempt to add/remove children to/from a node with a null redirect");
} else if (redirect != this) {
else JS.warn("attempt to add/remove children to/from a node with a null redirect");
} else if (redirect != this) {
- Box b = (Box)redirect.get(new Integer(i));
- if (b != null) putAndTriggerTrapsAndCatchExceptions("ChildChange", b);
+ Box b = (Box)redirect.get(JS.N(i));
+ if (b != null) putAndTriggerTrapsAndCatchExceptions(JS.S("ChildChange"), b);