我正在使用 JGraphModelAdapter 将 Jgraph 转换为 JGrapht。它工作正常,我的顶点应该显示在 gui 上。
在 GUI 上编辑顶点的位置时,我得到了一些基本代码可以使用。(见下文)
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);
}
每个 MapLocation(Vertex) 对象代表美国一个地方的邮政编码,它可以访问准确的纬度和经度获取器。使用它们,我应该能够将顶点定位在我的 gui 上成比例的真实位置。但是,我很难确定哪种公式(用(?)表示)在这种情况下会很好地工作。
框架设置为 MAXIMIZED_BOTH,但必须适用于任何显示器尺寸。
感谢您提前提供任何帮助。