本文介绍了如何以编程方式平移Jung(Java库)的VisualizationViewer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
经过大量调查后,我无法找到一个方便的答案来解决以下问题:如何以编程方式在Jung上平移VisualizationViewer?我有一个带有图形顶点列表的图形用户界面,我希望双击列表中的一个项目(即一个节点描述),为我点击的节点执行VisualizationViewer的居中动作。
如何编写这样的行为?它似乎很简单,但我发现没有方便的答案。
如果有人可以帮忙,谢谢!
njames
解决方案
public void centerViewsOnVertex(SynsetVertex v){
//以下位置有感觉在布局的空间
Point2D v_location = layout.transform(v);
Point2D vv1_center_location = vv1.getRenderContext()
.getMultiLayerTransformer()
.inverseTransform(Layer.LAYOUT,vv1.getCenter());
double scale = vv1.getRenderContext()。getMultiLayerTransformer()。getTransformer(Layer.VIEW).getScale();
vv1.getRenderContext()。getMultiLayerTransformer()。getTransformer(Layer.LAYOUT).translate(
- (v_location.getX() - vv1_center_location.getX())* 1
/ scale,
- (v_location.getY() - vv1_center_location.getY())* 1
/ scale);
refreshViews();
}
After a lot a investigations, I don't achieve to find a convenient answer to the following question: how to programatically pan a VisualizationViewer with Jung?
I have a GUI with the list of the vertices of my graph, and I want that a double click on one item of the list (i.e. a node description) perform a "centering action" of my VisualizationViewer for the clicked node.How to code such a behavior? it seems simple but I found no convenient answer.
If someone could help, thanks!
njames
解决方案
public void centerViewsOnVertex(SynsetVertex v) {
//the following location have sense in the space of the layout
Point2D v_location = layout.transform(v);
Point2D vv1_center_location = vv1.getRenderContext()
.getMultiLayerTransformer()
.inverseTransform(Layer.LAYOUT, vv1.getCenter());
double scale = vv1.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW).getScale();
vv1.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).translate(
-(v_location.getX() - vv1_center_location.getX()) * 1
/ scale,
-(v_location.getY() - vv1_center_location.getY()) * 1
/ scale);
refreshViews();
}
这篇关于如何以编程方式平移Jung(Java库)的VisualizationViewer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!