1 | |
---|
2 | package view; |
---|
3 | |
---|
4 | import edu.uci.ics.jung.algorithms.layout.FRLayout; |
---|
5 | import edu.uci.ics.jung.algorithms.layout.Layout; |
---|
6 | import edu.uci.ics.jung.graph.Graph; |
---|
7 | import edu.uci.ics.jung.visualization.BasicVisualizationServer; |
---|
8 | import java.awt.Color; |
---|
9 | import java.awt.Dimension; |
---|
10 | import java.awt.Paint; |
---|
11 | import java.util.ArrayList; |
---|
12 | import java.util.List; |
---|
13 | import javax.swing.JFrame; |
---|
14 | import org.apache.commons.collections15.Transformer; |
---|
15 | |
---|
16 | |
---|
17 | |
---|
18 | public class Viewer<V,E> { |
---|
19 | |
---|
20 | Graph<V,E> graph; |
---|
21 | Layout<V, E> layout; |
---|
22 | BasicVisualizationServer<V,E> vv; |
---|
23 | JFrame frame; |
---|
24 | |
---|
25 | public Viewer(Graph<V,E> graph) { |
---|
26 | this.graph = graph; |
---|
27 | this.frame = new JFrame("Graph View"); |
---|
28 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
---|
29 | layout = new FRLayout(graph); |
---|
30 | layout.setSize(new Dimension(1000,700)); |
---|
31 | vv = new BasicVisualizationServer(layout); |
---|
32 | vv.setPreferredSize(new Dimension(1000,700)); |
---|
33 | vv.getRenderContext().setVertexLabelTransformer(new VertexLabelTransformer<V, String>()); |
---|
34 | } |
---|
35 | |
---|
36 | |
---|
37 | public void viewGraph(List<V> cut){ |
---|
38 | |
---|
39 | if(cut != null){ |
---|
40 | VertexPaintTransformer<V,Paint> vertexPaint = new VertexPaintTransformer<V, Paint>(cut); |
---|
41 | vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint); |
---|
42 | } |
---|
43 | |
---|
44 | frame.getContentPane().add(vv); |
---|
45 | frame.pack(); |
---|
46 | frame.repaint(); |
---|
47 | frame.setVisible(true); |
---|
48 | |
---|
49 | } |
---|
50 | } |
---|