I am using a JGraphModelAdapter to convert a Jgraph to a JGrapht. Its working fine and my vertices are displayed on the gui as they should.
I have been given some base code to work with when editing the positions of the vertices on the GUI. (Seen Below)
private void positionVertices() {
for (MapLocation aVertex : this.graphContents.vertexSet()) {
double xPostion = (?);
double yPostion = (?);
this.positionAVertex(aVertex, xPostion, yPostion);
}
}
private void positionAVertex(Object vertex, double x, double y) {
DefaultGraphCell vertexDisplayCell = this.theModelAdapter
.getVertexCell(vertex);
AttributeMap cellAttributes = vertexDisplayCell.getAttributes();
Rectangle2D bounds = GraphConstants.getBounds(cellAttributes);
Rectangle2D newBounds = new Rectangle2D.Double(x, y, bounds.getWidth(),
bounds.getHeight());
GraphConstants.setBounds(cellAttributes, newBounds);
HashMap<DefaultGraphCell, AttributeMap> cellAttributeMap = new HashMap<>();
cellAttributeMap.put(vertexDisplayCell, cellAttributes);
this.theModelAdapter.edit(cellAttributeMap, null, null, null);
}
Each MapLocation(Vertex) object represents a Zip code of a place in America, it has access to an accurate latitude and longitude getter. Using them I should be able to position the vertices at proportionally realistic places on my gui. However I am having difficulty determining what formula (Denoted by (?)) would work well in this situation.
The frame is set to MAXIMIZED_BOTH but must work on any monitor size.
Thanks for any assistance in advance.