Jung: prevent user from moving a vertex outside the Visualization size?

51 Views Asked by At

When in picking mode, I want to limit the user from dragging a vertex outside of the defined layout bounds. I've set the ISOMLayout, VisualizationModel, and the VisualizationViewer to be the same size. But if I zoom out (I'm using a CrossoverScalingControl) I can drag vertices way outside the layout/vv's bounds. This results in the scrollbars of my GraphZoomScrollPane not working as expected: there can be vertices floating out there that you can't scroll to and you have to zoom out to see them.

Surely there's a way to lock the user into a certain boundary?

    Dimension preferredDimension = new Dimension(1200, 800);

    Layout<CNode,CEdge> layout = new ISOMLayout<>(graph);
    layout.setSize(preferredDimension);

    VisualizationModel<CNode, CEdge> visualizationModel = new DefaultVisualizationModel<>(layout, preferredDimension);

    vv = new VisualizationViewer<>(visualizationModel, preferredDimension);
1

There are 1 best solutions below

0
Joshua O'Madadhain On

If you want to set a boundary outside which you can't manually move a vertex, you can do that in your code (specifically, in the part that responds to you dragging a selected vertex; you can specify limits there on how far out you can drag a vertex). It's not JUNG's responsibility to prevent you from setting a vertex location to something that the Layout wouldn't use; as far as the JUNG is concerned, you can do that if you want to. :)