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

Last change on this file since 32 was 32, checked in by toshi, 14 years ago
File size: 2.0 KB
RevLine 
[27]1
2package view;
3
[32]4import clustering.VertexScore;
5import clustering.VertexString;
[27]6import edu.uci.ics.jung.algorithms.layout.FRLayout;
7import edu.uci.ics.jung.algorithms.layout.Layout;
8import edu.uci.ics.jung.graph.Graph;
9import edu.uci.ics.jung.visualization.BasicVisualizationServer;
10import java.awt.Color;
11import java.awt.Dimension;
[32]12import java.awt.LayoutManager;
[27]13import java.awt.Paint;
14import java.util.ArrayList;
15import java.util.List;
16import javax.swing.JFrame;
17import org.apache.commons.collections15.Transformer;
18
19
20
21public class Viewer<V,E> {
22
23    Graph<V,E> graph;
24    Layout<V, E> layout;
25    BasicVisualizationServer<V,E> vv;
26    JFrame frame;
27
28    public Viewer(Graph<V,E> graph) {
29        this.graph = graph;
30        this.frame = new JFrame("Graph View");
31        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
32        layout = new FRLayout(graph);
33        layout.setSize(new Dimension(1000,700));
34        vv = new BasicVisualizationServer(layout);
35        vv.setPreferredSize(new Dimension(1000,700));
36        vv.getRenderContext().setVertexLabelTransformer(new VertexLabelTransformer<V, String>());
37    }
38
[32]39    public void setGraph(Graph<V, E> graph) {
40        this.graph = graph;
41        layout.setGraph(graph);
42        frame.repaint();
43    }
44   
45    public void viewGraphRank(List<VertexScore<V>> pagerank, List<V> cluster){
46         VertexPaintRankTransformer vertexPaint = new VertexPaintRankTransformer(pagerank,cluster);
47         vv.getRenderContext().setVertexFillPaintTransformer((Transformer<V, Paint>) vertexPaint);
48         
49         frame.getContentPane().add(vv);
50         frame.pack();
51         frame.repaint();
52         frame.setVisible(true);
53    }
[27]54
[32]55
[27]56    public void viewGraph(List<V> cut){
57       
58         if(cut != null){
59             VertexPaintTransformer<V,Paint> vertexPaint = new VertexPaintTransformer<V, Paint>(cut);
60             vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
61         }
62         
63         frame.getContentPane().add(vv);
64         frame.pack();
65         frame.repaint();
66         frame.setVisible(true);
67
68     }
69}
Note: See TracBrowser for help on using the repository browser.