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