[prev in list] [next in list] [prev in thread] [next in thread]
List: batik-dev
Subject: cvs commit: xml-batik/sources/org/apache/batik/bridge BridgeContext.java BridgeEventSupport.java SVG
From: tkormann () apache ! org
Date: 2002-05-22 11:18:18
[Download RAW message or body]
tkormann 02/05/22 04:18:18
Modified: sources/org/apache/batik/bridge BridgeContext.java
BridgeEventSupport.java SVGAElementBridge.java
SVGTextElementBridge.java
Log:
fix two memory leaks (remove 'local' listeners from the elements on
bridgeContext.dispose()). This is due to the fact that the
SVGAElementBridge and SVGTextElementBridge attach 'local' listeners.
Now, *all* bridges that are attaching 'local' listeners on elements
*must* call storeEventListener on the BridgeContext and so the dispose
method of the BridgeContext can remove those listeners later.
Revision Changes Path
1.48 +49 -15 xml-batik/sources/org/apache/batik/bridge/BridgeContext.java
Index: BridgeContext.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/BridgeContext.java,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -r1.47 -r1.48
--- BridgeContext.java 22 May 2002 10:06:55 -0000 1.47
+++ BridgeContext.java 22 May 2002 11:18:17 -0000 1.48
@@ -66,7 +66,7 @@
* a SVG DOM tree such as the current viewport or the user agent.
*
* @author <a href="mailto:Thierry.Kormann@sophia.inria.fr">Thierry Kormann</a>
- * @version $Id: BridgeContext.java,v 1.47 2002/05/22 10:06:55 tkormann Exp $
+ * @version $Id: BridgeContext.java,v 1.48 2002/05/22 11:18:17 tkormann Exp $
*/
public class BridgeContext implements ErrorConstants, CSSContext {
@@ -711,9 +711,10 @@
// dynamic support ////////////////////////////////////////////////////////
/**
- * The DOM EventListener to receive 'DOMCharacterDataModified' event.
+ * The list of all EventListener attached by bridges that need to
+ * be removed on a dispose() call.
*/
- protected EventListener unloadListener;
+ protected List eventListenerList = new LinkedList();
/**
* The DOM EventListener to receive 'DOMCharacterDataModified' event.
@@ -746,13 +747,6 @@
protected FocusManager focusManager;
/**
- * Sets the unload listener.
- */
- protected void setUnloadListener(EventListener l) {
- unloadListener = l;
- }
-
- /**
* Adds EventListeners to the DOM and CSSEngineListener to the
* CSSEngine to handle any modifications on the DOM tree or style
* properties and update the GVT tree in response.
@@ -790,13 +784,52 @@
}
/**
+ * Adds to the eventListenerList the specified event listener
+ * registration.
+ */
+ protected void storeEventListener(EventTarget t,
+ String s,
+ EventListener l,
+ boolean b) {
+ eventListenerList.add(new EventListenerMememto(t, s, l, b));
+ }
+
+ /**
+ * A class used to store an EventListener added to the DOM.
+ */
+ protected static class EventListenerMememto {
+
+ public EventTarget target;
+ public EventListener listener;
+ public boolean useCapture;
+ public String eventType;
+
+ public EventListenerMememto(EventTarget t,
+ String s,
+ EventListener l,
+ boolean b) {
+ target = t;
+ eventType = s;
+ listener = l;
+ useCapture = b;
+ }
+ }
+
+ /**
* Disposes this BridgeContext.
*/
public void dispose() {
- EventTarget evtTarget = (EventTarget)document;
- // remove the listener added by BridgeEventSupport
- evtTarget.removeEventListener("SVGUnload", unloadListener, false);
+ // remove all listeners added by Bridges
+ Iterator iter = eventListenerList.iterator();
+ while (iter.hasNext()) {
+ EventListenerMememto m = (EventListenerMememto)iter.next();
+ m.target.removeEventListener(m.eventType,
+ m.listener,
+ m.useCapture);
+ }
+
+ EventTarget evtTarget = (EventTarget)document;
evtTarget.removeEventListener("DOMAttrModified",
domAttrModifiedEventListener,
@@ -815,8 +848,9 @@
CSSEngine cssEngine = svgDocument.getCSSEngine();
cssEngine.removeCSSEngineListener(cssPropertiesChangedListener);
cssEngine.dispose();
-
- focusManager.dispose();
+ if (focusManager != null) {
+ focusManager.dispose();
+ }
}
/**
1.38 +4 -3 xml-batik/sources/org/apache/batik/bridge/BridgeEventSupport.java
Index: BridgeEventSupport.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/BridgeEventSupport.java,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- BridgeEventSupport.java 22 May 2002 10:06:55 -0000 1.37
+++ BridgeEventSupport.java 22 May 2002 11:18:17 -0000 1.38
@@ -50,7 +50,7 @@
* fowarding them to the DOM as regular DOM MouseEvent.
*
* @author <a href="mailto:tkormann@ilog.fr>Thierry Kormann</a>
- * @version $Id: BridgeEventSupport.java,v 1.37 2002/05/22 10:06:55 tkormann Exp $
+ * @version $Id: BridgeEventSupport.java,v 1.38 2002/05/22 11:18:17 tkormann Exp $
*/
public class BridgeEventSupport implements SVGConstants {
@@ -70,8 +70,9 @@
// add an unload listener on the SVGDocument to remove
// that listener for dispatching events
EventListener l = new GVTUnloadListener(dispatcher, listener);
- ((EventTarget)doc).addEventListener("SVGUnload", l, false);
- ctx.setUnloadListener(l);
+ EventTarget target = (EventTarget)doc;
+ target.addEventListener("SVGUnload", l, false);
+ ctx.storeEventListener(target, "SVGUnload", l, false);
}
}
}
1.17 +12 -12 xml-batik/sources/org/apache/batik/bridge/SVGAElementBridge.java
Index: SVGAElementBridge.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGAElementBridge.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- SVGAElementBridge.java 15 May 2002 14:14:30 -0000 1.16
+++ SVGAElementBridge.java 22 May 2002 11:18:17 -0000 1.17
@@ -24,7 +24,7 @@
* Bridge class for the <a> element.
*
* @author <a href="mailto:tkormann@apache.org">Thierry Kormann</a>
- * @version $Id: SVGAElementBridge.java,v 1.16 2002/05/15 14:14:30 deweese Exp $
+ * @version $Id: SVGAElementBridge.java,v 1.17 2002/05/22 11:18:17 tkormann Exp $
*/
public class SVGAElementBridge extends AbstractGraphicsNodeBridge {
@@ -63,17 +63,17 @@
EventTarget target = (EventTarget)e;
- target.addEventListener(SVG_EVENT_CLICK,
- new AnchorListener(ctx.getUserAgent()),
- false);
-
- target.addEventListener(SVG_EVENT_MOUSEOVER,
- new CursorMouseOverListener(ctx.getUserAgent()),
- false);
-
- target.addEventListener(SVG_EVENT_MOUSEOUT,
- new CursorMouseOutListener(ctx.getUserAgent()),
- false);
+ EventListener l = new AnchorListener(ctx.getUserAgent());
+ target.addEventListener(SVG_EVENT_CLICK, l, false);
+ ctx.storeEventListener(target, SVG_EVENT_CLICK, l, false);
+
+ l = new CursorMouseOverListener(ctx.getUserAgent());
+ target.addEventListener(SVG_EVENT_MOUSEOVER, l, false);
+ ctx.storeEventListener(target, SVG_EVENT_MOUSEOVER, l, false);
+
+ l = new CursorMouseOutListener(ctx.getUserAgent());
+ target.addEventListener(SVG_EVENT_MOUSEOUT, l, false);
+ ctx.storeEventListener(target, SVG_EVENT_MOUSEOUT, l, false);
}
/**
1.68 +21 -20 xml-batik/sources/org/apache/batik/bridge/SVGTextElementBridge.java
Index: SVGTextElementBridge.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGTextElementBridge.java,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -r1.67 -r1.68
--- SVGTextElementBridge.java 14 May 2002 21:28:13 -0000 1.67
+++ SVGTextElementBridge.java 22 May 2002 11:18:17 -0000 1.68
@@ -69,7 +69,7 @@
*
* @author <a href="stephane@hillion.org">Stephane Hillion</a>
* @author <a href="bill.haneman@ireland.sun.com">Bill Haneman</a>
- * @version $Id: SVGTextElementBridge.java,v 1.67 2002/05/14 21:28:13 tkormann Exp $
+ * @version $Id: SVGTextElementBridge.java,v 1.68 2002/05/22 11:18:17 tkormann Exp $
*/
public class SVGTextElementBridge extends AbstractGraphicsNodeBridge {
@@ -273,14 +273,17 @@
//to be notified when a child is removed from the
//<text> element.
- evtTarget.addEventListener("DOMNodeRemoved",
- childNodeRemovedEventListener,
- true);
+ evtTarget.addEventListener
+ ("DOMNodeRemoved", childNodeRemovedEventListener, true);
+ ctx.storeEventListener
+ (evtTarget, "DOMNodeRemoved", childNodeRemovedEventListener, true);
+
//to be notified when the modification of the subtree
//of the <text> element is done
- evtTarget.addEventListener("DOMSubtreeModified",
- subtreeModifiedEventListener,
- false);
+ evtTarget.addEventListener
+ ("DOMSubtreeModified", subtreeModifiedEventListener, false);
+ ctx.storeEventListener
+ (evtTarget, "DOMSubtreeModified", subtreeModifiedEventListener, false);
// traverse the children to add context on
// <tspan>, <tref> and <textPath>
@@ -733,20 +736,18 @@
} else if (ln.equals(SVG_A_TAG)) {
EventTarget target = (EventTarget)nodeElement;
UserAgent ua = ctx.getUserAgent();
- target.addEventListener
- (SVG_EVENT_CLICK,
- new SVGAElementBridge.AnchorListener(ua),
- false);
-
- target.addEventListener
- (SVG_EVENT_MOUSEOVER,
- new SVGAElementBridge.CursorMouseOverListener(ua),
- false);
+ EventListener l = new SVGAElementBridge.AnchorListener(ua);
+ target.addEventListener(SVG_EVENT_CLICK, l, false);
+ ctx.storeEventListener(target, SVG_EVENT_CLICK, l, false);
- target.addEventListener
- (SVG_EVENT_MOUSEOUT,
- new SVGAElementBridge.CursorMouseOutListener(ua),
- false);
+ l = new SVGAElementBridge.CursorMouseOverListener(ua);
+ target.addEventListener(SVG_EVENT_MOUSEOVER, l, false);
+ ctx.storeEventListener(target, SVG_EVENT_MOUSEOVER, l, false);
+
+ l = new SVGAElementBridge.CursorMouseOutListener(ua);
+ target.addEventListener(SVG_EVENT_MOUSEOUT, l, false);
+ ctx.storeEventListener(target, SVG_EVENT_MOUSEOUT, l, false);
+
fillAttributedStringBuffer(ctx,
nodeElement,
false,
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic