X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2FTrap.java;h=196c445472c11d86d6bb7f8e15925e141ca13b3f;hb=8235361e8601ae7b36ab707058de3b52225d15a2;hp=7966047820250fc094d79fd1a47747028d2d2628;hpb=5f24fa01863f5f21f8ce5351f22b59cce07aa4e8;p=org.ibex.core.git diff --git a/src/org/xwt/Trap.java b/src/org/xwt/Trap.java index 7966047..196c445 100644 --- a/src/org/xwt/Trap.java +++ b/src/org/xwt/Trap.java @@ -1,4 +1,4 @@ -// Copyright 2002 Adam Megacz, see the COPYING file for licensing [GPL] +// Copyright 2003 Adam Megacz, see the COPYING file for licensing [GPL] package org.xwt; import java.util.*; @@ -15,51 +15,36 @@ public class Trap { // Static Data ////////////////////////////////////////////////////////////// - /** a vector of weak references to all instances of Trap; used for retheming */ - private static Hashtable allTraps = new Hashtable(1000); - /** List of properties that cannot be trapped */ private static final Hash PROHIBITED = new Hash(120, 3); static { String[] p = new String[] { - "sizetoimage", "shrink", "hshrink", "vshrink", "x", "y", "width", "height", - "flex", "align", "invisible", "absolute", "globalx", "globaly", - "minwidth", "minheight", "height", "width", "maxwidth", "maxheight", - "numchildren", "hpad", "vpad", "doublebuffered", "cursor", - "mousex", "mousey", "xwt", "static", "mouseinside", "root", "thisbox", "indexof", "svg" + "shrink", "hshrink", "vshrink", "x", "y", + "width", "height", "flex", "colspan", "rowspan", "cols", + "rows", "align", "invisible", "absolute", "globalx", + "globaly", "minwidth", "minheight", "height", "width", + "maxwidth", "maxheight", "numchildren", "hpad", "vpad", + "buffered", "cursor", "mousex", "mousey", + "mouseinside", "thisbox", "indexof", "path", "font", "fontsize" }; for(int i=0; i
b
by the currently-running script */
- public static Trap getTrap(Box b, String name) {
- if (b.traps == null) return null;
- String currentFunctionNodeName = JS.Thread.fromJavaThread(java.lang.Thread.currentThread()).getCurrentCompiledFunction().getSourceName();
- for(Trap cur = (Trap)b.traps.get(name); cur != null; cur = cur.next)
- if (cur.placerNodeName.equals(currentFunctionNodeName))
- return cur;
-
- return null;
+ /**
+ * deletes a trap.
+ * @param trapee the box to remove the trap from
+ * @param name the name of the property to trap on
+ * @param f the function to remove
+ */
+ static void delTrap(Box trapee, Object name, JS.CompiledFunction f) {
+ Trap t = (Trap)trapee.get(name, Trap.class);
+ if (t.f == f) {
+ trapee.put(name, Trap.class, t.next);
+ return;
+ }
+ for(; t.next != null; t = t.next)
+ if (t.next.f == f) {
+ t.next = t.next.next;
+ return;
+ }
+ Log.logJS("warning: tried to remove a trap that had not been placed");
}
- // Instance Methods //////////////////////////////////////////////////////////////////////////
-
- private Trap() { allTraps.put(myWeak, dummy); }
- /** perform this trap -- arg.length == 0 if this is a get; otherwise it contains a single element to be put */
- public Object perform(JS.Array jsArrayArgs) throws JS.Exn {
- // TrapContext tc = TrapContext.get();
- TrapArgs args = new TrapArgs(this,jsArrayArgs);
+ // Instance Methods //////////////////////////////////////////////////////////////////////////
- // invoke the trap function
- try {
- if (!isreadtrap && args.length() == 0) return cascade(args);
+ private Trap() { }
- if (f == null) {
- if (Log.verbose) Log.log(this, "debug: reclaimed a dangling trap on property " + name);
- Object ret = cascade(args);
- delete();
- return ret;
- }
-
- Object ret = f.call(args);
-
- // autocascade if required
- if(args.length() > 0 && !isreadtrap && !args.cascadeHappened) cascade(args);
-
- return ret;
-
- } finally {
-
- }
+ public Object perform() throws JS.Exn {
+ if (f.getNumFormalArgs() > 0) return cascade();
+ return f.call(new TrapArgs(this));
}
- public Object cascade(JS.Array args) {
- // if we've hit the end of the trap stack, just do a put(,,,true)
- if (next == null) {
- if (args.length() == 0) return trapee.get(name, true);
- trapee.put(name, args.elementAt(0), true);
- return null;
- }
- return next.perform(args);
+ public void perform(Object val) throws JS.Exn {
+ if (f.getNumFormalArgs()== 0) cascade(val);
+ f.call(new TrapArgs(this, val));
+ }
+
+ public Object cascade() {
+ if (next != null) return next.perform();
+ return trapee.get(name, true);
}
- /** removes this trap */
- public void delete() {
- for(Trap last = null, cur = (Trap)trapee.traps.get(name); cur != null; last = cur, cur = cur.next) {
- if (cur != this) continue;
- else if (last != null) last.next = cur.next;
- else if (cur.next == null) trapee.traps.remove(name);
- else trapee.traps.put(name, cur.next);
- }
- if (trapee.surface != null && !trapee.is_trapped("KeyPressed") && !trapee.is_trapped("KeyReleased"))
- trapee.surface.keywatchers.removeElement(trapee);
- allTraps.remove(myWeak);
+ public void cascade(Object val) {
+ if (next != null) next.perform(val);
+ trapee.put(name, val, true);
}
-
+
private static class TrapArgs extends JS.Array {
- public boolean cascadeHappened;
private Trap t;
- public TrapArgs(Trap t,JS.Array args) {
- int size = args.length();
- setSize(size);
- for(int i=0;i