/** * Shows the image export dialog and processes the results. * * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */ public void actionPerformed(ActionEvent evt) { // lazy initialization if (chooser == null) init(); // open image save dialog File f = null; scaler.setImage(display.getOffscreenBuffer()); int returnVal = chooser.showSaveDialog(display); if (returnVal == JFileChooser.APPROVE_OPTION) { f = chooser.getSelectedFile(); } else { return; } String format = ((SimpleFileFilter) chooser.getFileFilter()).getExtension(); String ext = IOLib.getExtension(f); if (!format.equals(ext)) { f = new File(f.toString() + "." + format); } double scale = scaler.getScale(); // save image boolean success = false; try { OutputStream out = new BufferedOutputStream(new FileOutputStream(f)); System.out.print("Saving image " + f.getName() + ", " + format + " format..."); success = display.saveImage(out, format, scale); out.flush(); out.close(); System.out.println("\tDONE"); } catch (Exception e) { success = false; } // show result dialog on failure if (!success) { JOptionPane.showMessageDialog( display, "Error Saving Image!", "Image Save Error", JOptionPane.ERROR_MESSAGE); } }