Hi Tomnelson, thanks for the reply, but the demo only shows how to label the node/edges, what if I want to add in some custom events, like writing the edge information to a text file when I double click the edge?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There are two types of behaviors you can change: 1) which meta keys must be pressed before the PickingGraphMousePlugin detects the click and 2) the code that needs to be executed when a vertex/edge is picked (clicked, selected).
You can control 1) by passing the mouse mask for the meta keys in the constructor of PickingGraphMousePlugin:
PickingGraphMousePlugin gm = new PickingGraphMousePlugin(InputEvent.BUTTON1_MASK | InputEvent.CTRL_MASK);
This creates a graphmouse that only respond to clicks if the ctrl key is pressed.
You can control 2) by adding an ItemListener to the PickedVertexState or PickedEdgeState of the BasicVisualizationServer (or any subclass of course):
VisualizationViewer<MyVertex, MyEdge> vv = new VisualizationViewer<MyVertex, MyEdge>(layout);
vv.getPickedVertexState().addItemListener(new MyVertexListener());
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
How do I add an edge or node event, say popping out a dialog box when I click on the edge/node?
GraphEditorDemo does this. The source code is with the downloads and in the CVS repository.
Hi Tomnelson, thanks for the reply, but the demo only shows how to label the node/edges, what if I want to add in some custom events, like writing the edge information to a text file when I double click the edge?
Oh I have found the PickingGraphMousePlugin that can do the job
But it seems to have a predefined set of behaviors, is there a way to modify these behaviors without changing the source code?
There are two types of behaviors you can change: 1) which meta keys must be pressed before the PickingGraphMousePlugin detects the click and 2) the code that needs to be executed when a vertex/edge is picked (clicked, selected).
You can control 1) by passing the mouse mask for the meta keys in the constructor of PickingGraphMousePlugin:
This creates a graphmouse that only respond to clicks if the ctrl key is pressed.
You can control 2) by adding an ItemListener to the PickedVertexState or PickedEdgeState of the BasicVisualizationServer (or any subclass of course):