01: /* Soot - a J*va Optimization Framework
02: * Copyright (C) 2005 Jennifer Lhotak
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the
16: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17: * Boston, MA 02111-1307, USA.
18: */
19:
20: package ca.mcgill.sable.graph.editparts;
21:
22: import org.eclipse.draw2d.AbstractLayout;
23: import org.eclipse.draw2d.IFigure;
24: import org.eclipse.draw2d.geometry.*;
25: import org.eclipse.draw2d.graph.*;
26: import java.util.*;
27:
28: public class GraphLayoutManager extends AbstractLayout {
29:
30: private GraphEditPart graphPart;
31:
32: public GraphLayoutManager(GraphEditPart graphPart) {
33: setGraphPart(graphPart);
34: }
35:
36: /* (non-Javadoc)
37: * @see org.eclipse.draw2d.AbstractLayout#calculatePreferredSize(org.eclipse.draw2d.IFigure, int, int)
38: */
39: protected Dimension calculatePreferredSize(IFigure arg0, int arg1,
40: int arg2) {
41: return null;
42: }
43:
44: /* (non-Javadoc)
45: * @see org.eclipse.draw2d.LayoutManager#layout(org.eclipse.draw2d.IFigure)
46: */
47: public void layout(IFigure arg0) {
48: DirectedGraph graph = new DirectedGraph();
49: HashMap map = new HashMap();
50: // add nodes and edges to graph
51: // retrieve them from CFGGraphEditPart
52: getGraphPart().contributeNodesToGraph(graph, map);
53: getGraphPart().contributeEdgesToGraph(graph, map);
54: if (graph.nodes.size() != 0) {
55: DirectedGraphLayout layout = new DirectedGraphLayout();
56: layout.visit(graph);
57: getGraphPart().applyGraphResults(graph, map);
58: }
59:
60: }
61:
62: /**
63: * @return
64: */
65: public GraphEditPart getGraphPart() {
66: return graphPart;
67: }
68:
69: /**
70: * @param part
71: */
72: public void setGraphPart(GraphEditPart part) {
73: graphPart = part;
74: }
75:
76: }
|