[prev in list] [next in list] [prev in thread] [next in thread] 

List:       batik-dev
Subject:    cvs commit: xml-batik/sources/org/apache/batik/swing/svg JSVGComponent.java
From:       tkormann () apache ! org
Date:       2002-05-22 10:06:56
[Download RAW message or body]

tkormann    02/05/22 03:06:56

  Modified:    sources/org/apache/batik/bridge BridgeContext.java
                        BridgeEventSupport.java GVTBuilder.java
               sources/org/apache/batik/swing/svg JSVGComponent.java
  Log:
  memory leak fix. svgCanvas.setSVGDocument(svgCanvas.getSVGDocument())
  now works. All attached listeners are now removed by using the
  bridgeContext.dispose() method.
  
  Revision  Changes    Path
  1.47      +18 -1     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.46
  retrieving revision 1.47
  diff -u -r1.46 -r1.47
  --- BridgeContext.java	22 Apr 2002 17:08:55 -0000	1.46
  +++ BridgeContext.java	22 May 2002 10:06:55 -0000	1.47
  @@ -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.46 2002/04/22 17:08:55 tkormann Exp $
  + * @version $Id: BridgeContext.java,v 1.47 2002/05/22 10:06:55 tkormann Exp $
    */
   public class BridgeContext implements ErrorConstants, CSSContext {
   
  @@ -713,6 +713,11 @@
       /**
        * The DOM EventListener to receive 'DOMCharacterDataModified' event.
        */
  +    protected EventListener unloadListener;
  +
  +    /**
  +     * The DOM EventListener to receive 'DOMCharacterDataModified' event.
  +     */
       protected EventListener domCharacterDataModifiedListener;
   
       /**
  @@ -741,6 +746,13 @@
       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.
  @@ -782,6 +794,10 @@
        */
       public void dispose() {
           EventTarget evtTarget = (EventTarget)document;
  +
  +        // remove the listener added by BridgeEventSupport
  +        evtTarget.removeEventListener("SVGUnload", unloadListener, false);
  +
           evtTarget.removeEventListener("DOMAttrModified",
                                         domAttrModifiedEventListener, 
                                         true);
  @@ -798,6 +814,7 @@
           SVGOMDocument svgDocument = (SVGOMDocument)document;
           CSSEngine cssEngine = svgDocument.getCSSEngine();
           cssEngine.removeCSSEngineListener(cssPropertiesChangedListener);
  +        cssEngine.dispose();
   
           focusManager.dispose();
       }
  
  
  
  1.37      +5 -6      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.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- BridgeEventSupport.java	17 May 2002 08:16:53 -0000	1.36
  +++ BridgeEventSupport.java	22 May 2002 10:06:55 -0000	1.37
  @@ -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.36 2002/05/17 08:16:53 tkormann Exp $
  + * @version $Id: BridgeEventSupport.java,v 1.37 2002/05/22 10:06:55 tkormann Exp $
    */
   public class BridgeEventSupport implements SVGConstants {
   
  @@ -60,7 +60,7 @@
        * Is called only for the root element in order to dispatch GVT
        * events to the DOM.
        */
  -    public static void addGVTListener(BridgeContext ctx, Element svgRoot) {
  +    public static void addGVTListener(BridgeContext ctx, Document doc) {
           UserAgent ua = ctx.getUserAgent();
           if (ua != null) {
               EventDispatcher dispatcher = ua.getEventDispatcher();
  @@ -69,10 +69,9 @@
                   dispatcher.addGraphicsNodeMouseListener(listener);
                   // add an unload listener on the SVGDocument to remove
                   // that listener for dispatching events
  -                ((EventTarget)svgRoot).addEventListener
  -                    ("SVGUnload",
  -                     new GVTUnloadListener(dispatcher, listener),
  -                     false);
  +                EventListener l = new GVTUnloadListener(dispatcher, listener);
  +                ((EventTarget)doc).addEventListener("SVGUnload", l, false);
  +                ctx.setUnloadListener(l);
               }
           }
       }
  
  
  
  1.21      +2 -2      xml-batik/sources/org/apache/batik/bridge/GVTBuilder.java
  
  Index: GVTBuilder.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/GVTBuilder.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- GVTBuilder.java	11 Apr 2002 08:42:22 -0000	1.20
  +++ GVTBuilder.java	22 May 2002 10:06:55 -0000	1.21
  @@ -30,7 +30,7 @@
    * This class is responsible for creating a GVT tree using an SVG DOM tree.
    *
    * @author <a href="mailto:tkormann@apache.org">Thierry Kormann</a>
  - * @version $Id: GVTBuilder.java,v 1.20 2002/04/11 08:42:22 tkormann Exp $
  + * @version $Id: GVTBuilder.java,v 1.21 2002/05/22 10:06:55 tkormann Exp $
    */
   public class GVTBuilder implements SVGConstants {
   
  @@ -87,7 +87,7 @@
           // <!> FIXME: TO BE REMOVED
           if (ctx.isDynamic()) {
               // register GVT listeners for AWT event support
  -            BridgeEventSupport.addGVTListener(ctx, svgElement);
  +            BridgeEventSupport.addGVTListener(ctx, document);
               // register DOM listeners for dynamic support
               ctx.addDOMListeners();
           }
  
  
  
  1.52      +4 -1      xml-batik/sources/org/apache/batik/swing/svg/JSVGComponent.java
  
  Index: JSVGComponent.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/swing/svg/JSVGComponent.java,v
  retrieving revision 1.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- JSVGComponent.java	30 Apr 2002 08:45:15 -0000	1.51
  +++ JSVGComponent.java	22 May 2002 10:06:55 -0000	1.52
  @@ -186,7 +186,7 @@
    * building/rendering a document (invalid XML file, missing attributes...).</p>
    *
    * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
  - * @version $Id: JSVGComponent.java,v 1.51 2002/04/30 08:45:15 vhardy Exp $
  + * @version $Id: JSVGComponent.java,v 1.52 2002/05/22 10:06:55 tkormann Exp $
    */
   public class JSVGComponent extends JGVTComponent {
   
  @@ -482,6 +482,9 @@
               (null, SVGConstants.SVG_ZOOM_AND_PAN_ATTRIBUTE);
           disableInteractions = !znp.equals(SVGConstants.SVG_MAGNIFY_VALUE);
   
  +        if (bridgeContext != null) {
  +            bridgeContext.dispose();
  +        }
           bridgeContext = createBridgeContext();
           nextGVTTreeBuilder = new GVTTreeBuilder(doc, bridgeContext);
           nextGVTTreeBuilder.setPriority(Thread.MIN_PRIORITY);
  
  
  

---------------------------------------------------------------------
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