Add listener for double click on nodes and double click on edges. Cytoscape 2.8.3

608 views
Skip to first unread message

Juanjo

unread,
Oct 25, 2012, 1:05:16 PM10/25/12
to cytoscap...@googlegroups.com
Hi guys,

I'm trying to two listener on my network view. One that preforms an action when the user double-clicks on a node and another that preforms an action when the user double-clicks on an edge. I have been looking about the different listener on the Cytoscape API but I'm still really confused and I'm sure that sure be an easy way to do it. Any help?

Thanks in advance!

Peng-Liang Wang

unread,
Nov 8, 2012, 6:31:49 PM11/8/12
to cytoscap...@googlegroups.com
In Cytosape 2.x, double-click is not supported in API level, but right-click is.

Peng
> --
> You received this message because you are subscribed to the Google Groups
> "cytoscape-discuss" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/cytoscape-discuss/-/qTcekLJLZZQJ.
> To post to this group, send email to cytoscap...@googlegroups.com.
> To unsubscribe from this group, send email to
> cytoscape-disc...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/cytoscape-discuss?hl=en.

Tim Hull

unread,
Nov 8, 2012, 7:23:51 PM11/8/12
to cytoscap...@googlegroups.com
The one way to do this in 2.x is to manually add a MouseListener to the network view's canvas:

CyNetworkView view=Cytoscape.getCurrentNetworkView();
((DGraphView) view).getCanvas().addMouseListener(this);

In the MouseListener, you would have code to get the CyNode they clicked on (if any) - something like this:        


public void mouseClicked(MouseEvent e) {
   CyNetworkView view=Cytoscape.getCurrentNetworkView();
   NodeView nv =((DGraphView) view).getPickedNodeView(e.getPoint ());
   if(nv != null) {
   CyNode node =(CyNode) nv.getNode();
   // do whatever you want with the node
   }
}

If you want to do this on edges,  just substitute EdgeView for NodeView. In 3.0 (in beta currently), you can associate a task with the double-click action directly, avoiding the need for low-level code like MouseListener...

Tim
Reply all
Reply to author
Forward
0 new messages