1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
package algographe;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import javax.swing.JFrame;
import edu.uci.ics.jung.graph.*;
import edu.uci.ics.jung.graph.impl.DirectedSparseEdge;
import edu.uci.ics.jung.graph.impl.DirectedSparseGraph;
import edu.uci.ics.jung.graph.impl.DirectedSparseVertex;
import edu.uci.ics.jung.utils.UserData;
import edu.uci.ics.jung.visualization.Layout;
import edu.uci.ics.jung.visualization.PluggableRenderer;
import edu.uci.ics.jung.visualization.ShapePickSupport;
import edu.uci.ics.jung.visualization.VisualizationViewer;
import edu.uci.ics.jung.visualization.contrib.CircleLayout;
import edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse;
public class SimpleGraphView {
Graph g;
public SimpleGraphView() {
// Graph<V, E> where V is the type of the vertices and E is the type of the edges
g = new DirectedSparseGraph();
// Add some vertices. From above we defined these to be type Integer.
//Graph g = new DirectedSparseGraph();
Vertex v1 = (Vertex) g.addVertex(new DirectedSparseVertex());
Vertex v2 = (Vertex) g.addVertex(new DirectedSparseVertex());
// Note that the default is for undirected edges, our Edges are Strings.
// On ajoute encore 2 sommets et des aretes entre les sommets
Vertex v3 = (Vertex) g.addVertex(new DirectedSparseVertex());
Vertex v4 = (Vertex) g.addVertex(new DirectedSparseVertex());
g.addEdge(new DirectedSparseEdge(v1,v3));
g.addEdge(new DirectedSparseEdge(v3,v4));
}
public Graph getGraph( )
{
return g;
}
public static void main(String[] args) {
try
{
SimpleGraphView sgv = new SimpleGraphView(); //We create our graph in here
// The Layout<V, E> is parameterized by the vertex and edge types
// Objets necessaires pour afficher un graphe de Jung
DefaultModalGraphMouse m_graphmouse;
PluggableRenderer mainRender = new PluggableRenderer();
Graph g=sgv.getGraph();
Layout mainLayout = new CircleLayout(g); /* how nodes will be placed */
VisualizationViewer VV = new VisualizationViewer(mainLayout, mainRender, new Dimension(500,500));
// un minimum de config
VV.setPickSupport(new ShapePickSupport()); /* allow clickable stuff */
VV.setBackground(Color.WHITE);
// declare la visu de graphe comme partie d'une fenetre graphique et demande l'affichage
/* JFrame frame = new JFrame("Simple Graph View");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(VV); VV.init();
frame.setSize(new Dimension(500,500));
frame.setVisible(true);
frame.pack();*/
//frame.setVisible(true);
}
catch(Exception e)
{
}
}
} |
Partager