KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > zanthan > sequence > ExportAction


1 /**
2  * SEQUENCE - A very simple sequence diagram editor
3  * Copyright (C) 2002 Alex Moffat
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
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  */

19 package com.zanthan.sequence;
20
21 import java.awt.Dimension JavaDoc;
22
23 import java.awt.event.ActionEvent JavaDoc;
24
25 import java.awt.image.BufferedImage JavaDoc;
26
27 import java.io.File JavaDoc;
28 import java.io.IOException JavaDoc;
29
30 import javax.imageio.ImageIO JavaDoc;
31
32 import javax.swing.JFileChooser JavaDoc;
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 JavaDoc e) {
45     final JFileChooser JavaDoc chooser = new JFileChooser JavaDoc();
46     chooser.setDialogType(JFileChooser.SAVE_DIALOG);
47     chooser.setDialogTitle(getResource("dialogTitle"));
48
49     // FIXED: uses save instead of open.
50
int returnVal = chooser.showSaveDialog(Sequence.getInstance());
51     if (returnVal == JFileChooser.APPROVE_OPTION) {
52         export(chooser.getSelectedFile());
53     }
54     }
55
56     private void export(File JavaDoc file) {
57     Dimension JavaDoc size = display.getPreferredSize();
58     BufferedImage JavaDoc bi = new BufferedImage JavaDoc(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 JavaDoc ioe) {
65         Sequence.getInstance().exception(ioe);
66     }
67     }
68 }
69
Popular Tags