KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ca > mcgill > sable > soot > cfg > editParts > CFGGraphLayoutManager


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2004 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.soot.cfg.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 CFGGraphLayoutManager extends AbstractLayout {
30
31     private CFGGraphEditPart graphPart;
32
33     public CFGGraphLayoutManager(CFGGraphEditPart graphPart) {
34         setGraphPart(graphPart);
35     }
36
37     /* (non-Javadoc)
38      * @see org.eclipse.draw2d.AbstractLayout#calculatePreferredSize(org.eclipse.draw2d.IFigure, int, int)
39      */

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

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

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

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