projects
/
org.ibex.core.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
2002/10/16 06:22:38
[org.ibex.core.git]
/
src
/
org
/
xwt
/
Trap.java
diff --git
a/src/org/xwt/Trap.java
b/src/org/xwt/Trap.java
index
d2b3954
..
23a3455
100644
(file)
--- a/
src/org/xwt/Trap.java
+++ b/
src/org/xwt/Trap.java
@@
-16,7
+16,7
@@
public class Trap {
// Static Data //////////////////////////////////////////////////////////////
/** a vector of weak references to all instances of Trap; used for retheming */
// Static Data //////////////////////////////////////////////////////////////
/** a vector of weak references to all instances of Trap; used for retheming */
- private static Vec allTraps = new Vec(1000);
+ private static Hashtable allTraps = new Hashtable(1000);
/** List of properties that cannot be trapped */
private static final Hash PROHIBITED = new Hash(120, 3);
/** List of properties that cannot be trapped */
private static final Hash PROHIBITED = new Hash(120, 3);
@@
-32,6
+32,9
@@
public class Trap {
for(int i=0; i<p.length; i++) PROHIBITED.put(p[i], Boolean.TRUE);
};
for(int i=0; i<p.length; i++) PROHIBITED.put(p[i], Boolean.TRUE);
};
+ private static Object dummy = new Object();
+
+
// Instance Members ////////////////////////////////////////////////////////
/** the box on which this trap was placed */
// Instance Members ////////////////////////////////////////////////////////
/** the box on which this trap was placed */
@@
-55,8
+58,9
@@
public class Trap {
/** The nodeName of the Template whose script placed the trap. See Template.nodeName for more detail. */
private String placerNodeName = null;
/** The nodeName of the Template whose script placed the trap. See Template.nodeName for more detail. */
private String placerNodeName = null;
- /** the index of this Trap in the allTraps vector */
- private int indexInAllTraps = 0;
+ /** our weak reference in the allTraps Hash */
+ private Weak myWeak = Platform.getWeak(this);
+
// Static Methods //////////////////////////////////////////////////////////////////////////
// Static Methods //////////////////////////////////////////////////////////////////////////
@@
-144,27
+148,36
@@
public class Trap {
else return current.trapee;
}
else return current.trapee;
}
+ /** called by Rhino's arguments.trapname hack */
+ public static String currentTrapname() {
+ Trap current = TrapContext.get().currentTrap;
+ if (current == null) return null;
+ else return current.name;
+ }
+
/** removes all traps whose function's ultimate parent scope is <tt>b</tt>. Used for retheming */
public static void removeAllTrapsByBox(Box b) {
/** removes all traps whose function's ultimate parent scope is <tt>b</tt>. Used for retheming */
public static void removeAllTrapsByBox(Box b) {
- for(int i=0; i<allTraps.size(); i++) {
- Trap t = (Trap)((Weak)allTraps.elementAt(i)).get();
- if (t == null) continue;
+ Enumeration e = allTraps.keys();
+ while(e.hasMoreElements()) {
+ Weak w = (Weak)e.nextElement();
+ Trap t = (Trap)w.get();
+ if (t == null) {
+ allTraps.remove(w);
+ continue;
+ }
for(Scriptable cur = t.f; cur != null; cur = cur.getParentScope()) {
if (cur == b) {
t.delete();
for(Scriptable cur = t.f; cur != null; cur = cur.getParentScope()) {
if (cur == b) {
t.delete();
- i--;
break;
}
}
}
}
break;
}
}
}
}
+
// Instance Methods //////////////////////////////////////////////////////////////////////////
// Instance Methods //////////////////////////////////////////////////////////////////////////
- private Trap() {
- indexInAllTraps = allTraps.size();
- allTraps.addElement(Platform.getWeak(this));
- }
+ 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(Object[] arg) {
/** perform this trap -- arg.length == 0 if this is a get; otherwise it contains a single element to be put */
public Object perform(Object[] arg) {
@@
-220,11
+233,7
@@
public class Trap {
}
if (trapee.surface != null && !trapee.is_trapped("KeyPressed") && !trapee.is_trapped("KeyReleased"))
trapee.surface.keywatchers.removeElement(trapee);
}
if (trapee.surface != null && !trapee.is_trapped("KeyPressed") && !trapee.is_trapped("KeyReleased"))
trapee.surface.keywatchers.removeElement(trapee);
- if (allTraps.size() == 1) allTraps.setSize(0);
- else {
- allTraps.setElementAt(allTraps.elementAt(allTraps.size() - 1), indexInAllTraps);
- allTraps.setSize(allTraps.size() - 1);
- }
+ allTraps.remove(myWeak);
}
/** per-thread storage for Traps */
}
/** per-thread storage for Traps */
@@
-250,3
+259,4
@@
public class Trap {
}
}
}
}
+