KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > workfloweditor > DisplayManager


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.workfloweditor;
20
21 import java.awt.*;
22 import java.awt.event.*;
23 import java.awt.geom.*;
24 import java.util.*;
25 import java.util.List JavaDoc;
26
27 import javax.swing.*;
28
29 import org.openharmonise.him.*;
30 import org.openharmonise.him.dnd.*;
31 import org.openharmonise.him.harmonise.*;
32 import org.openharmonise.him.swing.resourcetree.*;
33 import org.openharmonise.vfs.*;
34 import org.openharmonise.vfs.gui.*;
35 import org.openharmonise.vfs.servers.*;
36 import org.openharmonise.workfloweditor.flowchart.*;
37 import org.openharmonise.workfloweditor.flowchart.shapes.*;
38 import org.openharmonise.workfloweditor.vfs.*;
39
40
41 /**
42  * The display manager handles the layout of the main window for the
43  * workflow editor.
44  *
45  * @author Matthew Large
46  * @version $Revision: 1.1 $
47  *
48  */

49 public class DisplayManager extends JFrame {
50
51     /**
52      * The workflow diagram.
53      */

54     private FlowChart m_chart = null;
55     
56     /**
57      * The workflow editor.
58      */

59     private WorkflowEditor m_editor = null;
60
61     /**
62      * Constructs a new display manager.
63      *
64      * @param editor Workflow editor
65      */

66     public DisplayManager(WorkflowEditor editor) {
67         super();
68         this.m_editor = editor;
69         this.setup();
70     }
71     
72     /**
73      * Configures the display manager.
74      *
75      */

76     private void setup() {
77         
78         this.setTitle("Workflow Editor");
79
80         this.setIconImage( ((ImageIcon)IconManager.getInstance().getIcon("16-command-change-status.gif")).getImage());
81         
82         
83         this.setSize(700,700);
84         int x = this.getGraphicsConfiguration().getBounds().width/2-this.getSize().width/2;
85         int y = this.getGraphicsConfiguration().getBounds().height/2-this.getSize().height/2;
86         
87         this.setLocation(x, y);
88         
89         this.addWindowListener(new WindowAdapter() {
90             public void windowClosing(WindowEvent woo) {
91                 shutdown();
92             }
93         });
94         
95         JPanel leftPanel = new JPanel();
96         leftPanel.setLayout( new BorderLayout());
97         
98         ResourceTree tree = new ResourceTree();
99         tree.setShowLeafNodes(true);
100         tree.setShowApprovedOnly(true);
101
102         Server server = ServerList.getInstance().getHarmoniseServer();
103         
104         VirtualFile vfFile = server.getVFS().getVirtualFile( HarmonisePaths.PATH_WORKFLOW_STAGES ).getResource();
105         
106         tree.addCollection(vfFile);
107         
108         
109         leftPanel.add( tree );
110         leftPanel.setBackground(Color.RED);
111         
112         JPanel rightPanel = new JPanel();
113         rightPanel.setLayout( new BorderLayout());
114         this.m_chart = new FlowChart();
115         this.m_chart.setPreferredSize(new Dimension(2000,2000));
116         
117         WorkflowDropTarget dropTarget = new WorkflowDropTarget(this.m_chart, tree);
118         
119         JScrollPane scroller = new JScrollPane(this.m_chart, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
120         scroller.getVerticalScrollBar().setUnitIncrement(50);
121         scroller.getHorizontalScrollBar().setUnitIncrement(50);
122         
123         rightPanel.add( scroller );
124         rightPanel.setBackground(Color.YELLOW);
125         
126         JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, rightPanel);
127         splitPane.setOneTouchExpandable(true);
128         splitPane.setContinuousLayout(true);
129         splitPane.setDividerLocation(150);
130         this.getContentPane().add(splitPane);
131         this.show();
132             
133     }
134     
135     /**
136      * Returns the workflow diagram.
137      *
138      * @return Workflow diagram
139      */

140     public FlowChart getFlowChart() {
141         return this.m_chart;
142     }
143
144     /**
145      * Prepares the display manager for shut down.
146      */

147     protected void shutdown() {
148         this.saveChartLayout();
149         this.hide();
150         this.m_editor.shutdown();
151     }
152     
153     /**
154      * Saves the workflow diagram layout.
155      *
156      */

157     private void saveChartLayout() {
158         try {
159             List JavaDoc shapes = this.m_chart.getShapes();
160             Iterator itor = shapes.iterator();
161             while (itor.hasNext()) {
162                 AbstractWorkflowShape shape = (AbstractWorkflowShape) itor.next();
163                 if(shape instanceof StageShape) {
164                     VFSWorkflowStage vfsStage = (VFSWorkflowStage) ((StageShape)shape).getStage();
165                     String JavaDoc sWorkflowPath = ((VFSWorkflowModel)this.m_chart.getModel()).getStagesCollection().getFullPath();
166                     String JavaDoc sStagePath = vfsStage.getPath();
167                     Point2D.Float point = new Point2D.Float(shape.getX(), shape.getY());
168                 
169                     WorkflowLayoutStore.getInstance().setStageLayout(sWorkflowPath, sStagePath, point);
170                 }
171             }
172         } catch(Exception JavaDoc e) {
173             e.printStackTrace();
174         }
175     }
176 }
177
Popular Tags