KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > workflow > designer > actions > PNGExport


1 package com.opensymphony.workflow.designer.actions;
2
3 import java.awt.event.ActionEvent JavaDoc;
4 import java.awt.image.BufferedImage JavaDoc;
5 import java.awt.*;
6 import java.io.File JavaDoc;
7 import java.io.IOException JavaDoc;
8 import javax.swing.*;
9 import javax.imageio.ImageIO JavaDoc;
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 WorkspaceListener
21 {
22   public PNGExport()
23   {
24     setEnabled(false);
25   }
26
27   public void actionPerformed(ActionEvent JavaDoc e)
28   {
29     File JavaDoc output = Utils.promptUserForFile((Component)e.getSource(), JFileChooser.FILES_AND_DIRECTORIES, true, ".png", ResourceManager.getString("png.files"));
30     if(output==null) return;
31     WorkflowGraph graph = WorkflowDesigner.INSTANCE.getCurrentGraph();
32     BufferedImage JavaDoc image = Utils.toImage(graph);
33     try
34     {
35       ImageIO.write(image, "png", output);
36     }
37     catch(IOException JavaDoc e1)
38     {
39       e1.printStackTrace();
40     }
41   }
42
43   public void workspaceChanged(WorkspaceEvent event)
44   {
45     if(event.getId()==WorkspaceEvent.WORKSPACE_OPENED)
46     {
47       setEnabled(true);
48     }
49     else
50     {
51       setEnabled(false);
52     }
53   }
54 }
55
Popular Tags