KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ca > mcgill > sable > graph > editparts > GraphLayoutManager


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2005 Jennifer Lhotak
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * 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
21 package ca.mcgill.sable.graph.editparts;
22
23 import org.eclipse.draw2d.AbstractLayout;
24 import org.eclipse.draw2d.IFigure;
25 import org.eclipse.draw2d.geometry.*;
26 import org.eclipse.draw2d.graph.*;
27 import java.util.*;
28
29 public class GraphLayoutManager extends AbstractLayout {
30
31     private GraphEditPart graphPart;
32     
33
34     public GraphLayoutManager(GraphEditPart graphPart) {
35         setGraphPart(graphPart);
36     }
37
38     /* (non-Javadoc)
39      * @see org.eclipse.draw2d.AbstractLayout#calculatePreferredSize(org.eclipse.draw2d.IFigure, int, int)
40      */

41     protected Dimension calculatePreferredSize(
42         IFigure arg0,
43         int arg1,
44         int arg2) {
45         return null;
46     }
47
48     /* (non-Javadoc)
49      * @see org.eclipse.draw2d.LayoutManager#layout(org.eclipse.draw2d.IFigure)
50      */

51     public void layout(IFigure arg0) {
52         DirectedGraph graph = new DirectedGraph();
53         HashMap map = new HashMap();
54         // add nodes and edges to graph
55
// retrieve them from CFGGraphEditPart
56
getGraphPart().contributeNodesToGraph(graph, map);
57         getGraphPart().contributeEdgesToGraph(graph, map);
58         if (graph.nodes.size() != 0){
59             DirectedGraphLayout layout = new DirectedGraphLayout();
60             layout.visit(graph);
61             getGraphPart().applyGraphResults(graph, map);
62         }
63         
64     }
65
66     /**
67      * @return
68      */

69     public GraphEditPart getGraphPart() {
70         return graphPart;
71     }
72
73     /**
74      * @param part
75      */

76     public void setGraphPart(GraphEditPart part) {
77         graphPart = part;
78     }
79
80 }
81
Popular Tags