001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.workfloweditor;
020:
021: import java.awt.*;
022: import java.awt.event.*;
023: import java.awt.geom.*;
024: import java.util.*;
025: import java.util.List;
026:
027: import javax.swing.*;
028:
029: import org.openharmonise.him.*;
030: import org.openharmonise.him.dnd.*;
031: import org.openharmonise.him.harmonise.*;
032: import org.openharmonise.him.swing.resourcetree.*;
033: import org.openharmonise.vfs.*;
034: import org.openharmonise.vfs.gui.*;
035: import org.openharmonise.vfs.servers.*;
036: import org.openharmonise.workfloweditor.flowchart.*;
037: import org.openharmonise.workfloweditor.flowchart.shapes.*;
038: import org.openharmonise.workfloweditor.vfs.*;
039:
040: /**
041: * The display manager handles the layout of the main window for the
042: * workflow editor.
043: *
044: * @author Matthew Large
045: * @version $Revision: 1.1 $
046: *
047: */
048: public class DisplayManager extends JFrame {
049:
050: /**
051: * The workflow diagram.
052: */
053: private FlowChart m_chart = null;
054:
055: /**
056: * The workflow editor.
057: */
058: private WorkflowEditor m_editor = null;
059:
060: /**
061: * Constructs a new display manager.
062: *
063: * @param editor Workflow editor
064: */
065: public DisplayManager(WorkflowEditor editor) {
066: super ();
067: this .m_editor = editor;
068: this .setup();
069: }
070:
071: /**
072: * Configures the display manager.
073: *
074: */
075: private void setup() {
076:
077: this .setTitle("Workflow Editor");
078:
079: this .setIconImage(((ImageIcon) IconManager.getInstance()
080: .getIcon("16-command-change-status.gif")).getImage());
081:
082: this .setSize(700, 700);
083: int x = this .getGraphicsConfiguration().getBounds().width / 2
084: - this .getSize().width / 2;
085: int y = this .getGraphicsConfiguration().getBounds().height / 2
086: - this .getSize().height / 2;
087:
088: this .setLocation(x, y);
089:
090: this .addWindowListener(new WindowAdapter() {
091: public void windowClosing(WindowEvent woo) {
092: shutdown();
093: }
094: });
095:
096: JPanel leftPanel = new JPanel();
097: leftPanel.setLayout(new BorderLayout());
098:
099: ResourceTree tree = new ResourceTree();
100: tree.setShowLeafNodes(true);
101: tree.setShowApprovedOnly(true);
102:
103: Server server = ServerList.getInstance().getHarmoniseServer();
104:
105: VirtualFile vfFile = server.getVFS().getVirtualFile(
106: HarmonisePaths.PATH_WORKFLOW_STAGES).getResource();
107:
108: tree.addCollection(vfFile);
109:
110: leftPanel.add(tree);
111: leftPanel.setBackground(Color.RED);
112:
113: JPanel rightPanel = new JPanel();
114: rightPanel.setLayout(new BorderLayout());
115: this .m_chart = new FlowChart();
116: this .m_chart.setPreferredSize(new Dimension(2000, 2000));
117:
118: WorkflowDropTarget dropTarget = new WorkflowDropTarget(
119: this .m_chart, tree);
120:
121: JScrollPane scroller = new JScrollPane(this .m_chart,
122: JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
123: JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
124: scroller.getVerticalScrollBar().setUnitIncrement(50);
125: scroller.getHorizontalScrollBar().setUnitIncrement(50);
126:
127: rightPanel.add(scroller);
128: rightPanel.setBackground(Color.YELLOW);
129:
130: JSplitPane splitPane = new JSplitPane(
131: JSplitPane.HORIZONTAL_SPLIT, leftPanel, rightPanel);
132: splitPane.setOneTouchExpandable(true);
133: splitPane.setContinuousLayout(true);
134: splitPane.setDividerLocation(150);
135: this .getContentPane().add(splitPane);
136: this .show();
137:
138: }
139:
140: /**
141: * Returns the workflow diagram.
142: *
143: * @return Workflow diagram
144: */
145: public FlowChart getFlowChart() {
146: return this .m_chart;
147: }
148:
149: /**
150: * Prepares the display manager for shut down.
151: */
152: protected void shutdown() {
153: this .saveChartLayout();
154: this .hide();
155: this .m_editor.shutdown();
156: }
157:
158: /**
159: * Saves the workflow diagram layout.
160: *
161: */
162: private void saveChartLayout() {
163: try {
164: List shapes = this .m_chart.getShapes();
165: Iterator itor = shapes.iterator();
166: while (itor.hasNext()) {
167: AbstractWorkflowShape shape = (AbstractWorkflowShape) itor
168: .next();
169: if (shape instanceof StageShape) {
170: VFSWorkflowStage vfsStage = (VFSWorkflowStage) ((StageShape) shape)
171: .getStage();
172: String sWorkflowPath = ((VFSWorkflowModel) this .m_chart
173: .getModel()).getStagesCollection()
174: .getFullPath();
175: String sStagePath = vfsStage.getPath();
176: Point2D.Float point = new Point2D.Float(shape
177: .getX(), shape.getY());
178:
179: WorkflowLayoutStore.getInstance().setStageLayout(
180: sWorkflowPath, sStagePath, point);
181: }
182: }
183: } catch (Exception e) {
184: e.printStackTrace();
185: }
186: }
187: }
|