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);
//}
}
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;
- }
- }
}
else if (button == 2) new SimpleMessage("Press2", T, Box.whoIs(root, mousex, mousey));
else if (button == 3) {
final Box who = Box.whoIs(root, mousex, mousey);
- Scheduler.add(new Scheduler.Task() { public void perform() {
+ Scheduler.add(new Scheduler.Task() { public void perform() throws JSExn {
Platform.clipboardReadEnabled = true;
- root.putAndTriggerTraps("Press3", T);
- Platform.clipboardReadEnabled = false;
+ try {
+ root.putAndTriggerTraps("Press3", T);
+ } finally {
+ Platform.clipboardReadEnabled = false;
+ }
}});
}
}
Box b = (Box)keywatchers.elementAt(i);
for(Box cur = b; cur != null; cur = cur.parent)
if (!cur.test(cur.VISIBLE)) continue outer;
- b.putAndTriggerTraps("KeyPressed", key);
+ try {
+ b.putAndTriggerTraps("KeyPressed", key);
+ } catch (JSExn e) {
+ Log.log(Surface.class, "Exception thrown from KeyPressed handler");
+ Log.logJS(e);
+ }
}
Platform.clipboardReadEnabled = false;
}
Box b = (Box)keywatchers.elementAt(i);
for(Box cur = b; cur != null; cur = cur.parent)
if (!cur.test(cur.VISIBLE)) continue outer;
- b.putAndTriggerTraps("KeyReleased", key);
+ try {
+ b.putAndTriggerTraps("KeyReleased", key);
+ } catch (JSExn e) {
+ Log.log(Surface.class, "Exception thrown from KeyReleased handler");
+ Log.logJS(e);
+ }
}
}});
}
String oldcursor = cursor; cursor = "default";
// Root gets motion events outside itself (if trapped)
if (!root.inside(oldmousex, oldmousey) && !root.inside(mousex, mousey) && (button1 || button2 || button3))
- root.putAndTriggerTraps("Move", T);
+ try {
+ root.putAndTriggerTraps("Move", T);
+ } catch (JSExn e) {
+ Log.log(Surface.class, "Exception thrown from Move message handler");
+ Log.logJS(e);
+ }
root.Move(oldmousex, oldmousey, mousex, mousey);
if (!cursor.equals(oldcursor)) syncCursor();
}
}
// FEATURE: can we avoid creating objects here?
+ /** subclasses should invoke this method when the user resizes the window */
protected final void SizeChange(final int width, final int height) {
Scheduler.addAtFront(new Scheduler.Task() { public void perform() {
// dirty the place where the scar used to be
root.dirty(0, root.maxheight - Main.scarImage.height, Main.scarImage.width, Main.scarImage.height);
root.setMaxWidth(JS.N(width));
root.setMaxHeight(JS.N(height));
- root.set(root.REFLOW);
}});
abort = true;
}
// FEATURE: can we avoid creating objects here?
protected final void PosChange(final int x, final int y) {
- Scheduler.add(new Scheduler.Task() { public void perform() {
+ Scheduler.add(new Scheduler.Task() { public void perform() throws JSExn {
root.x = x;
root.y = y;
root.putAndTriggerTraps("PosChange", T);
Scheduler.add(this);
}
- public void perform() { boxContainingMouse.putAndTriggerTraps(name, value); }
+ public void perform() throws JSExn { boxContainingMouse.putAndTriggerTraps(name, value); }
public String toString() { return "SimpleMessage [name=" + name + ", value=" + value + "]"; }
}