/** * Draws a given graph with all its vertices and edges. * * @param graph the graph to be added to the existing graph. */ private void insertJGraphT(Graph<V, E> graph) { for (V vertex : graph.vertexSet()) { addJGraphTVertex(vertex); } for (E edge : graph.edgeSet()) { addJGraphTEdge(edge); } } }
/** * Draws a new vertex into the graph. * * @param vertex vertex to be added to the graph */ private void addJGraphTVertex(V vertex) { getModel().beginUpdate(); try { // create a new JGraphX vertex at position 0 mxICell cell = (mxICell) insertVertex(defaultParent, null, vertex, 0, 0, 0, 0); // update cell size so cell isn't "above" graph updateCellSize(cell); // Save reference between vertex and cell vertexToCellMap.put(vertex, cell); cellToVertexMap.put(cell, vertex); } finally { getModel().endUpdate(); } }
/** * Constructs and draws a new mxGraph from a JGraphT graph. Changes on the JGraphT graph will * not edit this mxGraph any further; use the constructor with the ListenableGraph parameter * instead or use this graph as a normal mxGraph. Throws an IllegalArgumentException if the * parameter is null. * * @param graph is a graph */ public JGraphXAdapter(Graph<V, E> graph) { super(); // Don't accept null as jgrapht graph if (graph == null) { throw new IllegalArgumentException(); } else { this.graphT = graph; } // generate the drawing insertJGraphT(graph); setAutoSizeCells(true); }
System.out.println(g.edgeSet().size()); JGraphXAdapter adapter = new JGraphXAdapter(g); layout.execute(adapter.getDefaultParent()); stylesheet.setDefaultVertexStyle(nodeStyle); adapter.setStylesheet(stylesheet);
getModel().beginUpdate(); mxICell cell = (mxICell) insertEdge(defaultParent, null, edge, sourceCell, targetCell); updateCellSize(cell); cellToEdgeMap.put(cell, edge); } finally { getModel().endUpdate();
new JGraphXAdapter<>(graph0); mxIGraphLayout layout = new mxCircleLayout(graphAdapter); layout.execute(graphAdapter.getDefaultParent()); dialog.add(new mxGraphComponent(graphAdapter)); dialog.pack();
@Override public void vertexRemoved(GraphVertexChangeEvent<V> e) { mxICell cell = vertexToCellMap.remove(e.getVertex()); removeCells(new Object[] { cell }); // remove vertex from hashmaps cellToVertexMap.remove(cell); vertexToCellMap.remove(e.getVertex()); // remove all edges that connected to the vertex ArrayList<E> removedEdges = new ArrayList<>(); // first, generate a list of all edges that have to be deleted // so we don't change the cellToEdgeMap.values by deleting while // iterating // we have to iterate over this because the graphT has already // deleted the vertex and edges so we can't query what the edges were for (E edge : cellToEdgeMap.values()) { if (!graphT.edgeSet().contains(edge)) { removedEdges.add(edge); } } // then delete all entries of the previously generated list for (E edge : removedEdges) { removeEdge(edge); } }
@Override public void edgeRemoved(GraphEdgeChangeEvent<V, E> e) { removeEdge(e.getEdge()); }
@Override public void edgeAdded(GraphEdgeChangeEvent<V, E> e) { addJGraphTEdge(e.getEdge()); }
@Override public void vertexAdded(GraphVertexChangeEvent<V> e) { addJGraphTVertex(e.getVertex()); }
/** * Removes a jgrapht edge and its visual representation from this graph completely. * * @param edge The edge that will be removed */ private void removeEdge(E edge) { mxICell cell = edgeToCellMap.remove(edge); removeCells(new Object[] { cell }); // remove edge from hashmaps cellToEdgeMap.remove(cell); edgeToCellMap.remove(edge); }
getModel().beginUpdate(); mxICell cell = (mxICell) insertEdge(defaultParent, null, edge, sourceCell, targetCell); updateCellSize(cell); cellToEdgeMap.put(cell, edge); } finally { getModel().endUpdate();
jgxAdapter = new JGraphXAdapter<String, DefaultEdge>(g); layout.execute(jgxAdapter.getDefaultParent());
@Override public void vertexRemoved(GraphVertexChangeEvent<V> e) { mxICell cell = vertexToCellMap.remove(e.getVertex()); removeCells(new Object[] { cell }); // remove vertex from hashmaps cellToVertexMap.remove(cell); vertexToCellMap.remove(e.getVertex()); // remove all edges that connected to the vertex ArrayList<E> removedEdges = new ArrayList<>(); // first, generate a list of all edges that have to be deleted // so we don't change the cellToEdgeMap.values by deleting while // iterating // we have to iterate over this because the graphT has already // deleted the vertex and edges so we can't query what the edges were for (E edge : cellToEdgeMap.values()) { if (!graphT.edgeSet().contains(edge)) { removedEdges.add(edge); } } // then delete all entries of the previously generated list for (E edge : removedEdges) { removeEdge(edge); } }
@Override public void edgeRemoved(GraphEdgeChangeEvent<V, E> e) { removeEdge(e.getEdge()); }
@Override public void edgeAdded(GraphEdgeChangeEvent<V, E> e) { addJGraphTEdge(e.getEdge()); }
@Override public void vertexAdded(GraphVertexChangeEvent<V> e) { addJGraphTVertex(e.getVertex()); }
/** * Removes a jgrapht edge and its visual representation from this graph completely. * * @param edge The edge that will be removed */ private void removeEdge(E edge) { mxICell cell = edgeToCellMap.remove(edge); removeCells(new Object[] { cell }); // remove edge from hashmaps cellToEdgeMap.remove(cell); edgeToCellMap.remove(edge); }
/** * Draws a new vertex into the graph. * * @param vertex vertex to be added to the graph */ private void addJGraphTVertex(V vertex) { getModel().beginUpdate(); try { // create a new JGraphX vertex at position 0 mxICell cell = (mxICell) insertVertex(defaultParent, null, vertex, 0, 0, 0, 0); // update cell size so cell isn't "above" graph updateCellSize(cell); // Save reference between vertex and cell vertexToCellMap.put(vertex, cell); cellToVertexMap.put(cell, vertex); } finally { getModel().endUpdate(); } }
/** * Draws a given graph with all its vertices and edges. * * @param graph the graph to be added to the existing graph. */ private void insertJGraphT(Graph<V, E> graph) { for (V vertex : graph.vertexSet()) { addJGraphTVertex(vertex); } for (E edge : graph.edgeSet()) { addJGraphTEdge(edge); } } }