我正在编写一个绘制有限状态系统的 eclipse 插件。由于它可能很大,我想附加一些现有的图形布局算法(例如分层布局、基于力的布局……)来自动优化系统可视化。
有没有办法集成我正在编写的插件(使用 GEF 编写),以便生成的编辑部分可以按照一些常见的图形布局算法放置在编辑器区域上?
我找到了这个有趣的文章 http://www.vogella.de/articles/EclipseZest/article.html#zest_overview但它不是优化编辑部分的可视化,而是专注于绘制全新的图形。
到目前为止我正在做的是添加以下代码(基于 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(...)
and completeGraph(...)
。问题是:之后currGraph.setLayoutAlgorithm(..., true)
that 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() {
...
}
in org.eclipse.zest.core.widgets.Graph
来源:-[对我来说,我似乎无法使用 zest Graph 库来完成这项工作。我错了吗?还有其他选择吗?
任何帮助,将不胜感激 :)