Search code examples
javagraphvisualizationjung

How to programatically pan a VisualizationViewer with Jung (the java library)?


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


Solution

  • 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();
    }