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