1 package com.opensymphony.workflow.designer.actions; 2 3 import java.awt.event.ActionEvent ; 4 import java.awt.image.BufferedImage ; 5 import java.awt.*; 6 import java.io.File ; 7 import java.io.IOException ; 8 import javax.swing.*; 9 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 20 public class PNGExport extends AbstractAction implements WorkspaceListener 21 { 22 public PNGExport() 23 { 24 setEnabled(false); 25 } 26 27 public void actionPerformed(ActionEvent e) 28 { 29 File 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 image = Utils.toImage(graph); 33 try 34 { 35 ImageIO.write(image, "png", output); 36 } 37 catch(IOException 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 |