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

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

creato il branch local spectral

File size: 1.4 KB
Line 
1
2package view;
3
4import edu.uci.ics.jung.algorithms.layout.FRLayout;
5import edu.uci.ics.jung.algorithms.layout.Layout;
6import edu.uci.ics.jung.graph.Graph;
7import edu.uci.ics.jung.visualization.BasicVisualizationServer;
8import java.awt.Color;
9import java.awt.Dimension;
10import java.awt.Paint;
11import java.util.ArrayList;
12import java.util.List;
13import javax.swing.JFrame;
14import org.apache.commons.collections15.Transformer;
15
16
17
18public class Viewer<V,E> {
19
20    Graph<V,E> graph;
21    Layout<V, E> layout;
22    BasicVisualizationServer<V,E> vv;
23    JFrame frame;
24
25    public Viewer(Graph<V,E> graph) {
26        this.graph = graph;
27        this.frame = new JFrame("Graph View");
28        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
29        layout = new FRLayout(graph);
30        layout.setSize(new Dimension(1000,700));
31        vv = new BasicVisualizationServer(layout);
32        vv.setPreferredSize(new Dimension(1000,700));
33        vv.getRenderContext().setVertexLabelTransformer(new VertexLabelTransformer<V, String>());
34    }
35
36
37    public void viewGraph(List<V> cut){
38       
39         if(cut != null){
40             VertexPaintTransformer<V,Paint> vertexPaint = new VertexPaintTransformer<V, Paint>(cut);
41             vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
42         }
43         
44         frame.getContentPane().add(vv);
45         frame.pack();
46         frame.repaint();
47         frame.setVisible(true);
48
49     }
50}
Note: See TracBrowser for help on using the repository browser.