public static int showSaveDialog ( SVGPlot plot , int width , int height ) { JFileChooser fc = new JFileChooser ( new File ( "." ) ) ; fc . setDialogTitle ( DEFAULT_TITLE ) ; // fc.setFileFilter(new ImageFilter()); SaveOptionsPanel optionsPanel = new SaveOptionsPanel ( fc , width , height ) ; fc . setAccessory ( optionsPanel ) ; int ret = fc . showSaveDialog ( null ) ; if ( ret == JFileChooser . APPROVE_OPTION ) { fc . setDialogTitle ( "Saving... Please wait." ) ; File file = fc . getSelectedFile ( ) ; String format = optionsPanel . getSelectedFormat ( ) ; width = optionsPanel . getSelectedWidth ( ) ; height = optionsPanel . getSelectedHeight ( ) ; if ( format == null || AUTOMAGIC_FORMAT . equals ( format ) ) { format = guessFormat ( file . getName ( ) ) ; } try { if ( format == null ) { showError ( fc , "Error saving image." , "File format not recognized." ) ; } else if ( "jpeg" . equals ( format ) || "jpg" . equals ( format ) ) { float quality = optionsPanel . getJPEGQuality ( ) ; plot . saveAsJPEG ( file , width , height , quality ) ; } else if ( "png" . equals ( format ) ) { plot . saveAsPNG ( file , width , height ) ; } else if ( "ps" . equals ( format ) ) { plot . saveAsPS ( file ) ; } else if ( "eps" . equals ( format ) ) { plot . saveAsEPS ( file ) ; } else if ( "pdf" . equals ( format ) ) { plot . saveAsPDF ( file ) ; } else if ( "svg" . equals ( format ) ) { plot . saveAsSVG ( file ) ; } else { showError ( fc , "Error saving image." , "Unsupported format: " + format ) ; } } catch ( java . lang . IncompatibleClassChangeError e ) { showError ( fc , "Error saving image." , "It seems that your Java version is incompatible with this version of Batik and Jpeg writing. Sorry." ) ; } catch ( ClassNotFoundException e ) { showError ( fc , "Error saving image." , "A class was not found when saving this image. Maybe installing Apache FOP will help (for PDF, PS and EPS output).\n" + e . toString ( ) ) ; } catch ( TransformerFactoryConfigurationError | Exception e ) { LOG . exception ( e ) ; showError ( fc , "Error saving image." , e . toString ( ) ) ; } } else if ( ret == JFileChooser . ERROR_OPTION ) { showError ( fc , "Error in file dialog." , "Unknown Error." ) ; } else if ( ret == JFileChooser . CANCEL_OPTION ) { // do nothing - except return result } return ret ; }
Show a Save as dialog .