1 | |
---|
2 | package view; |
---|
3 | |
---|
4 | import clustering.VertexScore; |
---|
5 | import clustering.VertexString; |
---|
6 | import edu.uci.ics.jung.algorithms.layout.DAGLayout; |
---|
7 | import edu.uci.ics.jung.algorithms.layout.FRLayout; |
---|
8 | import edu.uci.ics.jung.algorithms.layout.KKLayout; |
---|
9 | import edu.uci.ics.jung.algorithms.layout.Layout; |
---|
10 | import edu.uci.ics.jung.graph.Graph; |
---|
11 | import edu.uci.ics.jung.visualization.BasicVisualizationServer; |
---|
12 | import java.awt.BorderLayout; |
---|
13 | import java.awt.Color; |
---|
14 | import java.awt.Dimension; |
---|
15 | import java.awt.FlowLayout; |
---|
16 | import java.awt.LayoutManager; |
---|
17 | import java.awt.Paint; |
---|
18 | import java.awt.event.ActionEvent; |
---|
19 | import java.awt.event.ActionListener; |
---|
20 | import java.util.ArrayList; |
---|
21 | import java.util.List; |
---|
22 | import javax.swing.JButton; |
---|
23 | import javax.swing.JFrame; |
---|
24 | import javax.swing.JPanel; |
---|
25 | import javax.swing.JTextArea; |
---|
26 | import javax.xml.bind.JAXB; |
---|
27 | import org.apache.commons.collections15.Transformer; |
---|
28 | |
---|
29 | |
---|
30 | |
---|
31 | public class Viewer<V,E> { |
---|
32 | |
---|
33 | Graph<V,E> graph; |
---|
34 | Layout<V, E> layout; |
---|
35 | BasicVisualizationServer<V,E> vv; |
---|
36 | JFrame frame; |
---|
37 | JButton button; |
---|
38 | JPanel button_panel; |
---|
39 | JTextArea text ; |
---|
40 | |
---|
41 | public Viewer(Graph<V,E> graph, ActionListener listerner) { |
---|
42 | this.button = new JButton("Next"); |
---|
43 | this.button.addActionListener(listerner); |
---|
44 | this.button_panel = new JPanel(new BorderLayout(100,100)); |
---|
45 | this.button_panel.add(button); |
---|
46 | this.text = new JTextArea(); |
---|
47 | this.text.setEditable(false); |
---|
48 | this.text.setBackground(Color.yellow); |
---|
49 | |
---|
50 | this.graph = graph; |
---|
51 | this.frame = new JFrame("Clustering with Google PageRank"); |
---|
52 | this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
---|
53 | KKLayout kklayout = new KKLayout(graph); |
---|
54 | kklayout.setAdjustForGravity(false); |
---|
55 | kklayout.setMaxIterations(100); |
---|
56 | this.layout = kklayout; |
---|
57 | layout.setSize(new Dimension(1280,700)); |
---|
58 | vv = new BasicVisualizationServer(layout); |
---|
59 | vv.setPreferredSize(new Dimension(1280,700)); |
---|
60 | vv.add(this.button_panel); |
---|
61 | vv.add(this.text); |
---|
62 | vv.getRenderContext().setVertexLabelTransformer(new VertexLabelTransformer<V, String>()); |
---|
63 | |
---|
64 | } |
---|
65 | |
---|
66 | public void setText(String text){ |
---|
67 | this.text.setText(text); |
---|
68 | } |
---|
69 | public void setGraph(Graph<V, E> graph) { |
---|
70 | this.graph = graph; |
---|
71 | layout.setGraph(graph); |
---|
72 | frame.repaint(); |
---|
73 | } |
---|
74 | |
---|
75 | public void viewGraphRank(List<VertexScore<V>> pagerank, V seed_node){ |
---|
76 | VertexPaintRankTransformer vertexPaint = new VertexPaintRankTransformer(pagerank,seed_node); |
---|
77 | vv.getRenderContext().setVertexFillPaintTransformer((Transformer<V, Paint>) vertexPaint); |
---|
78 | |
---|
79 | frame.getContentPane().add(vv); |
---|
80 | frame.pack(); |
---|
81 | frame.repaint(); |
---|
82 | frame.setVisible(true); |
---|
83 | } |
---|
84 | |
---|
85 | |
---|
86 | public void viewGraph(List<V> cut){ |
---|
87 | |
---|
88 | if(cut != null){ |
---|
89 | VertexPaintTransformer<V,Paint> vertexPaint = new VertexPaintTransformer<V, Paint>(cut); |
---|
90 | vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint); |
---|
91 | } |
---|
92 | |
---|
93 | frame.getContentPane().add(vv); |
---|
94 | frame.pack(); |
---|
95 | frame.repaint(); |
---|
96 | frame.setVisible(true); |
---|
97 | |
---|
98 | } |
---|
99 | |
---|
100 | } |
---|