I have created an application with the help of jgraph for the visualization. I have couple of problems regarding this.
1: I need to change the names of Vertices according to an attribute of the Vertex object. When i run the application with the default settings, the names of the vertices are printed as Vertex@c8191c (Changes based on the vertex). I want to change this name to an attribute value of the vertex.
2: This is the most critical one. The number of vertices generated is not static. Number depends on various other factors of the application and can change every time the application runs. When i run this application with the default setting the nodes overlap and only one is shown at first place. I need to distribute the nodes randomly within the jgraph.
Can someone please help me with these two problems. If you need further information please mention. Following is my code to visualize the graph.
public void randomizeLocations(JGraph jgraph) {
System.out.println("Visualization 1");
GraphLayoutCache cache = jgraph.getGraphLayoutCache();
System.out.println("Visualization 2");
Random r = new Random();
for (Object item : jgraph.getRoots()) {
System.out.println("Visualization 3");
GraphCell cell = (GraphCell) item;
CellView view = cache.getMapping(cell, true);
Rectangle2D bounds = view.getBounds();
System.out.println("next double"+r.nextDouble()*400);
bounds.setRect(r.nextDouble() * 400, r.nextDouble() * 5,
bounds.getWidth(), bounds.getHeight());
}
System.out.println("Visualization 4");
cache.reload();
System.out.println("Visualization 5");
jgraph.repaint();
System.out.println("Visualization 6");
}
Thank you in advance.