View Javadoc
1   /*
2    * Copyright (c) 2008, The JUNG Authors
3    * All rights reserved.
4    * 
5    * This software is open-source under the BSD license; see either "license.txt"
6    * or https://github.com/jrtom/jung/blob/master/LICENSE for a description.
7    */
8   package edu.uci.ics.jung.samples;
9   
10  import java.io.IOException;
11  
12  import javax.swing.JFrame;
13  
14  import com.google.common.base.Supplier;
15  
16  import edu.uci.ics.jung.algorithms.layout.FRLayout;
17  import edu.uci.ics.jung.graph.Graph;
18  import edu.uci.ics.jung.graph.UndirectedSparseGraph;
19  import edu.uci.ics.jung.io.PajekNetReader;
20  import edu.uci.ics.jung.visualization.VisualizationViewer;
21  
22  /**
23   * A class that shows the minimal work necessary to load and visualize a graph.
24   */
25  public class SimpleGraphDraw 
26  {
27  
28      @SuppressWarnings({ "rawtypes", "unchecked" })
29  	public static void main(String[] args) throws IOException 
30      {
31          JFrame jf = new JFrame();
32  		Graph g = getGraph();
33          VisualizationViewer vv = new VisualizationViewer(new FRLayout(g));
34          jf.getContentPane().add(vv);
35          jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
36          jf.pack();
37          jf.setVisible(true);
38      }
39      
40      /**
41       * Generates a graph: in this case, reads it from the file
42       * "samples/datasetsgraph/simple.net"
43       * @return A sample undirected graph
44       * @throws IOException if there is an error in reading the file
45       */
46      @SuppressWarnings({ "rawtypes", "unchecked" })
47  	public static Graph getGraph() throws IOException 
48      {
49          PajekNetReader pnr = new PajekNetReader(new Supplier(){
50  			public Object get() {
51  				return new Object();
52  			}});
53          Graph g = new UndirectedSparseGraph();
54          
55          pnr.load("src/main/resources/datasets/simple.net", g);
56          return g;
57      }
58  }