1 19 package com.zanthan.sequence; 20 21 import java.awt.Dimension ; 22 23 import java.awt.event.ActionEvent ; 24 25 import java.awt.image.BufferedImage ; 26 27 import java.io.File ; 28 import java.io.IOException ; 29 30 import javax.imageio.ImageIO ; 31 32 import javax.swing.JFileChooser ; 33 34 public class ExportAction 35 extends SequenceAction { 36 37 private Display display = null; 38 39 ExportAction(Display display) { 40 super("ExportAction", true); 41 this.display = display; 42 } 43 44 public void actionPerformed(ActionEvent e) { 45 final JFileChooser chooser = new JFileChooser (); 46 chooser.setDialogType(JFileChooser.SAVE_DIALOG); 47 chooser.setDialogTitle(getResource("dialogTitle")); 48 49 int returnVal = chooser.showSaveDialog(Sequence.getInstance()); 51 if (returnVal == JFileChooser.APPROVE_OPTION) { 52 export(chooser.getSelectedFile()); 53 } 54 } 55 56 private void export(File file) { 57 Dimension size = display.getPreferredSize(); 58 BufferedImage bi = new BufferedImage (size.width, 59 size.height, 60 BufferedImage.TYPE_INT_ARGB); 61 display.paintComponent(bi.createGraphics()); 62 try { 63 ImageIO.write(bi, "png", file); 64 } catch (IOException ioe) { 65 Sequence.getInstance().exception(ioe); 66 } 67 } 68 } 69 | Popular Tags |