xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Kelly <Chris.ke...@advent-comm.co.uk>
Subject JSVGCanvas - java.lang.OutOfMemoryError
Date Tue, 04 Sep 2001 09:13:13 GMT
Hi 

I'm using the 1.3 jdk on Windows NT. I am running the application from
within JBuilder 3.5

I have slightly modified the JSVGCanvas sample code to increment a counter
in a very simple SVG

After some time (after counting to 8351 last time), I get a
java.lang.OutOfMemoryError

Here is the SVG:-

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20000303 Stylable//EN"
"http://www.w3.org/TR/2000/03/WD-SVG-20000303/DTD/svg-20000303-stylable.dtd"
>

<svg onload="" width="100%" height="100%" viewBox="0 0 300 45"
xml:space="preserve">
                <text id="myTitle" x="5" y="20" style="stroke:none;
fill:#cc00ff; font-family:'Arial'; font-size:24;">Counter</text>
		<text id="text" x="5" y="40" style="stroke:none;
fill:#cc00ff; font-family:'Arial'; font-size:24;">0</text>

</svg>

Here is the code:-

package batik;

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;

import org.apache.batik.swing.JSVGCanvas;
import org.apache.batik.swing.gvt.GVTTreeRendererAdapter;
import org.apache.batik.swing.gvt.GVTTreeRendererEvent;
import org.apache.batik.swing.svg.SVGDocumentLoaderAdapter;
import org.apache.batik.swing.svg.SVGDocumentLoaderEvent;
import org.apache.batik.swing.svg.GVTTreeBuilderAdapter;
import org.apache.batik.swing.svg.GVTTreeBuilderEvent;

import org.w3c.dom.svg.SVGDocument;
import org.w3c.dom.Node;

public class SVGApplication
{

    public static void main(String[] args)
    {
        JFrame f = new JFrame("Batik");
        SVGApplication app = new SVGApplication(f);
        f.getContentPane().add(app.createComponents());

        f.addWindowListener(new WindowAdapter()
        {
            public void windowClosing(WindowEvent e)
            {
                System.exit(0);
            }
        });

        f.setSize(400, 400);
        f.setVisible(true);
    }

    JFrame frame;
    JButton button1 = new JButton("Load...");
    JButton button2 = new JButton("Animate!!!");
    JLabel label = new JLabel();
    JSVGCanvas svgCanvas = new JSVGCanvas();

    SVGDocument tempDoc;
    Node tempNode;
    int counter = 0;
    boolean counting = false;

    public SVGApplication(JFrame f)
    {
        frame = f;
    }

    public JComponent createComponents()
    {
        // set doublebufferedrendering to true to avoid flicker
        svgCanvas.setDoubleBufferedRendering(true);

        final JPanel panel = new JPanel(new BorderLayout());

        JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT));

        p.add(button1);
        p.add(button2);

        p.add(label);

        panel.add("North", p);
        panel.add("Center", svgCanvas);

        // Set the button1 action.
        button1.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent ae)
            {
                JFileChooser fc = new JFileChooser(".");
                int choice = fc.showOpenDialog(panel);
                if (choice == JFileChooser.APPROVE_OPTION)
                {
                    File f = fc.getSelectedFile();
                    try
                    {
                        svgCanvas.setURI(f.toURL().toString());
                    }
                    catch (IOException ex)
                    {
                        ex.printStackTrace();
                    }
                }
            }
        });

        // Set the button2 action.
        button2.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent ae)
            {
              tempDoc = svgCanvas.getSVGDocument();
              tempNode = tempDoc.getElementById("text").getFirstChild();

              if (!counting)
              {
                counting = true;
                count();
              }
              else
              {
                counting = false;
              }
}
        });



        svgCanvas.addGVTTreeRendererListener(new GVTTreeRendererAdapter()
        {
            public void gvtRenderingCompleted(GVTTreeRendererEvent e)
            {

                if (counting)
                {
                  count();
                }
            }
        });

        return panel;
    }

  /**
  * pause for specified number of milliseconds
  */
  private void pause(int milliseconds)
  {
    try
    {
      Thread.sleep((long)(milliseconds));
    }
    catch(InterruptedException ie)
    {
        System.out.println("DisplayController, sleep interrupted:" +
ie.toString());
    }
  }

  private void count()
  {
    pause(500);
    counter = counter + 1;

    tempNode.setNodeValue(Integer.toString(counter));
    svgCanvas.setSVGDocument(tempDoc);
  }

}

Any ideas would be greatly appreciated

Thanks

Chris
This message is intended for the addressee only. It must not be disclosed
to, altered, copied or used by anyone other than the addressee(s). If you
have received this message in error, please notify our email administrator
at   postmaster@advent-comm.co.uk <mailto:postmaster@advent-comm.co.uk> and
destroy the message, removing it completely from your computer system. 
Thank you for your assistance. 

Mail Virus Warning
-------------------------------

This email and any attachment are believed to be free from viruses which
might affect any system into which they are received or opened, it is the
responsibility of the recipient to ensure that they are virus free.
 Advent Communications ltd accepts no liability whatsoever for any direct,
indirect or consequential loss or damage arising in any way from receipt,
opening or use.


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


Mime
View raw message