source: branches/localSpectral/src/view/Viewer.java @ 36

Last change on this file since 36 was 36, checked in by toshi, 14 years ago

ultimo commit

File size: 3.5 KB
RevLine 
[27]1
2package view;
3
[32]4import clustering.VertexScore;
5import clustering.VertexString;
[34]6import edu.uci.ics.jung.algorithms.layout.DAGLayout;
[27]7import edu.uci.ics.jung.algorithms.layout.FRLayout;
[34]8import edu.uci.ics.jung.algorithms.layout.KKLayout;
[27]9import edu.uci.ics.jung.algorithms.layout.Layout;
10import edu.uci.ics.jung.graph.Graph;
11import edu.uci.ics.jung.visualization.BasicVisualizationServer;
[34]12import java.awt.BorderLayout;
[27]13import java.awt.Color;
14import java.awt.Dimension;
[34]15import java.awt.FlowLayout;
[32]16import java.awt.LayoutManager;
[27]17import java.awt.Paint;
[34]18import java.awt.event.ActionEvent;
19import java.awt.event.ActionListener;
[27]20import java.util.ArrayList;
21import java.util.List;
[34]22import javax.swing.JButton;
[27]23import javax.swing.JFrame;
[34]24import javax.swing.JPanel;
25import javax.swing.JTextArea;
[27]26import org.apache.commons.collections15.Transformer;
27
28
29
30public 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}
Note: See TracBrowser for help on using the repository browser.