01: /*******************************************************************************
02: * Copyright (c) 2003, 2004 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Common Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/cpl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.openwfe.gpe.parts;
11:
12: import java.util.HashMap;
13: import java.util.List;
14: import java.util.Map;
15:
16: import org.eclipse.draw2d.AbstractLayout;
17: import org.eclipse.draw2d.IFigure;
18: import org.eclipse.draw2d.geometry.Dimension;
19: import org.eclipse.draw2d.geometry.Rectangle;
20: import org.eclipse.draw2d.graph.CompoundDirectedGraph;
21: import org.eclipse.draw2d.graph.CompoundDirectedGraphLayout;
22:
23: class GraphLayoutManager extends AbstractLayout {
24:
25: private FlowElementDiagramPart diagram;
26:
27: GraphLayoutManager(FlowElementDiagramPart diagram) {
28: this .diagram = diagram;
29: }
30:
31: protected Dimension calculatePreferredSize(IFigure container,
32: int wHint, int hHint) {
33: // if (state == PLAYBACK)
34: // return container.getSize();
35: container.validate();
36: List children = container.getChildren();
37: Rectangle result = new Rectangle().setLocation(container
38: .getClientArea().getLocation());
39: for (int i = 0; i < children.size(); i++)
40: result.union(((IFigure) children.get(i)).getBounds());
41: result.resize(container.getInsets().getWidth(), container
42: .getInsets().getHeight());
43: return result.getSize();
44: }
45:
46: public void layout(IFigure container) {
47: GraphAnimation.recordInitialState(container);
48: if (GraphAnimation.playbackState(container))
49: return;
50:
51: CompoundDirectedGraph graph = new CompoundDirectedGraph();
52: Map partsToNodes = new HashMap();
53: diagram.contributeNodesToGraph(graph, null, partsToNodes);
54: diagram.contributeEdgesToGraph(graph, partsToNodes);
55: new CompoundDirectedGraphLayout().visit(graph);
56: diagram.applyGraphResults(graph, partsToNodes);
57: }
58:
59: }
|