/** * Constructs a new JGraph model adapter for the specified JGraphT graph. * * @param jGraphTGraph the JGraphT graph for which JGraph model adapter to be created. <code>null * </code> is NOT permitted. * @param defaultVertexAttributes a default map of JGraph attributes to format vertices. <code> * null</code> is NOT permitted. * @param defaultEdgeAttributes a default map of JGraph attributes to format edges. <code>null * </code> is NOT permitted. * @param cellFactory a {@link CellFactory} to be used to create the JGraph cells. <code>null * </code> is NOT permitted. * @throws IllegalArgumentException */ public JGraphModelAdapter( Graph<V, E> jGraphTGraph, AttributeMap defaultVertexAttributes, AttributeMap defaultEdgeAttributes, CellFactory<V, E> cellFactory) { super(); if ((jGraphTGraph == null) || (defaultVertexAttributes == null) || (defaultEdgeAttributes == null) || (cellFactory == null)) { throw new IllegalArgumentException("null is NOT permitted"); } jtGraph = new ShieldedGraph(jGraphTGraph); setDefaultVertexAttributes(defaultVertexAttributes); setDefaultEdgeAttributes(defaultEdgeAttributes); this.cellFactory = cellFactory; if (jGraphTGraph instanceof ListenableGraph<?, ?>) { ListenableGraph<V, E> g = (ListenableGraph<V, E>) jGraphTGraph; g.addGraphListener(new JGraphTListener()); } for (Iterator<V> i = jGraphTGraph.vertexSet().iterator(); i.hasNext(); ) { handleJGraphTAddedVertex(i.next()); } for (Iterator<E> i = jGraphTGraph.edgeSet().iterator(); i.hasNext(); ) { handleJGraphTAddedEdge(i.next()); } this.addGraphModelListener(new JGraphListener()); }
// Desenha grafo teste public void grafotest() { // create a JGraphT graph ListenableGraph<String, Object> g = new ListenableDirectedGraph<String, Object>(DefaultEdge.class); // add some sample data (graph manipulated via JGraphT) g.addVertex("v1"); g.addVertex("v2"); g.addVertex("v3"); g.addVertex("v4"); g.addEdge("v1", "v2"); g.addEdge("v2", "v3"); g.addEdge("v3", "v1"); g.addEdge("v4", "v3"); GraphUtil gu = new GraphUtil(); contentPane.add(gu.getJGraph(g)); validate(); repaint(); }