01: /**
02: * SEQUENCE - A very simple sequence diagram editor
03: * Copyright (C) 2002 Alex Moffat
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: */package com.zanthan.sequence;
19:
20: import java.awt.Dimension;
21:
22: import java.awt.event.ActionEvent;
23:
24: import java.awt.image.BufferedImage;
25:
26: import java.io.File;
27: import java.io.IOException;
28:
29: import javax.imageio.ImageIO;
30:
31: import javax.swing.JFileChooser;
32:
33: public class ExportAction extends SequenceAction {
34:
35: private Display display = null;
36:
37: ExportAction(Display display) {
38: super ("ExportAction", true);
39: this .display = display;
40: }
41:
42: public void actionPerformed(ActionEvent e) {
43: final JFileChooser chooser = new JFileChooser();
44: chooser.setDialogType(JFileChooser.SAVE_DIALOG);
45: chooser.setDialogTitle(getResource("dialogTitle"));
46:
47: // FIXED: uses save instead of open.
48: int returnVal = chooser.showSaveDialog(Sequence.getInstance());
49: if (returnVal == JFileChooser.APPROVE_OPTION) {
50: export(chooser.getSelectedFile());
51: }
52: }
53:
54: private void export(File file) {
55: Dimension size = display.getPreferredSize();
56: BufferedImage bi = new BufferedImage(size.width, size.height,
57: BufferedImage.TYPE_INT_ARGB);
58: display.paintComponent(bi.createGraphics());
59: try {
60: ImageIO.write(bi, "png", file);
61: } catch (IOException ioe) {
62: Sequence.getInstance().exception(ioe);
63: }
64: }
65: }
|