public static void saveGraph(Component apane, JComponent c, String description,  String format){
           
           if (apane instanceof EditorPane){
               apane = ((EditorPane)apane).getAutomatonPane();
           }

           Image canvasimage = apane.createImage(apane.getWidth(),apane.getHeight());
           Graphics imgG = canvasimage.getGraphics();
           apane.paint(imgG);
           BufferedImage bimg = new BufferedImage(canvasimage.getWidth(null), canvasimage.getHeight(null), BufferedImage.TYPE_INT_RGB);
           Graphics2D g = bimg.createGraphics();
           g.drawImage(canvasimage, null, null);
           


           Universe.CHOOSER.resetChoosableFileFilters();
           Universe.CHOOSER.setAcceptAllFileFilterUsed(false);
        
           FileFilter spec = new FileNameExtensionFilter(description, format.split(","));

           Universe.CHOOSER.addChoosableFileFilter(spec);
           Universe.CHOOSER.addChoosableFileFilter(new AcceptAllFileFilter());
           Universe.CHOOSER.setFileFilter(spec);


           int result = Universe.CHOOSER.showSaveDialog(c);
           while (result == JFileChooser.APPROVE_OPTION) {
                    File file = Universe.CHOOSER.getSelectedFile();

                    if (!new FileNameExtensionFilter(description, format.split(",")).accept(file)) //only append if the chosen name is not acceptable
                        file = new File(file.getAbsolutePath() + "." + format.split(",")[0]);

                    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  
             {
                    ImageIO.write(bimg, format.split(",")[0], file);
                    return;
              } 
             catch (IOException ioe)  
             {  
                    JOptionPane.showMessageDialog(c,
                    "Save failed with error:\n"+ioe.getMessage(),
                    "Save failed", JOptionPane.ERROR_MESSAGE);
                    return;
             }
		}
        }