How do I listen to changes in vertex selection in Jung 2?
•
Java
How do I listen to changes in vertex selection in Jung 2? I've been trying to use propertychangelister and changelistener
Solution
Here http://kahdev.wordpress.com/2010/02/20/detecting-selection-of-vertices-in-jung/ Well explained
Just add a listener on the pickedvertexstate of the visualizationviewer:
Graph<Integer,String> basis = new SparseMultigraph<Integer,String>(); final Layout<Integer,String> layout = new CircleLayout<Integer,String>( basis); layout.setSize(new Dimension(300,300)); VisualizationViewer<Integer,String> vv = new VisualizationViewer<Integer,String>( layout); final PickedState<Integer> pickedState = vv.getPickedVertexState(); // Attach the listener that will print when the vertices selection changes. pickedState.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { Object subject = e.getItem(); // The graph uses Integers for vertices. if (subject instanceof Integer) { Integer vertex = (Integer) subject; if (pickedState.isPicked(vertex)) { System.out.println("Vertex " + vertex + " is Now selected"); } else { System.out.println("Vertex " + vertex + " no longer selected"); } } } });
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码