source: branches/localSpectral/src/view/GraphToGraphviz.java @ 38

Last change on this file since 38 was 37, checked in by toshi, 14 years ago
File size: 772 bytes
RevLine 
[37]1
2package view;
3
4import edu.uci.ics.jung.graph.Graph;
5import edu.uci.ics.jung.graph.util.Pair;
6import java.io.File;
7import java.util.Collection;
8import java.util.List;
9
10public class GraphToGraphviz<V,E> {
11
12    GraphViz gv;
13
14    public GraphToGraphviz(){
15        gv = new GraphViz();
16    }
17
18    public void renderGraph(Graph<V,E> graph){
19        Collection<E> edges = graph.getEdges();
20        gv.addln(gv.start_graph());
21        for (E edge : edges){
22            Pair<V> nodes = graph.getEndpoints(edge);
23            gv.addln(nodes.getFirst().toString() + " -> " + nodes.getSecond().toString());
24        }
25        gv.addln(gv.end_graph());
26        File out = new File("/home/luke/Desktop/out.gif");
27        gv.writeGraphToFile(gv.getGraph(gv.getDotSource()), out);
28    }
29}
Note: See TracBrowser for help on using the repository browser.