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

Last change on this file since 35 was 34, checked in by toshi, 14 years ago
File size: 3.1 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;
26import javax.xml.bind.JAXB;
[27]27import org.apache.commons.collections15.Transformer;
28
29
30
31public 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}
Note: See TracBrowser for help on using the repository browser.