We have developed a little graph editor with jung where you can draw graph/networks with your mouse. We use the VisualizationViewer as the panel we draw on. The VisualizationViewer holds the graph it has to display via its containing GraphLayout. We also have a save function which saves the graph into a text file:
public void saveGraph(){
Graph<V, E> g = visualizationviewer.getGraphLayout.getGraph();
// save g into text file
}
I have now written a class that generates me a new graph object using some algorithms:
public Graph<V, E> generateGraph(){
Graph<V, E> g = new DirectedSparseGraph<V, E>();
// do some algorithms on g
return g
}
If I now want to display the generated graph via:
...
visualisationviewer.getGraphLayout.setGraph(generateGraph());
...
The new Graph is perfectly displayed and one can draw on it even further.
But the saving functions (and all other functions that want to use the underlying Graph object of the VisualizationViewer) are now not working properly anymore. Either only one node is recognized or no nodes (which results in a NullPointerException). Everytime we want to retrieve the underlying Graph data structure we use:
visualizationviewer.getGraphLayout.getGraph();
Am I something missing here? Or is there a known bug within the framework that hasn't been fixed? It seems weird that the optical part is working perfectly while the programmatically retrieving of the underlying objects is not.