[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; |
---|
| 26 | import javax.xml.bind.JAXB; |
---|
[27] | 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; |
---|
[34] | 37 | JButton button; |
---|
| 38 | JPanel button_panel; |
---|
| 39 | JTextArea text ; |
---|
[27] | 40 | |
---|
[34] | 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 | |
---|
[27] | 50 | this.graph = graph; |
---|
[34] | 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)); |
---|
[27] | 58 | vv = new BasicVisualizationServer(layout); |
---|
[34] | 59 | vv.setPreferredSize(new Dimension(1280,700)); |
---|
| 60 | vv.add(this.button_panel); |
---|
| 61 | vv.add(this.text); |
---|
[27] | 62 | vv.getRenderContext().setVertexLabelTransformer(new VertexLabelTransformer<V, String>()); |
---|
[34] | 63 | |
---|
[27] | 64 | } |
---|
| 65 | |
---|
[34] | 66 | public void setText(String text){ |
---|
| 67 | this.text.setText(text); |
---|
| 68 | } |
---|
[32] | 69 | public void setGraph(Graph<V, E> graph) { |
---|
| 70 | this.graph = graph; |
---|
| 71 | layout.setGraph(graph); |
---|
| 72 | frame.repaint(); |
---|
| 73 | } |
---|
| 74 | |
---|
[34] | 75 | public void viewGraphRank(List<VertexScore<V>> pagerank, V seed_node){ |
---|
| 76 | VertexPaintRankTransformer vertexPaint = new VertexPaintRankTransformer(pagerank,seed_node); |
---|
[32] | 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 | } |
---|
[27] | 84 | |
---|
[32] | 85 | |
---|
[27] | 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 | } |
---|
[34] | 99 | |
---|
[27] | 100 | } |
---|