deweese     2003/07/02 19:00:01

  Modified:    samples/tests/spec/scripting boundsTransformChange.svg
                        rectResizeOnClick.svg rootSizeChange.svg
               sources/org/apache/batik/bridge
                        BaseScriptingEnvironment.java
               sources/org/apache/batik/gvt/event AWTEventDispatcher.java
               test-resources/org/apache/batik/test samplesRendering.xml
               test-resources/org/apache/batik/test/svg/resources
                        Messages.properties
               test-sources/org/apache/batik/test/svg
                        AbstractRenderingAccuracyTest.java
                        SVGRenderingAccuracyTest.java
  Added:       test-references/samples/tests/spec/scripting
                        boundsTransformChange.png rectResizeOnClick.png
                        rootSizeChange.png
               test-references/test-resources/org/apache/batik/test/svg
                        .cvsignore
               test-sources/org/apache/batik/test/svg
                        JSVGRenderingAccuracyTest.java
  Log:
  1) Introduced a new type of Regard test that uses the JSVGCanvas to
     render dynamic content and then grab the screen contents for
     comparison.
  2) Updated a few script tests to use this new test type.
  3) Fixed a minor bug with completely empty SVG Documents.
  4) Fixed a minor bug when JSVGCanvas pops down away with the mouse over it.
  
  Revision  Changes    Path
  1.2       +11 -4     xml-batik/samples/tests/spec/scripting/boundsTransformChange.svg
  
  Index: boundsTransformChange.svg
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/samples/tests/spec/scripting/boundsTransformChange.svg,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- boundsTransformChange.svg 20 Mar 2003 00:18:35 -0000      1.1
  +++ boundsTransformChange.svg 3 Jul 2003 01:59:59 -0000       1.2
  @@ -26,7 +26,8 @@
       <desc>This tests changing the bounds of an object then changing a
       a parent's transform to ensure the dirty regions are properly
       computed.</desc>
  -    <script type="text/ecmascript">
  +    <script type="text/ecmascript"><![CDATA[
  +        var inRegard=false;
        var time1 = 90;
        function updateGroup1() {
               var elt = document.getElementById("g1");
  @@ -37,9 +38,15 @@
            var y = Math.sin(.5*(time1+90)*3.1415926/180)*150 + 250;
               elt.setAttribute("transform", "translate("+x+","+y+")");
            time1 += 20;
  -         setTimeout('updateGroup1()', 100);
  +            if (inRegard && (time1 >= 270))
  +               regardTestInstance.scriptDone();
  +            else
  +               setTimeout('updateGroup1()', 100);
        }
  -    </script>
  +       function regardStart() {
  +          inRegard = true;
  +       }
  +    ]]></script>
   
       <g id="test-content">
          <g id="g1">
  
  
  
  1.2       +9 -6      xml-batik/samples/tests/spec/scripting/rectResizeOnClick.svg
  
  Index: rectResizeOnClick.svg
  ===================================================================
  RCS file: /home/cvs/xml-batik/samples/tests/spec/scripting/rectResizeOnClick.svg,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- rectResizeOnClick.svg     4 Feb 2002 20:11:33 -0000       1.1
  +++ rectResizeOnClick.svg     3 Jul 2003 01:59:59 -0000       1.2
  @@ -24,16 +24,19 @@
   
      <script type="text/ecmascript">
   
  -    function setRect(evt, target, valX, valY, valW, valH){
  -        var r = evt.getTarget();
  -        var doc = r.getOwnerDocument();
  -        var t = doc.getElementById(target);
  +    function setRect(target, valX, valY, valW, valH){
  +        var t = document.getElementById(target);
           t.setAttribute('x', valX);
           t.setAttribute('y', valY);
           t.setAttribute('width', valW);
           t.setAttribute('height', valH);
       }
   
  +    // This function is only called if test is run from regard.
  +    function regardStart() {
  +       setRect('targetRect', '5', '5', '440', '490');
  +       regardTestInstance.scriptDone();
  +    }
      </script>
   
      <text x="50%" y="45" class="title">&lt;rect&gt; width &amp; height modification 
in 'onclick'</text>
  @@ -49,7 +52,7 @@
         <text class="legend" x="225" y="240">Click Target</text>
   
         <g stroke="black"
  -         onclick="setRect(evt, 'targetRect', '5', '5', '440', '490')" >
  +         onclick="setRect('targetRect', '5', '5', '440', '490')" >
            <circle cx="225" cy="200"  r="10"           fill="crimson"/>
            <line   x1="225" x2="225" y1="185" y2="215" fill="none" />
            <line   x1="210" x2="240" y1="200" y2="200" fill="none" />
  
  
  
  1.2       +19 -9     xml-batik/samples/tests/spec/scripting/rootSizeChange.svg
  
  Index: rootSizeChange.svg
  ===================================================================
  RCS file: /home/cvs/xml-batik/samples/tests/spec/scripting/rootSizeChange.svg,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- rootSizeChange.svg        7 Mar 2003 12:36:30 -0000       1.1
  +++ rootSizeChange.svg        3 Jul 2003 01:59:59 -0000       1.2
  @@ -27,28 +27,38 @@
       double buffering and pause the animation and force a repaint, if
       you see lots of junk then the repaint engine is not working
       properly.</desc>
  -    <script type="text/ecmascript">
  -     var time1 = 90;
  +    <script type="text/ecmascript"><![CDATA[
  +        var inRegard = false;
  +     var time1 = 70;
        function updateGroup1() {
               var elt = document.getElementById("g1");
            var x = Math.cos(time1*3.1415926/180)*150 + 225;
            var y = Math.sin(.5*(time1+90)*3.1415926/180)*150 + 250;
               elt.setAttributeNS(null, "transform", 
                               "translate("+x+","+y+")");
  -         time1 += 5;
  -         setTimeout('updateGroup1()', 100);
  +         time1 += 15;
  +            if (!inRegard || (time1 < 470))
  +            setTimeout('updateGroup1()', 100);
  +            if (inRegard && (time2 <= -290) && (time1 >= 470))
  +              regardTestInstance.scriptDone();
        }
  -     var time2 = 90;
  +     var time2 = 110;
        function updateGroup2() {
               var elt = document.getElementById("g2");
            var x = Math.cos(time2*3.1415926/180)*150 + 225;
            var y = Math.sin(.5*(time2+90)*3.1415926/180)*150 + 250;
               elt.setAttributeNS(null, "transform", 
                               "translate("+x+","+y+")");
  -         time2 -= 5;
  -         setTimeout('updateGroup2()', 100);
  +         time2 -= 15;
  +            if (!inRegard || (time2 > -290))
  +               setTimeout('updateGroup2()', 100);
  +            if (inRegard && (time2 <= -290) && (time1 >= 470))
  +              regardTestInstance.scriptDone();
        }
  -    </script>
  +       function regardStart() {
  +          inRegard = true;
  +       }
  +    ]]></script>
   
       <g id="test-content">
          <g id="g1">
  
  
  
  1.21      +3 -2      
xml-batik/sources/org/apache/batik/bridge/BaseScriptingEnvironment.java
  
  Index: BaseScriptingEnvironment.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/sources/org/apache/batik/bridge/BaseScriptingEnvironment.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- BaseScriptingEnvironment.java     1 Jul 2003 09:34:17 -0000       1.20
  +++ BaseScriptingEnvironment.java     3 Jul 2003 02:00:00 -0000       1.21
  @@ -54,7 +54,8 @@
        */
       public static boolean isDynamicDocument(Document doc) {
           Element elt = doc.getDocumentElement();
  -        if (elt.getNamespaceURI().equals(SVGConstants.SVG_NAMESPACE_URI)) {
  +        if ((elt != null) &&
  +            SVGConstants.SVG_NAMESPACE_URI.equals(elt.getNamespaceURI())) {
               if (elt.getAttributeNS
                   (null, SVGConstants.SVG_ONABORT_ATTRIBUTE).length() > 0) {
                   return true;
  
  
  
  1.14      +9 -4      
xml-batik/sources/org/apache/batik/gvt/event/AWTEventDispatcher.java
  
  Index: AWTEventDispatcher.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/sources/org/apache/batik/gvt/event/AWTEventDispatcher.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- AWTEventDispatcher.java   11 Apr 2003 13:58:34 -0000      1.13
  +++ AWTEventDispatcher.java   3 Jul 2003 02:00:00 -0000       1.14
  @@ -344,9 +344,14 @@
   
           // If the receiving node has changed, send a notification
           // check if we enter a new node
  -        Point screenPos = evt.getComponent().getLocationOnScreen();
  -        screenPos.x += evt.getX();
  -        screenPos.y += evt.getY();
  +        Point screenPos;
  +        if (!evt.getComponent().isShowing()) {
  +            screenPos = new Point(0,0);
  +        } else {
  +            screenPos = evt.getComponent().getLocationOnScreen();
  +            screenPos.x += evt.getX();
  +            screenPos.y += evt.getY();
  +        }
   
   
           if (lastHit != node) {
  
  
  
  1.1                  
xml-batik/test-references/samples/tests/spec/scripting/boundsTransformChange.png
  
        <<Binary file>>
  
  
  1.1                  
xml-batik/test-references/samples/tests/spec/scripting/rectResizeOnClick.png
  
        <<Binary file>>
  
  
  1.1                  
xml-batik/test-references/samples/tests/spec/scripting/rootSizeChange.png
  
        <<Binary file>>
  
  
  1.1                  
xml-batik/test-references/test-resources/org/apache/batik/test/svg/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  accepted-variation
  candidate-reference
  candidate-variation
  
  
  
  1.99      +13 -5     
xml-batik/test-resources/org/apache/batik/test/samplesRendering.xml
  
  Index: samplesRendering.xml
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/test-resources/org/apache/batik/test/samplesRendering.xml,v
  retrieving revision 1.98
  retrieving revision 1.99
  diff -u -r1.98 -r1.99
  --- samplesRendering.xml      1 Jul 2003 09:43:09 -0000       1.98
  +++ samplesRendering.xml      3 Jul 2003 02:00:00 -0000       1.99
  @@ -12,10 +12,10 @@
   <!-- ========================================================================= -->
   <testSuite id="samplesRendering" name="samples and samples/test Rendering" 
class="org.apache.batik.test.svg.SamplesRenderingTest">
   
  -    <!-- ========================================================================== 
-->
  -    <!-- The following tests check correct rendering of images in the samples       
-->
  -    <!-- directory.                                                                 
-->
  -    <!-- ========================================================================== 
-->
  +    <!-- ================================================================== -->
  +    <!-- The following tests check correct rendering of images in the       -->
  +    <!-- samples directory.                                                 -->
  +    <!-- ================================================================== -->
       <testGroup id="samples" name="samples Rendering">
           <test id="samples/anne.svg" />
           <test id="samples/asf-logo.svg" />
  @@ -379,4 +379,12 @@
       <testGroup id="test-resources.bugs">
           <test id="test-resources/org/apache/batik/test/svg/bug19363.svg" />
       </testGroup>
  +
  +    <testGroup id="updateTests" name="Dynamic Update Tests"
  +               class="org.apache.batik.test.svg.JSVGRenderingAccuracyTest">
  +        <test id="samples/tests/spec/scripting/boundsTransformChange.svg" />
  +        <test id="samples/tests/spec/scripting/rootSizeChange.svg" />
  +        <test id="samples/tests/spec/scripting/rectResizeOnClick.svg" />
  +    </testGroup>
  +
   </testSuite>
  
  
  
  1.5       +13 -0     
xml-batik/test-resources/org/apache/batik/test/svg/resources/Messages.properties
  
  Index: Messages.properties
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/test-resources/org/apache/batik/test/svg/resources/Messages.properties,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Messages.properties       16 Apr 2001 22:42:38 -0000      1.4
  +++ Messages.properties       3 Jul 2003 02:00:00 -0000       1.5
  @@ -77,3 +77,16 @@
   SVGRenderingAccuracyTest.message.error.could.not.load.image = \
   Could not load image {0}
   
  +JSVGRenderingAccuracyTest.message.error.could.not.load.svg = \
  +Could not load SVG file: '{0}'
  +
  +JSVGRenderingAccuracyTest.message.error.svg.render.failed = \
  +Failed to render SVG file: '{0}'
  +
  +JSVGRenderingAccuracyTest.message.error.svg.update.failed = \
  +Failed to handle SVG update: '{0}'
  +
  +JSVGRenderingAccuracyTest.message.error.save.failed = \
  +Save of new image failed: '{0}' \n\
  +I/O Exception: {1}
  +
  
  
  
  1.2       +13 -5     
xml-batik/test-sources/org/apache/batik/test/svg/AbstractRenderingAccuracyTest.java
  
  Index: AbstractRenderingAccuracyTest.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/test-sources/org/apache/batik/test/svg/AbstractRenderingAccuracyTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractRenderingAccuracyTest.java        1 Jul 2003 09:34:17 -0000       1.1
  +++ AbstractRenderingAccuracyTest.java        3 Jul 2003 02:00:01 -0000       1.2
  @@ -14,8 +14,9 @@
   import java.io.FileOutputStream;
   import java.io.InputStream;
   import java.io.IOException;
  -import java.io.StringWriter;
  +import java.io.OutputStream;
   import java.io.PrintWriter;
  +import java.io.StringWriter;
   
   import java.net.URL;
   import java.net.MalformedURLException;
  @@ -422,7 +423,8 @@
           // encoding failed and we should return that report.
           {
               TestReport encodeTR = encode(svgURL, tmpFileOS);
  -            if (encodeTR != null) {
  +            if ((encodeTR != null) && 
  +                (encodeTR.hasPassed() == false)) {
                   tmpFile.deleteOnExit();
                   return encodeTR;
               }
  @@ -625,10 +627,16 @@
           if(!imgFile.exists()){
               imgFile.createNewFile();
           }
  +        saveImage(img, new FileOutputStream(imgFile));
  +    }
   
  +    /**
  +     * Saves an image in a given File
  +     */
  +    protected void saveImage(BufferedImage img, OutputStream os)
  +        throws IOException {
           PNGImageEncoder encoder = new PNGImageEncoder
  -            (new FileOutputStream(imgFile),
  -             PNGEncodeParam.getDefaultEncodeParam(img));
  +            (os, PNGEncodeParam.getDefaultEncodeParam(img));
           
           encoder.encode(img);
       }
  
  
  
  1.34      +2 -34     
xml-batik/test-sources/org/apache/batik/test/svg/SVGRenderingAccuracyTest.java
  
  Index: SVGRenderingAccuracyTest.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/test-sources/org/apache/batik/test/svg/SVGRenderingAccuracyTest.java,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- SVGRenderingAccuracyTest.java     1 Jul 2003 09:34:17 -0000       1.33
  +++ SVGRenderingAccuracyTest.java     3 Jul 2003 02:00:01 -0000       1.34
  @@ -8,39 +8,11 @@
   
   package org.apache.batik.test.svg;
   
  -import java.io.BufferedInputStream;
  -import java.io.File;
  -import java.io.FileInputStream;
  +import java.awt.Color;
   import java.io.FileOutputStream;
  -import java.io.InputStream;
  -import java.io.IOException;
   import java.io.StringWriter;
   import java.io.PrintWriter;
  -
   import java.net.URL;
  -import java.net.MalformedURLException;
  -
  -import java.util.Locale;
  -import java.util.ResourceBundle;
  -import java.util.Vector;
  -
  -import java.awt.Color;
  -import java.awt.Graphics2D;
  -import java.awt.image.BufferedImage;
  -import java.awt.image.RenderedImage;
  -import java.awt.image.WritableRaster;
  -import java.awt.image.ColorModel;
  -
  -import org.apache.batik.ext.awt.image.CompositeRule;
  -import org.apache.batik.ext.awt.image.GraphicsUtil;
  -import org.apache.batik.ext.awt.image.rendered.CompositeRed;
  -import org.apache.batik.ext.awt.image.rendered.BufferedImageCachableRed;
  -
  -import org.apache.batik.ext.awt.image.spi.ImageTagRegistry;
  -import org.apache.batik.ext.awt.image.renderable.Filter;
  -
  -import org.apache.batik.ext.awt.image.codec.PNGImageEncoder;
  -import org.apache.batik.ext.awt.image.codec.PNGEncodeParam;
   
   import org.apache.batik.transcoder.TranscoderException;
   import org.apache.batik.transcoder.TranscoderInput;
  @@ -49,11 +21,7 @@
   import org.apache.batik.transcoder.image.ImageTranscoder;
   import org.apache.batik.transcoder.image.PNGTranscoder;
   
  -import org.apache.batik.util.ParsedURL;
  -
  -import org.apache.batik.test.AbstractTest;
   import org.apache.batik.test.DefaultTestReport;
  -import org.apache.batik.test.Test;
   import org.apache.batik.test.TestReport;
   
   import org.w3c.dom.Document;
  
  
  
  1.1                  
xml-batik/test-sources/org/apache/batik/test/svg/JSVGRenderingAccuracyTest.java
  
  Index: JSVGRenderingAccuracyTest.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included with this distribution in  *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.batik.test.svg;
  
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.StringWriter;
  import java.io.PrintWriter;
  import java.net.URL;
  import java.awt.event.WindowAdapter;
  import java.awt.event.WindowEvent;
  import java.awt.event.WindowListener;
  
  import org.w3c.dom.Document;
  
  import org.apache.batik.test.DefaultTestReport;
  import org.apache.batik.test.TestReport;
  
  import org.apache.batik.bridge.ScriptingEnvironment;
  import org.apache.batik.bridge.UpdateManager;
  import org.apache.batik.bridge.UpdateManagerEvent;
  import org.apache.batik.bridge.UpdateManagerListener;
  import org.apache.batik.script.Interpreter;
  import org.apache.batik.script.InterpreterException;
  import org.apache.batik.swing.gvt.GVTTreeRendererAdapter;
  import org.apache.batik.swing.gvt.GVTTreeRendererEvent;
  import org.apache.batik.swing.JSVGCanvas;
  import org.apache.batik.swing.svg.SVGDocumentLoaderAdapter;
  import org.apache.batik.swing.svg.SVGDocumentLoaderEvent;
  
  import java.awt.Dimension;
  import java.awt.image.BufferedImage;
  
  import javax.swing.JFrame;
  
  /**
   * One line Class Desc
   *
   * Complete Class Desc
   *
   * @author <a href="mailto:[EMAIL PROTECTED]>l449433</a>
   * @version $Id: JSVGRenderingAccuracyTest.java,v 1.1 2003/07/03 02:00:01 deweese 
Exp $
   */
  public class JSVGRenderingAccuracyTest extends SamplesRenderingTest {
  
      public static final String REGARD_TEST_INSTANCE = "regardTestInstance";
      public static final String REGARD_START_SCRIPT = 
          "try { regardStart(); } catch (er) {}";
  
      /**
       * Error when canvas can't load SVG file.
       * {0} The file/url that could not be loaded.
       */
      public static final String ERROR_CANNOT_LOAD_SVG = 
          "JSVGRenderingAccuracyTest.message.error.could.not.load.svg";
  
      /**
       * Error when canvas can't render SVG file.
       * {0} The file/url that could not be rendered.
       */
      public static final String ERROR_SVG_RENDER_FAILED = 
          "JSVGRenderingAccuracyTest.message.error.svg.render.failed";
  
      /**
       * Error when canvas can't peform render update SVG file.
       * {0} The file/url that could not be updated..
       */
      public static final String ERROR_SVG_UPDATE_FAILED = 
          "JSVGRenderingAccuracyTest.message.error.svg.update.failed";
  
      /**
       * Error when canvas can't peform render update SVG file.
       * {0} The file/url that could not be updated..
       */
      public static final String ERROR_SAVE_FAILED = 
          "JSVGRenderingAccuracyTest.message.error.save.failed";
  
      public static String fmt(String key, Object []args) {
          return Messages.formatMessage(key, args);
      }
  
      /**
       * For subclasses
       */
      public JSVGRenderingAccuracyTest(){
      }
  
      JFrame     frame = null;
      JSVGCanvas canvas = null;
      UpdateManager updateManager = null;
      BufferedImage theImage = null;
      WindowListener wl = null;
  
      boolean renderFailed;
      boolean loadFailed;
      boolean done;
      boolean abort;
      Object loadMonitor = new Object();
      Object renderMonitor = new Object();
  
      public TestReport encode(URL srcURL, FileOutputStream fos) {
          DefaultTestReport report = new DefaultTestReport(this);
              loadFailed = true;
              renderFailed = true;
              
              frame = new JFrame(getName());
              canvas = new JSVGCanvas();
              frame.getContentPane().add(canvas);
              frame.setSize(new Dimension(450, 500));
              frame.setVisible(true);
              wl = new WindowAdapter() {
                      public void windowClosing(WindowEvent e) {
                          synchronized (loadMonitor) {
                              abort = true;
                              loadMonitor.notifyAll();
                          }
                          synchronized (renderMonitor) {
                              abort = true;
                              renderMonitor.notifyAll();
                          }
                      }
                  };
              frame.addWindowListener(wl);
              
              canvas.addGVTTreeRendererListener
                  (new InitialRenderListener());
              canvas.addSVGDocumentLoaderListener
                  (new LoadListener());
              try {
              
              initCanvas(canvas, srcURL);
              
              synchronized (renderMonitor) {
                  synchronized (loadMonitor) {
                      try { loadMonitor.wait(); }
                      catch(InterruptedException ie) { /* nothing */ }
                      if (abort || loadFailed) {
                          report.setErrorCode(ERROR_CANNOT_LOAD_SVG);
                          report.setDescription(new TestReport.Entry[] { 
                              new TestReport.Entry
                              (fmt(ENTRY_KEY_ERROR_DESCRIPTION, null),
                               fmt(ERROR_CANNOT_LOAD_SVG, 
                                   new Object[]{srcURL.toString()}))
                          });
                          report.setPassed(false);
                          return report;
                      }
                  }
  
                  try { renderMonitor.wait(); }
                  catch(InterruptedException ie) { /* nothing */ }
                  if (abort || renderFailed) {
                          report.setErrorCode(ERROR_SVG_RENDER_FAILED);
                          report.setDescription(new TestReport.Entry[] { 
                              new TestReport.Entry
                              (fmt(ENTRY_KEY_ERROR_DESCRIPTION, null),
                               fmt(ERROR_SVG_RENDER_FAILED, 
                                   new Object[]{srcURL.toString()}))
                          });
                      report.setPassed(false);
                      return report;
                  }
  
                  updateManager = canvas.getUpdateManager();
                  if (updateManager == null) {
                      // Not dynamic?  Just use image..
                      theImage = copyImage(canvas.getOffScreen());
                  } else {
                      updateManager.addUpdateManagerListener
                          (new UpdateRenderListener());
                      done = false;
                      updateManager.getUpdateRunnableQueue().invokeLater
                          (new Runnable() {
                                  UpdateManager um = updateManager;
                                  public void run() {
                                      ScriptingEnvironment scriptEnv;
                                      scriptEnv = um.getScriptingEnvironment();
                                      Interpreter interp;
                                      interp    = scriptEnv.getInterpreter();
                                      interp.bindObject(REGARD_TEST_INSTANCE, 
                                                        
JSVGRenderingAccuracyTest.this);
                                      try {
                                          interp.evaluate(REGARD_START_SCRIPT);
                                      } catch (InterpreterException ie) {
                                          // Could not wait if no start script.
                                      }
                                  }
                              });
                                                                  
                      while (theImage == null) {
                          try { renderMonitor.wait(); }
                          catch (InterruptedException ie) { /* nothing */ }
                          if (abort || renderFailed) {
                              report.setErrorCode(ERROR_SVG_UPDATE_FAILED);
                              report.setDescription(new TestReport.Entry[] { 
                                  new TestReport.Entry
                                  (fmt(ENTRY_KEY_ERROR_DESCRIPTION, null),
                                   fmt(ERROR_SVG_UPDATE_FAILED, 
                                       new Object[]{srcURL.toString()}))
                              });
                              report.setPassed(false);
                              return report;
                          }
                      }
                  }
                  try {
                      saveImage(theImage, fos);
                  } catch (IOException ioe) {
                      StringWriter trace = new StringWriter();
                      ioe.printStackTrace(new PrintWriter(trace));
                      report.setErrorCode(ERROR_SAVE_FAILED);
                      report.setDescription(new TestReport.Entry[] { 
                          new TestReport.Entry
                          (fmt(ENTRY_KEY_ERROR_DESCRIPTION, null),
                           fmt(ERROR_SAVE_FAILED, 
                               new Object[]{ srcURL.toString(),
                                             trace.toString()}))
                      });
                      report.setPassed(false);
                      return report;
                  }
              }
          } finally {
              dispose();
          }
          report.setPassed(true);
          return report;
      }
  
      public void dispose() {
          frame.removeWindowListener(wl);
          wl = null;
          if (frame != null) 
              frame.setVisible(false);
          theImage = null;
          updateManager = null;
          canvas = null;
          frame = null;
      }
  
      /**
       * Method subclasses can implement to do more sophisticated
       * initialization of the canvas.
       */
      protected void initCanvas(JSVGCanvas canvas, URL srcURL) {
          canvas.setURI(srcURL.toString());
      }
  
      public void scriptDone() {
          synchronized (renderMonitor) {
              done = true;
              // Don't notify.  The Update Complete will notify - and
              // provide us with the 'up to date' image for comparison.
          }
      }
  
      public static BufferedImage copyImage(BufferedImage bi) {
          // Copy off the image just rendered.
          BufferedImage ret;
          ret = new BufferedImage(bi.getWidth(), bi.getHeight(), bi.getType());
          bi.copyData(ret.getRaster());
          return ret;
      }
  
      class UpdateRenderListener implements UpdateManagerListener {
          public void updateCompleted(UpdateManagerEvent e) {
              synchronized(renderMonitor){
                  renderFailed = false;
                  if (done) {
                      theImage = copyImage(e.getImage());
                  }
                  renderMonitor.notifyAll();
              }
          }
          public void updateFailed(UpdateManagerEvent e) {
              synchronized(renderMonitor){
                  renderFailed = true;
                  renderMonitor.notifyAll();
              }
          }
          public void managerStarted(UpdateManagerEvent e) { }
          public void managerSuspended(UpdateManagerEvent e) { }
          public void managerResumed(UpdateManagerEvent e) { }
          public void managerStopped(UpdateManagerEvent e) { }
          public void updateStarted(UpdateManagerEvent e) { }
      }
  
      class InitialRenderListener extends GVTTreeRendererAdapter {
          public void gvtRenderingCompleted(GVTTreeRendererEvent e) {
              synchronized(renderMonitor){
                  renderFailed = false;
                  if (done) {
                      theImage = copyImage(e.getImage());
                  }
                  renderMonitor.notifyAll();
              }
          }
  
  
          public void gvtRenderingCancelled(GVTTreeRendererEvent e) {
              synchronized(renderMonitor){
                  renderMonitor.notifyAll();
              }
          }
  
          public void gvtRenderingFailed(GVTTreeRendererEvent e) {
              synchronized(renderMonitor){
                  renderMonitor.notifyAll();
              }
          }
      }
  
      class LoadListener extends SVGDocumentLoaderAdapter {
          public void documentLoadingCompleted(SVGDocumentLoaderEvent e) {
              synchronized(loadMonitor){
                  loadFailed = false;
                  loadMonitor.notifyAll();
              }
          }
  
          public void documentLoadingFailed(SVGDocumentLoaderEvent e) {
              synchronized(loadMonitor){
                  loadMonitor.notifyAll();
              }
          }
  
          public void documentLoadingCancelled(SVGDocumentLoaderEvent e) {
              synchronized(loadMonitor){
                  loadMonitor.notifyAll();
              }
          }
      }
  
  };
  
  
  

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

Reply via email to