KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > workflow > designer > GraphTabbedPane


1 package com.opensymphony.workflow.designer;
2
3 import java.util.List JavaDoc;
4 import java.util.ArrayList JavaDoc;
5 import javax.swing.*;
6
7 /**
8  * User: Hani Suleiman
9  * Date: Jan 9, 2004
10  * Time: 1:22:46 PM
11  */

12 public class GraphTabbedPane extends JTabbedPane
13 {
14     private List JavaDoc graphs = new ArrayList JavaDoc();
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 JavaDoc workflowName)
24     {
25         for(int i = 0; i < getTabCount(); i++)
26         {
27           String JavaDoc 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 JavaDoc name, String JavaDoc 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 JavaDoc 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