import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

import org.apache.batik.swing.JSVGCanvas;

public class JSVGCanvasTester extends JFrame
{
    private static final long serialVersionUID = -5989881674509541041L;
    private static JSVGCanvas canvas = null;
    private JButton stop;
    private static JSVGCanvasTester jsvgct = null;

    public static void main(String[] args)
    {
        jsvgct = new JSVGCanvasTester();
    }

    public JSVGCanvasTester()
    {
        super("Fenster");
        this.setSize(640, 480);
        this.setLocation(300, 300);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setLayout(new BorderLayout());

        JPanel dummy = new JPanel();
        dummy.setLayout(new FlowLayout(FlowLayout.CENTER));

        stop = new JButton("Stop");
        dummy.add(stop);
        stop.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                jsvgct.dispose();
                System.exit(0);
            }
        });

        canvas = new JSVGCanvas();
        canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
        setSVGDocument(new File("2.svg"));

        this.getContentPane().add(canvas, BorderLayout.CENTER);
        this.getContentPane().add(dummy, BorderLayout.SOUTH);
        this.setVisible(true);
    }

    public static void setSVGDocument(File svgFile)
    {
        try
        {
            canvas.setURI(svgFile.toURL().toString());
        }
        catch (IOException ex)
        {
            ex.printStackTrace();
        }
    }
}
