1 package com.opensymphony.workflow.designer.actions;2 3 import java.awt.event.ActionEvent ;4 import javax.swing.*;5 6 import com.opensymphony.workflow.designer.WorkflowGraph;7 import com.opensymphony.workflow.designer.WorkflowDesigner;8 import com.opensymphony.workflow.designer.event.WorkspaceListener;9 import com.opensymphony.workflow.designer.event.WorkspaceEvent;10 11 /**12 * @author Hani Suleiman (hani@formicary.net)13 * Date: May 20, 200314 * Time: 8:25:28 PM15 */16 public class AutoLayout extends AbstractAction implements WorkspaceListener17 {18 private WorkflowGraph graph;19 20 /**21 * Create an auto layout action.22 * This action calls an auto layout algorithm on the specified graph.23 * @param graph the graph to autolayout. If the graph is null, then the currently24 * showing graph has auto layout applied to it.25 */26 public AutoLayout(WorkflowGraph graph)27 {28 this.graph = graph;29 }30 31 public void actionPerformed(ActionEvent e)32 {33 if(graph==null)34 {35 WorkflowGraph selected = WorkflowDesigner.INSTANCE.getCurrentGraph();36 if(selected!=null)37 selected.autoLayout();38 }39 else40 {41 graph.autoLayout();42 }43 }44 45 public void workspaceChanged(WorkspaceEvent event)46 {47 if(event.getId()==WorkspaceEvent.WORKSPACE_OPENED)48 {49 setEnabled(true);50 }51 else52 {53 setEnabled(false);54 }55 }56 }57