01: package com.opensymphony.workflow.designer.actions;
02:
03: import java.awt.event.ActionEvent;
04: import javax.swing.*;
05:
06: import com.opensymphony.workflow.designer.WorkflowGraph;
07: import com.opensymphony.workflow.designer.WorkflowDesigner;
08: import com.opensymphony.workflow.designer.event.WorkspaceListener;
09: import com.opensymphony.workflow.designer.event.WorkspaceEvent;
10:
11: /**
12: * @author Hani Suleiman (hani@formicary.net)
13: * Date: May 20, 2003
14: * Time: 8:25:28 PM
15: */
16: public class AutoLayout extends AbstractAction implements
17: WorkspaceListener {
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 currently
24: * showing graph has auto layout applied to it.
25: */
26: public AutoLayout(WorkflowGraph graph) {
27: this .graph = graph;
28: }
29:
30: public void actionPerformed(ActionEvent e) {
31: if (graph == null) {
32: WorkflowGraph selected = WorkflowDesigner.INSTANCE
33: .getCurrentGraph();
34: if (selected != null)
35: selected.autoLayout();
36: } else {
37: graph.autoLayout();
38: }
39: }
40:
41: public void workspaceChanged(WorkspaceEvent event) {
42: if (event.getId() == WorkspaceEvent.WORKSPACE_OPENED) {
43: setEnabled(true);
44: } else {
45: setEnabled(false);
46: }
47: }
48: }
|