public void actionPerformed(ActionEvent e) {
    JComponent c=(JComponent)environment.getActive();
    Component comp= (Component) environment.tabbed.getSelectedComponent();

    SVGDOMImplementation domImpl = (SVGDOMImplementation)SVGDOMImplementation.getDOMImplementation();
    
    String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
    Document document = domImpl.createDocument(svgNS, "svg", null);
    
    SVGGeneratorContext cntx = SVGGeneratorContext.createDefault(document);
    cntx.setComment("Generated by JFLAP using Batik SVG Generator");
    cntx.setEmbeddedFontsOn(true);
    
    SVGGraphics2D svgGenerator = new SVGGraphics2D(cntx, false);
    
    Image canvasimage = comp.createImage(comp.getWidth(),comp.getHeight());
    Graphics imgG = canvasimage.getGraphics(); //voodoo
    comp.paint(imgG);

    comp.print(svgGenerator);

//    svgGenerator.drawImage(canvasimage, null, null);

    Universe.CHOOSER.resetChoosableFileFilters();
    Universe.CHOOSER.setAcceptAllFileFilterUsed(false);
    Universe.CHOOSER.addChoosableFileFilter(new SVGFileFilter());
    int result = Universe.CHOOSER.showSaveDialog(c);
    while (result == JFileChooser.APPROVE_OPTION) {
        File file = Universe.CHOOSER.getSelectedFile();

        if (!new SVGFileFilter().accept(file))
            file = new File(file.getAbsolutePath() + ".svg");


        if (file.exists()) {
            int confirm = JOptionPane.showConfirmDialog(Universe.CHOOSER, "File exists. Shall I overwrite?", "FILE OVERWRITE ATTEMPTED", JOptionPane.YES_NO_OPTION);
            if (confirm == JOptionPane.NO_OPTION){ 
                result = Universe.CHOOSER.showSaveDialog(c);
                continue;
            }
        }

        try {
            Writer out = new OutputStreamWriter(new FileOutputStream(file),
                        "UTF-8");
            svgGenerator.stream(out, true);
            return;
        }
        catch (IOException ioe) {
            JOptionPane.showMessageDialog(c,
            "Export failed with error:\n"+ioe.getMessage(),
            "Export failed", JOptionPane.ERROR_MESSAGE);
            return;
        }
    }
    }