xmlgraphics-batik-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vha...@apache.org
Subject cvs commit: xml-batik/sources/org/apache/batik/swing JSVGCanvas.java
Date Mon, 10 Jun 2002 12:07:05 GMT
vhardy      2002/06/10 05:07:05

  Modified:    test-sources/org/apache/batik/swing NullURITest.java
               sources/org/apache/batik/swing JSVGCanvas.java
  Log:
  Fix/implementation for bug/REF #6683
  
  Revision  Changes    Path
  1.2       +89 -19    xml-batik/test-sources/org/apache/batik/swing/NullURITest.java
  
  Index: NullURITest.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/test-sources/org/apache/batik/swing/NullURITest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- NullURITest.java	10 Jun 2002 09:29:08 -0000	1.1
  +++ NullURITest.java	10 Jun 2002 12:07:05 -0000	1.2
  @@ -9,9 +9,11 @@
   package org.apache.batik.swing;
   
   import javax.swing.*;
  +import java.awt.*;
   import java.awt.event.*;
   
   import org.apache.batik.swing.svg.*;
  +import org.apache.batik.swing.gvt.*;
   import org.apache.batik.test.*;
   
   /**
  @@ -19,24 +21,60 @@
    * null does not cause a NullPointerException
    *
    * @author <a href="mailto:vincent.hardy@sun.com">Vincent Hardy</a>
  - * @version $Id: NullURITest.java,v 1.1 2002/06/10 09:29:08 vhardy Exp $
  + * @version $Id: NullURITest.java,v 1.2 2002/06/10 12:07:05 vhardy Exp $
    */
   public class NullURITest extends AbstractTest {
  -    /**
  -     * Code used if error happens while setting null URI on JSVGCanvas
  -     */
  -    public static final String ERROR_WITH_NULL_URI
  -        = "error.with.null.uri";
  +    public static final String TEST_NON_NULL_URI
  +        = "file:samples/anne.svg";
  +
  +    public static final String ERROR_COULD_NOT_RENDER_TEST_URI
  +        = "error.could.not.render.test.uri";
  +
  +    public static final String ERROR_COULD_NOT_RENDER_NULL_URI
  +        = "error.could.not.render.null.uri";
  +
  +    public String testURI = "samples/anne.svg";
   
       public TestReport runImpl() throws Exception {
  +        final JFrame f = new JFrame();
           final JSVGCanvas canvas = new JSVGCanvas();
  +
           final String monitor = "monitor";
   
  +        f.getContentPane().add(canvas);
  +        f.setSize(new Dimension(450, 500));
  +        f.setVisible(true);
  +
  +        // This class is not fool-proof: it assumes that the
  +        // non-null uri will render properly
  +        class InitialRenderListener extends GVTTreeRendererAdapter {
  +            public boolean failed = true;
  +
  +            public void gvtRenderingCompleted(GVTTreeRendererEvent e) {
  +                failed = false;
  +                synchronized(monitor){
  +                    monitor.notifyAll();
  +                }
  +            }
  +
  +
  +            public void gvtRenderingCancelled(GVTTreeRendererEvent e) {
  +                synchronized(monitor){
  +                    monitor.notifyAll();
  +                }
  +            }
  +
  +            public void gvtRenderingFailed(GVTTreeRendererEvent e) {
  +                synchronized(monitor){
  +                    monitor.notifyAll();
  +                }
  +            }
  +        }
  +
           class LoadListener extends SVGDocumentLoaderAdapter {
               public boolean failed = false;
               public void documentLoadingFailed(SVGDocumentLoaderEvent e) {
                   synchronized(monitor){
  -                    System.out.println(">>>>>>>>>>>>>>>
in documentLoadingFailed");
                       failed = true;
                       monitor.notifyAll();
                   }
  @@ -44,6 +82,7 @@
   
               public void documentLoadingCancelled(SVGDocumentLoaderEvent e) {
                   synchronized(monitor){
  +                    failed = true;
                       monitor.notifyAll();
                   }
               }
  @@ -55,24 +94,55 @@
               }
           }
   
  -        LoadListener l = new LoadListener();
  -        canvas.addSVGDocumentLoaderListener(l);
  +        InitialRenderListener l = new InitialRenderListener();
  +        LoadListener ll = new LoadListener();
  +        canvas.addGVTTreeRendererListener(l);
  +
  +        canvas.setURI(TEST_NON_NULL_URI);
  +        canvas.setEnabled(false);
  +
  +        synchronized(monitor){
  +            monitor.wait();
  +        }
  +
  +        if (l.failed || ll.failed){
  +            f.setVisible(false);
  +            return reportError(ERROR_COULD_NOT_RENDER_TEST_URI);
  +        }
   
  +        // Now, wait on new rendering
  +        l.failed = true;
           canvas.setURI(null);
  +        canvas.setEnabled(false);
   
  -        // Give chance to the DocumentLoader thread to kick in
  -        // This is not 
           synchronized(monitor){
  -            // Document loading should not take more than 10 sec.
  -            // Put a maximum to avoid deadlocks in case something
  -            // else goes wrong.
  -            monitor.wait(10000);
  +            monitor.wait();
  +        }
  +
  +        if (l.failed || ll.failed){
  +            f.setVisible(false);
  +            return reportError(ERROR_COULD_NOT_RENDER_NULL_URI);
  +        }
  +
  +        canvas.setURI(TEST_NON_NULL_URI);
  +        canvas.setEnabled(false);
  +        synchronized(monitor){
  +            monitor.wait();
  +        }
  +
  +        if (l.failed || ll.failed){
  +            f.setVisible(false);
  +            return reportError(ERROR_COULD_NOT_RENDER_TEST_URI);
           }
   
  -        if (!l.failed){
  -            return reportSuccess();
  -        } else {
  -            return reportError(ERROR_WITH_NULL_URI);
  +        
  +        f.dispose();
  +
  +        synchronized(monitor){
  +            monitor.wait(10000);
           }
  +
  +        return reportSuccess();
  +    
       }
   }
  
  
  
  1.34      +17 -3     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.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- JSVGCanvas.java	17 Apr 2002 14:39:50 -0000	1.33
  +++ JSVGCanvas.java	10 Jun 2002 12:07:05 -0000	1.34
  @@ -37,6 +37,8 @@
   
   import org.apache.batik.bridge.UserAgent;
   
  +import org.apache.batik.dom.svg.SVGDOMImplementation;
  +
   import org.apache.batik.swing.gvt.AbstractImageZoomInteractor;
   import org.apache.batik.swing.gvt.AbstractPanInteractor;
   import org.apache.batik.swing.gvt.AbstractResetTransformInteractor;
  @@ -51,6 +53,7 @@
   import org.apache.batik.util.SVGConstants;
   import org.apache.batik.util.XMLConstants;
   
  +import org.w3c.dom.DOMImplementation;
   import org.w3c.dom.Element;
   import org.w3c.dom.Node;
   
  @@ -58,6 +61,7 @@
   import org.w3c.dom.events.EventListener;
   import org.w3c.dom.events.EventTarget;
   
  +import org.w3c.dom.svg.SVGDocument;
   
   /**
    * This class represents a general-purpose swing SVG component. The
  @@ -69,7 +73,7 @@
    *
    * @author <a href="mailto:tkormann@apache.org">Thierry Kormann</a>
    * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
  - * @version $Id: JSVGCanvas.java,v 1.33 2002/04/17 14:39:50 tkormann Exp $
  + * @version $Id: JSVGCanvas.java,v 1.34 2002/06/10 12:07:05 vhardy Exp $
    */
   public class JSVGCanvas extends JSVGComponent {
   
  @@ -453,14 +457,24 @@
       }
   
       /**
  -     * Sets the URI to the specified uri.
  +     * Sets the URI to the specified uri. If the input 'newURI'
  +     * string is null, then the canvas will display an empty
  +     * document.
        *
        * @param newURI the new uri of the document to display
        */
       public void setURI(String newURI) {
           String oldValue = uri;
           this.uri = newURI;
  -        loadSVGDocument(uri);
  +        if (uri != null) {
  +            loadSVGDocument(uri);
  +        } else {
  +            DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
  +            SVGDocument doc = (SVGDocument)impl.createDocument(SVGConstants.SVG_NAMESPACE_URI,

  +                                                               SVGConstants.SVG_SVG_TAG,
null);
  +            setSVGDocument(doc);
  +        }
  +
           pcs.firePropertyChange("URI", oldValue, uri);
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org


Mime
View raw message