Line | |
---|
1 | |
---|
2 | package view; |
---|
3 | |
---|
4 | import edu.uci.ics.jung.graph.Graph; |
---|
5 | import edu.uci.ics.jung.graph.util.Pair; |
---|
6 | import java.io.File; |
---|
7 | import java.util.Collection; |
---|
8 | import java.util.List; |
---|
9 | |
---|
10 | public 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.