Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is how to popup a menu after right-clicking on a node in JUNG2 and later choose to center to this node:</p> <pre><code>graphMouse.add(new MyPopupGraphMousePlugin()); /** * a GraphMousePlugin that offers popup * menu support */ protected class MyPopupGraphMousePlugin extends AbstractPopupGraphMousePlugin implements MouseListener { public MyPopupGraphMousePlugin() { this(MouseEvent.BUTTON3_MASK); } public MyPopupGraphMousePlugin(int modifiers) { super(modifiers); } /** * If this event is over a node, pop up a menu to * allow the user to center view to the node * * @param e */ protected void handlePopup(MouseEvent e) { final VisualizationViewer&lt;Node,Link&gt; vv = (VisualizationViewer&lt;Node,Link&gt;)e.getSource(); final Point2D p = e.getPoint(); GraphElementAccessor&lt;Node,Link&gt; pickSupport = vv.getPickSupport(); if(pickSupport != null) { final Node station = pickSupport.getVertex(vv.getGraphLayout(), p.getX(), p.getY()); if(station != null) { JPopupMenu popup = new JPopupMenu(); String center = "Center to Node"; popup.add(new AbstractAction("&lt;html&gt;&lt;center&gt;" + center) { public void actionPerformed(ActionEvent e) { MutableTransformer view = vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW); MutableTransformer layout = vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT); Point2D ctr = vv.getCenter(); Point2D pnt = view.inverseTransform(ctr); double scale = vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW).getScale(); double deltaX = (ctr.getX() - p.getX())*1/scale; double deltaY = (ctr.getY() - p.getY())*1/scale; Point2D delta = new Point2D.Double(deltaX, deltaY); layout.translate(deltaX, deltaY); } }); popup.show(vv, e.getX(), e.getY()); } else { } } } } </code></pre> <p><strong>Edited:</strong> Finally! the correct node-to-center-view with scale factor calculation...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload