01: package com.opensymphony.workflow.designer.actions;
02:
03: import java.awt.event.ActionEvent;
04: import java.awt.image.BufferedImage;
05: import java.awt.*;
06: import java.io.File;
07: import java.io.IOException;
08: import javax.swing.*;
09: import javax.imageio.ImageIO;
10:
11: import com.opensymphony.workflow.designer.event.WorkspaceListener;
12: import com.opensymphony.workflow.designer.event.WorkspaceEvent;
13: import com.opensymphony.workflow.designer.*;
14:
15: /**
16: * @author Hani Suleiman (hani@formicary.net)
17: * Date: May 21, 2003
18: * Time: 5:51:14 PM
19: */
20: public class PNGExport extends AbstractAction implements
21: WorkspaceListener {
22: public PNGExport() {
23: setEnabled(false);
24: }
25:
26: public void actionPerformed(ActionEvent e) {
27: File output = Utils.promptUserForFile(
28: (Component) e.getSource(),
29: JFileChooser.FILES_AND_DIRECTORIES, true, ".png",
30: ResourceManager.getString("png.files"));
31: if (output == null)
32: return;
33: WorkflowGraph graph = WorkflowDesigner.INSTANCE
34: .getCurrentGraph();
35: BufferedImage image = Utils.toImage(graph);
36: try {
37: ImageIO.write(image, "png", output);
38: } catch (IOException e1) {
39: e1.printStackTrace();
40: }
41: }
42:
43: public void workspaceChanged(WorkspaceEvent event) {
44: if (event.getId() == WorkspaceEvent.WORKSPACE_OPENED) {
45: setEnabled(true);
46: } else {
47: setEnabled(false);
48: }
49: }
50: }
|