hillion     02/02/21 02:33:44

  Modified:    sources/org/apache/batik/bridge RepaintManager.java
                        ScriptingEnvironment.java UpdateManager.java
               sources/org/apache/batik/swing JSVGCanvas.java
               sources/org/apache/batik/swing/gvt
                        AbstractPanInteractor.java
               sources/org/apache/batik/swing/svg JSVGComponent.java
  Log:
  - JSVGComponent cleanup.
  
  Revision  Changes    Path
  1.8       +3 -6      xml-batik/sources/org/apache/batik/bridge/RepaintManager.java
  
  Index: RepaintManager.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/RepaintManager.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- RepaintManager.java       19 Feb 2002 18:01:29 -0000      1.7
  +++ RepaintManager.java       21 Feb 2002 10:33:43 -0000      1.8
  @@ -26,7 +26,7 @@
    * This class manages the rendering of a GVT tree.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Stephane Hillion</a>
  - * @version $Id: RepaintManager.java,v 1.7 2002/02/19 18:01:29 deweese Exp $
  + * @version $Id: RepaintManager.java,v 1.8 2002/02/21 10:33:43 hillion Exp $
    */
   public class RepaintManager {
       
  @@ -57,7 +57,7 @@
        * Provokes a repaint, if needed.
        * @param b If true, waits until the repaint has finished.
        */
  -    public void repaint(boolean b) {
  +    public void repaint(boolean b) throws InterruptedException {
           if (!enabled) {
               return;
           }
  @@ -80,10 +80,7 @@
               return;
           }
           if (b) {
  -            try {
  -                updateManager.getUpdateRunnableQueue().invokeAndWait(r);
  -            } catch (InterruptedException e) {
  -            }
  +            updateManager.getUpdateRunnableQueue().invokeAndWait(r);
           } else {
               updateManager.getUpdateRunnableQueue().invokeLater(r);
           }
  
  
  
  1.6       +62 -19    
xml-batik/sources/org/apache/batik/bridge/ScriptingEnvironment.java
  
  Index: ScriptingEnvironment.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/sources/org/apache/batik/bridge/ScriptingEnvironment.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ScriptingEnvironment.java 18 Feb 2002 09:11:58 -0000      1.5
  +++ ScriptingEnvironment.java 21 Feb 2002 10:33:43 -0000      1.6
  @@ -52,7 +52,7 @@
    * This class contains the informations needed by the SVG scripting.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Stephane Hillion</a>
  - * @version $Id: ScriptingEnvironment.java,v 1.5 2002/02/18 09:11:58 hillion Exp $
  + * @version $Id: ScriptingEnvironment.java,v 1.6 2002/02/21 10:33:43 hillion Exp $
    */
   public class ScriptingEnvironment {
   
  @@ -207,6 +207,17 @@
       protected JavaFunction alertFunction;
   
       /**
  +     * The live scripting threads.
  +     */
  +    protected List liveThreads =
  +        Collections.synchronizedList(new LinkedList());
  +
  +    /**
  +     * Whether this environment has been interrupted.
  +     */
  +    protected boolean interrupted;
  +
  +    /**
        * Creates a new ScriptingEnvironment.
        * @param um The update manager.
        */
  @@ -250,6 +261,20 @@
       }
   
       /**
  +     * Interrupts the scripts.
  +     */
  +    public void interruptScripts() {
  +        synchronized (liveThreads) {
  +            interrupted = true;
  +            Iterator it = liveThreads.iterator();
  +            while (it.hasNext()) {
  +                scriptingLock.unlock();
  +                ((Thread)it.next()).interrupt();
  +            }
  +        }
  +    }
  +
  +    /**
        * Suspends the scripts.
        */
       public void suspendScripts() {
  @@ -262,7 +287,7 @@
       public void resumeScripts() {
           synchronized (suspendLock) {
               suspended = false;
  -            suspendLock.notify();
  +            suspendLock.notifyAll();
           }
       }
   
  @@ -280,12 +305,16 @@
                   try {
                       suspendLock.wait();
                   } catch (InterruptedException e) {
  +                    throw new StopScriptException();
                   }
               }
           }
   
           if (repaintManager == null) {
               repaintManager = updateManager.getRepaintManager();
  +            if (repaintManager == null) {
  +                throw new StopScriptException();
  +            }
               updateRunnableQueue = updateManager.getUpdateRunnableQueue();
           }
   
  @@ -306,6 +335,7 @@
                   try {
                       suspendLock.wait();
                   } catch (InterruptedException e) {
  +                    throw new StopScriptException();
                   }
               }
           }
  @@ -315,7 +345,12 @@
               throw new StopScriptException();
           }
           updateRunnableQueue.resumeExecution();
  -        repaintManager.repaint(true);
  +    
  +        try {
  +            repaintManager.repaint(true);
  +        } catch (InterruptedException e) {
  +            throw new StopScriptException();
  +        }
           scriptingLock.unlock();
       }
   
  @@ -541,28 +576,36 @@
            * The main method.
            */
           public void run() {
  -            if (interpreter != null) {
  -                try {
  -                    beginScript();
  -                } catch (StopScriptException e) {
  +            try {
  +                liveThreads.add(this);
  +                if (interrupted) {
                       return;
                   }
  -
  -                try {
  -                    interpreter.evaluate(getScript());
  -                } catch (InterpreterException ie) {
  -                    Exception ex = ie.getException();
  -                    if (ex instanceof StopScriptException) {
  +                if (interpreter != null) {
  +                    try {
  +                        beginScript();
  +                    } catch (StopScriptException e) {
                           return;
                       }
  -                    if (userAgent != null) {
  -                        userAgent.displayError((ex != null) ? ex : ie);
  +                    
  +                    try {
  +                        interpreter.evaluate(getScript());
  +                    } catch (InterpreterException ie) {
  +                        Exception ex = ie.getException();
  +                        if (ex instanceof StopScriptException) {
  +                            return;
  +                        }
  +                        if (userAgent != null) {
  +                            userAgent.displayError((ex != null) ? ex : ie);
  +                        }
  +                    }
  +                    try {
  +                        endScript();
  +                    } catch (StopScriptException e) {
                       }
                   }
  -                try {
  -                    endScript();
  -                } catch (StopScriptException e) {
  -                }
  +            } finally {
  +                liveThreads.remove(this);
               }
           }
   
  
  
  
  1.10      +75 -36    xml-batik/sources/org/apache/batik/bridge/UpdateManager.java
  
  Index: UpdateManager.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/UpdateManager.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- UpdateManager.java        18 Feb 2002 12:39:48 -0000      1.9
  +++ UpdateManager.java        21 Feb 2002 10:33:43 -0000      1.10
  @@ -44,7 +44,7 @@
    * This class provides features to manage the update of an SVG document.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Stephane Hillion</a>
  - * @version $Id: UpdateManager.java,v 1.9 2002/02/18 12:39:48 hillion Exp $
  + * @version $Id: UpdateManager.java,v 1.10 2002/02/21 10:33:43 hillion Exp $
    */
   public class UpdateManager implements RunnableQueue.RunHandler {
   
  @@ -93,7 +93,7 @@
       /**
        * Whether the update manager is running.
        */
  -    protected volatile boolean running;
  +    protected boolean running;
   
       /**
        * Whether the suspend() method was called.
  @@ -136,6 +136,11 @@
       protected GraphicsNode graphicsNode;
   
       /**
  +     * Whether the manager was started.
  +     */
  +    protected boolean started;
  +
  +    /**
        * Creates a new update manager.
        * @param ctx The bridge context.
        * @param gn GraphicsNode whose updates are to be tracked.
  @@ -158,25 +163,54 @@
       }
   
       /**
  -     * Finishes the UpdateManager initialization.
  +     * Dispatches an 'SVGLoad' event to the document.
  +     * NOTES:
  +     * - This method starts the update manager threads so one can't use
  +     *   the update runnable queue to invoke this method.
  +     * - The scripting lock is taken. Is is released by a call to
  +     *   manageUpdates().
        */
  -    public void manageUpdates(ImageRenderer r) {
  -        running = true;
  -        renderer = r;
  +    public void dispatchSVGLoadEvent() throws InterruptedException {
  +        // Locking avoid execution of scripts scheduled by calls
  +        // to the setTimeout() function.
  +        // The lock is be released by a call to manageUpdates().
  +        scriptingEnvironment.getScriptingLock().lock();
  +
  +        scriptingEnvironment.loadScripts();
  +        scriptingEnvironment.dispatchSVGLoadEvent();
           
  -        updateTracker = new UpdateTracker();
  -        RootGraphicsNode root = graphicsNode.getRoot();
  -        if (root != null){
  -            root.addTreeGraphicsNodeChangeListener(updateTracker);
  -        }
  +        updateRunnableQueue.resumeExecution();
  +    }
   
  -        repaintManager = new RepaintManager(this, renderer);
  -        repaintRateManager = new RepaintRateManager(this);
  -        repaintRateManager.start();
  +    /**
  +     * Finishes the UpdateManager initialization.
  +     */
  +    public void manageUpdates(final ImageRenderer r) {
  +        updateRunnableQueue.invokeLater(new Runnable() {
  +                public void run() {
  +                    startingTime = System.currentTimeMillis();
   
  -        scriptingEnvironment.getScriptingLock().unlock();
  +                    running = true;
  +                    renderer = r;
  +        
  +                    updateTracker = new UpdateTracker();
  +                    RootGraphicsNode root = graphicsNode.getRoot();
  +                    if (root != null){
  +                        root.addTreeGraphicsNodeChangeListener(updateTracker);
  +                    }
   
  -        fireManagerStartedEvent();
  +                    repaintManager =
  +                        new RepaintManager(UpdateManager.this, renderer);
  +                    repaintRateManager =
  +                        new RepaintRateManager(UpdateManager.this);
  +                    repaintRateManager.start();
  +                    
  +                    scriptingEnvironment.getScriptingLock().unlock();
  +                    
  +                    fireManagerStartedEvent();
  +                    started = true;
  +                }
  +            });
       }
   
   
  @@ -260,24 +294,25 @@
       }
   
       /**
  -     * Dispatches an 'SVGLoad' event to the document.
  -     * NOTES:
  -     * - This method starts the update manager threads so one can't use
  -     *   the update runnable queue to invoke this method.
  -     * - The scripting lock is taken. Is is released by a call to
  -     *   manageUpdates().
  +     * Interrupts the manager tasks.
        */
  -    public void dispatchSVGLoadEvent() throws InterruptedException {
  -        // Locking avoid execution of scripts scheduled by calls
  -        // to the setTimeout() function.
  -        // The lock is be released by a call to manageUpdates().
  -        scriptingEnvironment.getScriptingLock().lock();
  -
  -        scriptingEnvironment.loadScripts();
  -        scriptingEnvironment.dispatchSVGLoadEvent();
  -        
  -        updateRunnableQueue.resumeExecution();
  -        startingTime = System.currentTimeMillis();
  +    public void interrupt() {
  +        if (updateRunnableQueue.getThread() != null) {
  +            if (started) {
  +                dispatchSVGUnLoadEvent();
  +            } else {
  +                resume();
  +                updateRunnableQueue.invokeLater(new Runnable() {
  +                        public void run() {
  +                            if (repaintRateManager != null) {
  +                                repaintRateManager.interrupt();
  +                            }
  +                            scriptingEnvironment.interruptScripts();
  +                            updateRunnableQueue.getThread().interrupt();
  +                        }
  +                    });
  +            }
  +        }
       }
   
       /**
  @@ -286,6 +321,10 @@
        * NOTE: this method must be called outside the update thread.
        */
       public void dispatchSVGUnLoadEvent() {
  +        if (!started) {
  +            throw new IllegalStateException("UpdateManager not started.");
  +        }
  +
           resume();
           updateRunnableQueue.invokeLater(new Runnable() {
                   public void run() {
  @@ -296,9 +335,8 @@
                           dispatchEvent(evt);
                       running = false;
                       
  -                    if (repaintManager != null) {
  -                        repaintRateManager.interrupt();
  -                    }
  +                    repaintRateManager.interrupt();
  +                    scriptingEnvironment.interruptScripts();
                       updateRunnableQueue.getThread().interrupt();
                       fireManagerStoppedEvent();
                   }
  @@ -494,6 +532,7 @@
       public void executionResumed(RunnableQueue rq) {
           if (suspendCalled && !running) {
               running = true;
  +
               suspendCalled = false;
               suspendedTime = System.currentTimeMillis() - suspendStartTime;
               fireManagerResumedEvent();
  
  
  
  1.32      +2 -1      xml-batik/sources/org/apache/batik/swing/JSVGCanvas.java
  
  Index: JSVGCanvas.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/swing/JSVGCanvas.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- JSVGCanvas.java   29 Nov 2001 09:17:41 -0000      1.31
  +++ JSVGCanvas.java   21 Feb 2002 10:33:44 -0000      1.32
  @@ -69,7 +69,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Thierry Kormann</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Stephane Hillion</a>
  - * @version $Id: JSVGCanvas.java,v 1.31 2001/11/29 09:17:41 tkormann Exp $
  + * @version $Id: JSVGCanvas.java,v 1.32 2002/02/21 10:33:44 hillion Exp $
    */
   public class JSVGCanvas extends JSVGComponent {
   
  @@ -487,6 +487,7 @@
            * Called when the loading of a document was started.
            */
           public void documentLoadingStarted(SVGDocumentLoaderEvent e) {
  +            super.documentLoadingStarted(e);
               JSVGCanvas.this.setToolTipText(null);
           }
   
  
  
  
  1.2       +19 -9     
xml-batik/sources/org/apache/batik/swing/gvt/AbstractPanInteractor.java
  
  Index: AbstractPanInteractor.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/sources/org/apache/batik/swing/gvt/AbstractPanInteractor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractPanInteractor.java        8 Mar 2001 01:21:07 -0000       1.1
  +++ AbstractPanInteractor.java        21 Feb 2002 10:33:44 -0000      1.2
  @@ -22,7 +22,7 @@
    * InteractorAdapter#startInteraction(InputEvent)} method.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Stephane Hillion</a>
  - * @version $Id: AbstractPanInteractor.java,v 1.1 2001/03/08 01:21:07 hillion Exp $
  + * @version $Id: AbstractPanInteractor.java,v 1.2 2002/02/21 10:33:44 hillion Exp $
    */
   public abstract class AbstractPanInteractor extends InteractorAdapter {
   
  @@ -85,6 +85,7 @@
           yStart = e.getY();
   
           JGVTComponent c = (JGVTComponent)e.getSource();
  +
           previousCursor = c.getCursor();
           c.setCursor(PAN_CURSOR);
       }
  @@ -93,16 +94,24 @@
        * Invoked when a mouse button has been released on a component.
        */
       public void mouseReleased(MouseEvent e) {
  +        if (finished) {
  +            return;
  +        }
           finished = true;
   
           JGVTComponent c = (JGVTComponent)e.getSource();
   
  -        AffineTransform pt = c.getPaintingTransform();
  -        if (pt != null) {
  -            AffineTransform rt = (AffineTransform)c.getRenderingTransform().clone();
  -            rt.preConcatenate(pt);
  -            c.setRenderingTransform(rt);
  -        }
  +        xCurrent = e.getX();
  +        yCurrent = e.getY();
  +
  +        AffineTransform at =
  +            AffineTransform.getTranslateInstance(xCurrent - xStart,
  +                                                 yCurrent - yStart);
  +        AffineTransform rt =
  +            (AffineTransform)c.getRenderingTransform().clone();
  +        rt.preConcatenate(at);
  +        c.setRenderingTransform(rt);
  +
           if (c.getCursor() == PAN_CURSOR) {
               c.setCursor(previousCursor);
           }
  @@ -136,8 +145,9 @@
           xCurrent = e.getX();
           yCurrent = e.getY();
   
  -        AffineTransform at = AffineTransform.getTranslateInstance(xCurrent - xStart,
  -                                                                  yCurrent - 
yStart);
  +        AffineTransform at =
  +            AffineTransform.getTranslateInstance(xCurrent - xStart,
  +                                                 yCurrent - yStart);
           c.setPaintingTransform(at);
       }
   }
  
  
  
  1.42      +165 -166  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.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- JSVGComponent.java        20 Feb 2002 12:38:45 -0000      1.41
  +++ JSVGComponent.java        21 Feb 2002 10:33:44 -0000      1.42
  @@ -180,7 +180,7 @@
    * building/rendering a document (invalid XML file, missing attributes...).</p>
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Stephane Hillion</a>
  - * @version $Id: JSVGComponent.java,v 1.41 2002/02/20 12:38:45 hillion Exp $
  + * @version $Id: JSVGComponent.java,v 1.42 2002/02/21 10:33:44 hillion Exp $
    */
   public class JSVGComponent extends JGVTComponent {
   
  @@ -210,6 +210,21 @@
       protected GVTTreeBuilder nextGVTTreeBuilder;
   
       /**
  +     * The SVGLoadEventDispatcher.
  +     */
  +    protected SVGLoadEventDispatcher svgLoadEventDispatcher;
  +
  +    /**
  +     * The update manager.
  +     */
  +    protected UpdateManager updateManager;
  +
  +    /**
  +     * The next update manager.
  +     */
  +    protected UpdateManager nextUpdateManager;
  +
  +    /**
        * The current SVG document.
        */
       protected SVGDocument svgDocument;
  @@ -255,26 +270,11 @@
       protected BridgeContext bridgeContext;
   
       /**
  -     * The update manager.
  -     */
  -    protected UpdateManager updateManager;
  -
  -    /**
        * The current document fragment identifier.
        */
       protected String fragmentIdentifier;
   
       /**
  -     * Whether the update manager was stopped.
  -     */
  -    protected boolean updateManagerStopped;
  -
  -    /**
  -     * Whether the update manager was suspended.
  -     */
  -    protected boolean updateManagerSuspended;
  -
  -    /**
        * Whether the current document has dynamic features.
        */
       protected boolean isDynamicDocument;
  @@ -304,7 +304,6 @@
           addSVGDocumentLoaderListener((SVGListener)listener);
           addGVTTreeBuilderListener((SVGListener)listener);
           addSVGLoadEventDispatcherListener((SVGListener)listener);
  -        updateManagerListeners.add(listener);
       }
   
       /**
  @@ -344,10 +343,10 @@
               documentLoader.interrupt();
           } else if (gvtTreeBuilder != null) {
               gvtTreeBuilder.interrupt();
  +        } else if (svgLoadEventDispatcher != null) {
  +            svgLoadEventDispatcher.interrupt();
           } else if (updateManager != null) {
  -            updateManager.dispatchSVGUnLoadEvent();
  -            updateManager = null;
  -            updateManagerStopped = true;
  +            updateManager.interrupt();
           } else {
               super.stopProcessing();
           }
  @@ -389,7 +388,9 @@
   
           if (documentLoader == null &&
               gvtTreeBuilder == null &&
  -            gvtTreeRenderer == null) {
  +            gvtTreeRenderer == null &&
  +            svgLoadEventDispatcher == null &&
  +            updateManager == null) {
               startDocumentLoader();
           }
       }
  @@ -412,15 +413,6 @@
               throw new IllegalArgumentException("Invalid DOM implementation.");
           }
   
  -        if (isDynamicDocument &&
  -            eventsEnabled &&
  -            svgDocument != null &&
  -            updateManager != null) {
  -            updateManager.dispatchSVGUnLoadEvent();
  -            updateManager = null;
  -        }
  -        updateManagerStopped = false;
  -
           isDynamicDocument = UpdateManager.isDynamicDocument(doc);
           
           svgDocument = doc;
  @@ -445,7 +437,9 @@
   
           if (gvtTreeBuilder == null &&
               documentLoader == null &&
  -            gvtTreeRenderer == null) {
  +            gvtTreeRenderer == null &&
  +            svgLoadEventDispatcher == null &&
  +            updateManager == null) {
               startGVTTreeBuilder();
           }
       }
  @@ -504,20 +498,15 @@
        * Starts a SVGLoadEventDispatcher thread.
        */
       protected void startSVGLoadEventDispatcher(GraphicsNode root) {
  -        updateManager = new UpdateManager(bridgeContext,
  -                                          root,
  -                                          svgDocument);
  -        Iterator it = updateManagerListeners.iterator();
  -        while (it.hasNext()) {
  -            updateManager.addUpdateManagerListener
  -                ((UpdateManagerListener)it.next());
  -        }
  -
  -        SVGLoadEventDispatcher d = new SVGLoadEventDispatcher(root,
  -                                                        svgDocument,
  -                                                        bridgeContext,
  -                                                        updateManager);
  -        it = svgLoadEventDispatcherListeners.iterator();
  +        nextUpdateManager = new UpdateManager(bridgeContext,
  +                                              root,
  +                                              svgDocument);
  +        SVGLoadEventDispatcher d =
  +            new SVGLoadEventDispatcher(root,
  +                                       svgDocument,
  +                                       bridgeContext,
  +                                       nextUpdateManager);
  +        Iterator it = svgLoadEventDispatcherListeners.iterator();
           while (it.hasNext()) {
               d.addSVGLoadEventDispatcherListener
                   ((SVGLoadEventDispatcherListener)it.next());
  @@ -592,6 +581,7 @@
   
           updateManager.getUpdateRunnableQueue().invokeLater(new Runnable() {
                   public void run() {
  +                    paintingTransform = null;
                       updateManager.updateRendering(renderingTransform,
                                                     doubleBufferedRendering,
                                                     s, d.width, d.height);
  @@ -669,7 +659,7 @@
        * Adds a UpdateManagerListener to this component.
        */
       public void addUpdateManagerListener(UpdateManagerListener l) {
  -        updateManagerListeners.add(new UpdateManagerListenerWrapper(l));
  +        updateManagerListeners.add(l);
       }
   
       /**
  @@ -680,102 +670,6 @@
       }
   
       /**
  -     * To call the update methods from the event thread.
  -     */
  -    protected static class UpdateManagerListenerWrapper
  -        implements UpdateManagerListener {
  -
  -        /**
  -         * The wrapped listener.
  -         */
  -        protected UpdateManagerListener listener;
  -
  -        /**
  -         * Creates a new wrapper.
  -         */
  -        public UpdateManagerListenerWrapper(UpdateManagerListener l) {
  -            listener = l;
  -        }
  -
  -        /**
  -         * Called when the manager was started.
  -         */
  -        public void managerStarted(final UpdateManagerEvent e) {
  -            EventQueue.invokeLater(new Runnable() {
  -                    public void run() {
  -                        listener.managerStarted(e);
  -                    }
  -                });
  -        }
  -
  -        /**
  -         * Called when the manager was suspended.
  -         */
  -        public void managerSuspended(final UpdateManagerEvent e) {
  -            EventQueue.invokeLater(new Runnable() {
  -                    public void run() {
  -                        listener.managerSuspended(e);
  -                    }
  -                });
  -        }
  -
  -        /**
  -         * Called when the manager was resumed.
  -         */
  -        public void managerResumed(final UpdateManagerEvent e) {
  -            EventQueue.invokeLater(new Runnable() {
  -                    public void run() {
  -                        listener.managerResumed(e);
  -                    }
  -                });
  -        }
  -
  -        /**
  -         * Called when the manager was stopped.
  -         */
  -        public void managerStopped(final UpdateManagerEvent e) {
  -            EventQueue.invokeLater(new Runnable() {
  -                    public void run() {
  -                        listener.managerStopped(e);
  -                    }
  -                });
  -        }
  -
  -        /**
  -         * Called when an update started.
  -         */
  -        public void updateStarted(final UpdateManagerEvent e) {
  -            EventQueue.invokeLater(new Runnable() {
  -                    public void run() {
  -                        listener.updateStarted(e);
  -                    }
  -                });
  -        }
  -
  -        /**
  -         * Called when an update was completed.
  -         */
  -        public void updateCompleted(final UpdateManagerEvent e) {
  -            EventQueue.invokeLater(new Runnable() {
  -                    public void run() {
  -                        listener.updateCompleted(e);
  -                    }
  -                });
  -        }
  -
  -        /**
  -         * Called when an update failed.
  -         */
  -        public void updateFailed(final UpdateManagerEvent e) {
  -            EventQueue.invokeLater(new Runnable() {
  -                    public void run() {
  -                        listener.updateFailed(e);
  -                    }
  -                });
  -        }
  -    }
  -
  -    /**
        * Creates an instance of Listener.
        */
       protected Listener createListener() {
  @@ -957,11 +851,18 @@
            */
           public void svgLoadEventDispatchCompleted
               (SVGLoadEventDispatcherEvent e) {
  +            svgLoadEventDispatcher = null;
               if (nextGVTTreeBuilder != null) {
  +                nextUpdateManager.interrupt();
  +                nextUpdateManager = null;
  +            
                   startGVTTreeBuilder();
                   return;
               }
               if (nextDocumentLoader != null) {
  +                nextUpdateManager.interrupt();
  +                nextUpdateManager = null;
  +            
                   startDocumentLoader();
                   return;
               }
  @@ -974,8 +875,11 @@
            */
           public void svgLoadEventDispatchCancelled
               (SVGLoadEventDispatcherEvent e) {
  -            loader = null;
  -            gvtTreeBuilder = null;
  +            svgLoadEventDispatcher = null;
  +
  +            nextUpdateManager.interrupt();
  +            nextUpdateManager = null;
  +            
               if (nextGVTTreeBuilder != null) {
                   startGVTTreeBuilder();
                   return;
  @@ -991,8 +895,11 @@
            */
           public void svgLoadEventDispatchFailed
               (SVGLoadEventDispatcherEvent e) {
  -            loader = null;
  -            gvtTreeBuilder = null;
  +            svgLoadEventDispatcher = null;
  +
  +            nextUpdateManager.interrupt();
  +            nextUpdateManager = null;
  +
               if (nextGVTTreeBuilder != null) {
                   startGVTTreeBuilder();
                   return;
  @@ -1031,13 +938,11 @@
                   return;
               }
               
  -            if (isDynamicDocument) {
  -                if (JSVGComponent.this.eventsEnabled &&
  -                    !updateManagerSuspended &&
  -                    !updateManagerStopped) {
  -                    updateManager.manageUpdates(renderer);
  -                }
  -                suspendInteractions = false;
  +            if (nextUpdateManager != null) {
  +                updateManager = nextUpdateManager;
  +                nextUpdateManager = null;
  +                updateManager.addUpdateManagerListener((SVGListener)this);
  +                updateManager.manageUpdates(renderer);
               }
           }
   
  @@ -1052,6 +957,10 @@
                   return;
               }
               if (nextDocumentLoader != null) {
  +                if (nextUpdateManager != null) {
  +                    nextUpdateManager.interrupt();
  +                    nextUpdateManager = null;
  +                }
                   startDocumentLoader();
                   return;
               }
  @@ -1068,6 +977,11 @@
                   return;
               }
               if (nextDocumentLoader != null) {
  +                if (nextUpdateManager != null) {
  +                    nextUpdateManager.interrupt();
  +                    nextUpdateManager = null;
  +                }
  +
                   startDocumentLoader();
                   return;
               }
  @@ -1078,31 +992,87 @@
           /**
            * Called when the manager was started.
            */
  -        public void managerStarted(UpdateManagerEvent e) {
  -            suspendInteractions = false;
  -            updateManagerSuspended = false;
  +        public void managerStarted(final UpdateManagerEvent e) {
  +            EventQueue.invokeLater(new Runnable() {
  +                    public void run() {
  +                        suspendInteractions = false;
  +
  +                        Object[] dll = updateManagerListeners.toArray();
  +                        
  +                        if (dll.length > 0) {
  +                            for (int i = 0; i < dll.length; i++) {
  +                                ((UpdateManagerListener)dll[i]).
  +                                    managerStarted(e);
  +                            }
  +                        }
  +                    }
  +                });
           }
   
           /**
            * Called when the manager was suspended.
            */
  -        public void managerSuspended(UpdateManagerEvent e) {
  -            updateManagerSuspended = true;
  +        public void managerSuspended(final UpdateManagerEvent e) {
  +            EventQueue.invokeLater(new Runnable() {
  +                    public void run() {
  +                        Object[] dll = updateManagerListeners.toArray();
  +                        
  +                        if (dll.length > 0) {
  +                            for (int i = 0; i < dll.length; i++) {
  +                                ((UpdateManagerListener)dll[i]).
  +                                    managerSuspended(e);
  +                            }
  +                        }
  +                    }
  +                });
           }
   
           /**
            * Called when the manager was resumed.
            */
  -        public void managerResumed(UpdateManagerEvent e) {
  -            updateManagerSuspended = false;
  +        public void managerResumed(final UpdateManagerEvent e) {
  +            EventQueue.invokeLater(new Runnable() {
  +                    public void run() {
  +                        Object[] dll = updateManagerListeners.toArray();
  +                        
  +                        if (dll.length > 0) {
  +                            for (int i = 0; i < dll.length; i++) {
  +                                ((UpdateManagerListener)dll[i]).
  +                                    managerResumed(e);
  +                            }
  +                        }
  +                    }
  +                });
           }
   
           /**
            * Called when the manager was stopped.
            */
  -        public void managerStopped(UpdateManagerEvent e) {
  -            updateManagerSuspended = false;
  -            updateManagerStopped = true;
  +        public void managerStopped(final UpdateManagerEvent e) {
  +            EventQueue.invokeLater(new Runnable() {
  +                    public void run() {
  +                        updateManager = null;
  +                        
  +
  +                        Object[] dll = updateManagerListeners.toArray();
  +                        
  +                        if (dll.length > 0) {
  +                            for (int i = 0; i < dll.length; i++) {
  +                                ((UpdateManagerListener)dll[i]).
  +                                    managerStopped(e);
  +                            }
  +                        }
  +
  +                        if (nextGVTTreeBuilder != null) {
  +                            startGVTTreeBuilder();
  +                            return;
  +                        }
  +                        if (nextDocumentLoader != null) {
  +                            startDocumentLoader();
  +                            return;
  +                        }
  +                    }
  +                });
           }
   
           /**
  @@ -1111,10 +1081,18 @@
           public void updateStarted(final UpdateManagerEvent e) {
               EventQueue.invokeLater(new Runnable() {
                       public void run() {
  -                        paintingTransform = null;
                           if (!doubleBufferedRendering) {
                               image = e.getImage();
                           }
  +
  +                        Object[] dll = updateManagerListeners.toArray();
  +                        
  +                        if (dll.length > 0) {
  +                            for (int i = 0; i < dll.length; i++) {
  +                                ((UpdateManagerListener)dll[i]).
  +                                    updateStarted(e);
  +                            }
  +                        }
                       }
                   });
           }
  @@ -1139,16 +1117,38 @@
                                   }
                               }
                               suspendInteractions = false;
  +
  +                            Object[] dll = updateManagerListeners.toArray();
  +                            
  +                            if (dll.length > 0) {
  +                                for (int i = 0; i < dll.length; i++) {
  +                                    ((UpdateManagerListener)dll[i]).
  +                                        updateCompleted(e);
  +                                }
  +                            }
                           }
                       });
               } catch (Exception ex) {
               }
  +            
           }
   
           /**
            * Called when an update failed.
            */
  -        public void updateFailed(UpdateManagerEvent e) {
  +        public void updateFailed(final UpdateManagerEvent e) {
  +            EventQueue.invokeLater(new Runnable() {
  +                    public void run() {
  +                        Object[] dll = updateManagerListeners.toArray();
  +                        
  +                        if (dll.length > 0) {
  +                            for (int i = 0; i < dll.length; i++) {
  +                                ((UpdateManagerListener)dll[i]).
  +                                    updateFailed(e);
  +                            }
  +                        }
  +                    }
  +                });
           }
   
           // Event propagation to GVT ///////////////////////////////////////
  @@ -1701,7 +1701,6 @@
               try {
                   EventQueue.invokeAndWait(r);
               } catch (Exception e) {
  -                throw new RuntimeException(e.getMessage());
               }
           }
       }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to