1 package com.opensymphony.workflow.designer; 2 3 import java.util.List ; 4 import java.util.ArrayList ; 5 import javax.swing.*; 6 7 12 public class GraphTabbedPane extends JTabbedPane 13 { 14 private List graphs = new ArrayList (); 15 16 public WorkflowGraph getCurrentGraph() 17 { 18 int index = getSelectedIndex(); 19 if(index == -1 || index >= graphs.size()) return null; 20 return (WorkflowGraph)graphs.get(index); 21 } 22 23 public boolean selectWorkflow(String workflowName) 24 { 25 for(int i = 0; i < getTabCount(); i++) 26 { 27 String name = getTitleAt(i); 28 if(name.equals(workflowName)) 29 { 30 setSelectedIndex(i); 31 return true; 32 } 33 } 34 return false; 35 } 36 37 public void addGraph(WorkflowGraph graph) 38 { 39 graphs.add(graph); 40 add(graph.getName(), new JScrollPane(graph)); 41 setSelectedIndex(getComponentCount() - 1); 42 } 43 44 public void removeAll() 45 { 46 super.removeAll(); 47 graphs.clear(); 48 } 49 50 public WorkflowGraph[] getGraphs() 51 { 52 WorkflowGraph[] g = new WorkflowGraph[graphs.size()]; 53 graphs.toArray(g); 54 return g; 55 } 56 57 public void renameGraph(String name, String newName) 58 { 59 for(int i=0;i<graphs.size();i++) 60 { 61 WorkflowGraph graph = (WorkflowGraph)graphs.get(i); 62 if(graph.getName().equals(name)) 63 { 64 graph.setName(newName); 65 setTitleAt(i, newName); 66 return; 67 } 68 } 69 } 70 71 public void removeGraph(String name) 72 { 73 for(int i=0;i<graphs.size();i++) 74 { 75 WorkflowGraph graph = (WorkflowGraph)graphs.get(i); 76 if(graph.getName().equals(name)) 77 { 78 removeTabAt(i); 79 graphs.remove(i); 80 revalidate(); 81 return; 82 } 83 } 84 } 85 86 public void removeGraph(WorkflowGraph graph) 87 { 88 for(int i=0;i<graphs.size();i++) 89 { 90 WorkflowGraph g = (WorkflowGraph)graphs.get(i); 91 if(graph == g) 92 { 93 removeTabAt(i); 94 graphs.remove(i); 95 revalidate(); 96 return; 97 } 98 } 99 } 100 } 101 | Popular Tags |