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.
This is the code that work
double xPostion = (124 - Math.abs(aVertex.getLongitude()));
xPostion = xPostion / 57;
xPostion = xPostion * this.myWidth;
double yPostion = 49 - aVertex.getLatitude();
yPostion = yPostion / 25;
yPostion = yPostion * this.myHeight ;
57 is difference in longitude from eastern most continental US and western most.
25 is the difference in latitude from the norther most continental US and the southern most
124 is the longitude of the western most continental US.
49 is the latitude of the norther most continental US.