JUNG,更改可视化查看器上的图形参考

发布于 2024-12-18 06:48:14 字数 970 浏览 1 评论 0原文

我们用 jung 开发了一个小型图形编辑器,您可以在其中用鼠标绘制图形/网络。我们使用 VisualizationViewer 作为我们绘图的面板。 VisualizationViewer 持有它必须通过其包含的 GraphLayout 显示的图形。我们还有一个保存函数,可以将图形保存到文本文件中:

public void saveGraph(){
    Graph<V, E> g = visualizationviewer.getGraphLayout.getGraph();
    // save g into text file
}

我现在已经编写了一个类,它使用一些算法生成一个新的图形对象:

public Graph<V, E> generateGraph(){
    Graph<V, E> g = new DirectedSparseGraph<V, E>();
    // do some algorithms on g
    return g
}

如果我现在想通过以下方式显示生成的图形:

...
visualisationviewer.getGraphLayout.setGraph(generateGraph());
...

新图形完美显示并且人们还可以进一步利用它。

但保存函数(以及所有其他想要使用 VisualizationViewer 的底层 Graph 对象的函数)现在不再正常工作。要么仅识别一个节点,要么不识别任何节点(这会导致 NullPointerException)。每次我们想要检索底层的图数据结构时,我们都会使用:

visualizationviewer.getGraphLayout.getGraph();

我这里缺少什么吗?或者框架内是否存在尚未修复的已知错误?光学部分工作完美,而以编程方式检索底层对象则不然,这似乎很奇怪。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笨笨の傻瓜 2024-12-25 06:48:14

问题在于,您通过两个步骤添加顶点,首先将它们添加到 arrayList,然后从该列表添加到图形。由于您的程序动态工作以避免空指针异常,因此您必须添加如下节点:

Node node;           
g.addVertex(node = nodefactory.create());
nodes.add(node);

这样您仍然可以使用 arrayList(nodes) 但避免错误!

第二个错误是可视化查看器无法识别新图中的节点,因此您必须比较节点的名称并从旧节点获取位置才能正确,

我认为这根本没有帮助..
请记住直接添加 PDEEdgesNodes 而不是通过 ArrayList ;-)

The problem is that you added the vertices in two steps by adding them to an arrayList first and adding to the graph from that list. Since your program works dynamically in order to avoid null-pointer exceptions you have to add nodes like this:

Node node;           
g.addVertex(node = nodefactory.create());
nodes.add(node);

This way you're still able to use your arrayList(nodes) but avoid errors!

The second error is that the visualization viewer does not recognize the nodes from the new graph therefore you have to compare the names of the nodes and take the position from the old node in order to get it right

I don't think that's helpful at all..
Just keep in mind to add PDEEdges and Nodes directly and not via ArrayList ;-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文