我正在编写一个绘制有限状态系统的 Eclipse 插件。由于它可能很大,我想附上一些现有的图形布局算法(例如分层布局、基于力的布局……),它们会自动优化系统可视化。
有没有办法集成我正在编写的插件(使用 GEF 编写),以便生成的编辑部分可以按照一些常见的图形布局算法放置在编辑器区域?
我发现了这篇有趣的文章,但它没有优化编辑部分的可视化,而是专注于绘制一个全新的图形。
到目前为止,我正在做的是添加以下代码(基于 Zest 1)
private static void createNewGraph(String autName) {
Shell tmpShell = new Shell();
currGraph = new Graph(tmpShell, SWT.NONE);
mapStateAndNodes = new HashMap<State, GraphNode>();
}
private static void addGraphNode(State currState)
{
GraphNode newNode = new GraphNode(currGraph, SWT.NONE, currState.getName());
mapStateAndNodes.put(currState, newNode);
}
private static void addGraphConnection(Transition currTrans)
{
GraphNode source = mapStateAndNodes.get(currTrans.getOrigState());
GraphNode dest = mapStateAndNodes.get(currTrans.getDestState());
GraphConnection newConn = new GraphConnection(currGraph, SWT.NONE, source, dest);
}
private static void completeGraph()
{
currGraph.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);
}
在构建模型时,我还调用createNewGraph(...)
、addGraphNode(...)
和。问题是:在那之后意味着它应该应用算法并将对象放置在“正确”的顺序中。此时(正如某些读者所建议的那样),可以通过一种方法提取计算出的坐标。不幸的是,在设置布局并应用它之后,所有状态都作为它们的位置。我还发现了这条评论:addGraphConnection(...)
completeGraph(...)
currGraph.setLayoutAlgorithm(..., true)
true
GraphNode.getLocation()
Point(0,0)
/**
* Runs the layout on this graph. It uses the reveal listener to run the
* layout only if the view is visible. Otherwise it will be deferred until
* after the view is available.
*/
public void applyLayout() {
...
}
在org.eclipse.zest.core.widgets.Graph
来源:-[对我来说,我似乎无法使用热情图形库来完成这项工作。我错了吗?有其他选择吗?
任何帮助,将不胜感激 :)