You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-commits@xmlgraphics.apache.org by de...@apache.org on 2005/12/19 02:59:34 UTC

svn commit: r357610 - /xmlgraphics/batik/trunk/sources/org/apache/batik/script/rhino/EventTargetWrapper.java

Author: deweese
Date: Sun Dec 18 17:59:30 2005
New Revision: 357610

URL: http://svn.apache.org/viewcvs?rev=357610&view=rev
Log:
Fixed bug with event removal for multiple events and the same target (thanks Andreas)

Modified:
    xmlgraphics/batik/trunk/sources/org/apache/batik/script/rhino/EventTargetWrapper.java

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/script/rhino/EventTargetWrapper.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/trunk/sources/org/apache/batik/script/rhino/EventTargetWrapper.java?rev=357610&r1=357609&r2=357610&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/script/rhino/EventTargetWrapper.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/script/rhino/EventTargetWrapper.java Sun Dec 18 17:59:30 2005
@@ -397,9 +397,15 @@
             throws JavaScriptException {
             NativeJavaObject  njo = (NativeJavaObject)thisObj;
             if (args[1] instanceof Function) {
-                EventListener evtListener = new FunctionEventListener
-                    ((Function)args[1], interpreter);
-                listenerMap.put(args[1], new SoftReference(evtListener));
+                EventListener evtListener = null;
+                SoftReference sr = (SoftReference)listenerMap.get(args[1]);
+                if (sr != null) 
+                    evtListener = (EventListener)sr.get();
+                if (evtListener == null) {
+                    evtListener = new FunctionEventListener
+                        ((Function)args[1], interpreter);
+                    listenerMap.put(args[1], new SoftReference(evtListener));
+                }
                 // we need to marshall args
                 Class[] paramTypes = { String.class, Function.class,
                                        Boolean.TYPE };
@@ -411,10 +417,16 @@
                 return Undefined.instance;
             }
             if (args[1] instanceof NativeObject) {
-                EventListener evtListener =
-                    new HandleEventListener((Scriptable)args[1],
-                                            interpreter);
-                listenerMap.put(args[1], new SoftReference(evtListener));
+                EventListener evtListener = null;
+                SoftReference sr = (SoftReference)listenerMap.get(args[1]);
+                if (sr != null) 
+                    evtListener = (EventListener)sr.get();
+                if (evtListener == null) {
+                    evtListener = new HandleEventListener((Scriptable)args[1],
+                                                          interpreter);
+                    listenerMap.put(args[1], new SoftReference(evtListener));
+                }
+
                 // we need to marshall args
                 Class[] paramTypes = { String.class, Scriptable.class,
                                        Boolean.TYPE };
@@ -448,6 +460,7 @@
                 EventListener el = (EventListener)sr.get();
                 if (el == null)
                     return Undefined.instance;
+
                 // we need to marshall args
                 Class[] paramTypes = { String.class, Function.class,
                                        Boolean.TYPE };
@@ -469,7 +482,6 @@
                                        Boolean.TYPE };
                 for (int i = 0; i < args.length; i++)
                     args[i] = Context.toType(args[i], paramTypes[i]);
-
                 ((EventTarget)njo.unwrap()).removeEventListener
                     ((String)args[0], el, ((Boolean)args[2]).booleanValue());
                 return Undefined.instance;