//#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&&value.equals(prop))) break; prop=(String)value;
+ void mark_for_repack() { MARK_REPACK; }
+
protected Box() { super(null); }
static Hash boxToCursor = new Hash(500, 3);
static final String[] props = new String[] {
"fill", "stroke", "image", "tile", "fixedaspect", "text", "path", "font",
"shrink", "hshrink", "vshrink", "x", "y", "width", "height", "cols", "rows",
- "colspan", "rowspan", "align", "invisible", "absolute", "globalx", "globaly",
+ "colspan", "rowspan", "align", "visible", "absolute", "globalx", "globaly",
"minwidth", "maxwidth", "minheight", "maxheight",
"numchildren", "redirect", "cursor", "mousex", "mousey", "xwt", "static",
"mouseinside", "root", "thisbox", "indexof"
private String text = null;
private Font font = DEFAULT_FONT;
- private Picture texture;
+ private Picture texture = null;
private short strokewidth = 1;
private int fillcolor = 0x00000000;
private int strokecolor = 0xFF000000;
/** invoked when a resource needed to render ourselves finishes loading */
- public void perform() {
+ public void perform() throws JSExn {
+ // as external events have occured, check the state of box
+ if (texture != null) {
+ if (texture.isLoaded) { minwidth = texture.width; minheight = texture.height; }
+ else { Res res = texture.res; texture = null; throw new JSExn("image not found: "+res); }
+ }
+
MARK_REPACK;
MARK_REFLOW;
MARK_RESIZE;
if (!wasinside && !isinside) return;
if (isinside && test(CURSOR)) Surface.fromBox(getRoot()).cursor = (String)boxToCursor.get(this);
- if (!wasinside && isinside && getTrap("Enter") != null) putAndTriggerTraps("Enter", T);
- else if (wasinside && !isinside && getTrap("Leave") != null) putAndTriggerTraps("Leave", T);
+ if (!wasinside && isinside && getTrap("Enter") != null) putAndTriggerTrapsAndCatchExceptions("Enter", T);
+ else if (wasinside && !isinside && getTrap("Leave") != null) putAndTriggerTrapsAndCatchExceptions("Leave", T);
else if (wasinside && isinside && (mousex != oldmousex || mousey != oldmousey) && getTrap("Move")!= null)
- putAndTriggerTraps("Move", T);
+ putAndTriggerTrapsAndCatchExceptions("Move", T);
for(Box b = getChild(treeSize() - 1); b != null; b = b.prevSibling()) {
b.Move(oldmousex - b.x, oldmousey - b.y, mousex - b.x, mousey - b.y, forceleave);
if (b.inside(mousex - b.x, mousey - b.y)) forceleave = true;
boolean poschange = (this.x != x || this.y != y) && getTrap("PosChange") != null;
this.width = width; this.height = height; this.x = x; this.y = y;
dirty();
- if (sizechange) try { putAndTriggerTraps("SizeChange", T); /*Surface.abort = true;*/ }
- catch (Exception e) { Log.log(this, e); }
- if (poschange) try { putAndTriggerTraps("PosChange", T); /*Surface.abort = true;*/ }
- catch (Exception e) { Log.log(this, e); }
+ if (sizechange) putAndTriggerTrapsAndCatchExceptions("SizeChange", T);
+ if (poschange) putAndTriggerTrapsAndCatchExceptions("PosChange", T);
//}
}
}
if (!(value instanceof Res)) return;
-
- // FIXME
texture = Picture.load((Res)value, this);
- if (texture.isLoaded) {
- minwidth = texture.width;
- minheight = texture.height;
- MARK_REFLOW;
- dirty();
- return;
- }
- texture = Picture.load((Res)value, new Scheduler.Task() { public void perform() {
- // FIXME pass this instead of a new Task?
- minwidth = texture.width;
- minheight = texture.height;
- Box b = Box.this; MARK_REFLOW_b;
- dirty();
- } });
}
private void mouseEvent(String name, Object value) {
int mousex = globalToLocalX(surface.mousex);
int mousey = globalToLocalY(surface.mousey);
for(Box c = prevSibling(); c != null; c = c.prevSibling())
- if (c.inside(mousex - c.x, mousey - c.y)) { c.putAndTriggerTraps(name, value); return; }
- if (parent != null) parent.putAndTriggerTraps(name, value);
+ if (c.inside(mousex - c.x, mousey - c.y)) { c.putAndTriggerTrapsAndCatchExceptions(name, value); return; }
+ if (parent != null) parent.putAndTriggerTrapsAndCatchExceptions(name, value);
}
private static int stringToColor(String s) {
deleteNode(i);
b.parent = null;
MARK_REFLOW;
- putAndTriggerTraps("childremoved", b);
+ putAndTriggerTrapsAndCatchExceptions("childremoved", b);
}
public void put(int i, Object value) throws JSExn {
}
if (redirect == null) {
- if (value == null) putAndTriggerTraps("childremoved", getChild(i));
+ if (value == null) putAndTriggerTrapsAndCatchExceptions("childremoved", getChild(i));
else Log.logJS(this, "attempt to add/remove children to/from a node with a null redirect");
} else if (redirect != this) {
- if (value != null) putAndTriggerTraps("childadded", value);
+ if (value != null) putAndTriggerTrapsAndCatchExceptions("childadded", value);
redirect.put(i, value);
if (value == null) {
Box b = (Box)redirect.get(new Integer(i));
- if (b != null) putAndTriggerTraps("childremoved", b);
+ if (b != null) putAndTriggerTrapsAndCatchExceptions("childremoved", b);
}
} else if (value == null) {
if (i < 0 || i > treeSize()) return;
Box b = getChild(i);
removeChild(i);
- putAndTriggerTraps("childremoved", b);
+ putAndTriggerTrapsAndCatchExceptions("childremoved", b);
} else {
Box b = (Box)value;
MARK_REFLOW;
b.dirty();
- putAndTriggerTraps("childadded", b);
+ putAndTriggerTrapsAndCatchExceptions("childadded", b);
}
}
-
- public final void putAndTriggerTraps(Object key, Object value) {
+ private void putAndTriggerTrapsAndCatchExceptions(Object name, Object val) {
try {
- super.putAndTriggerTraps(key, value);
- } catch (JSExn jse) {
- Log.logJS("attempt to put value " + value + " to key " + key + " on a box triggered a trap which threw:");
- Log.logJS(jse);
+ putAndTriggerTraps(name, val);
+ } catch (Exception e) {
+ Log.logJS("caught exception while putting to trap \""+name+"\"");
+ Log.logJS(e);
}
}
- public final Object getAndTriggerTraps(Object key) {
- try {
- return super.getAndTriggerTraps(key);
- } catch (JSExn jse) {
- Log.logJS("attempt to get key " + key + " on a box triggered a trap which threw:");
- Log.logJS(jse);
- return null;
- }
- }
}