Select molecule from MViewPane with mouse right button

User 818520b6b8

15-12-2005 15:36:01

Hi,





I'd like to be able to select a molecule from MViewPane with the mouse right button.





I've a MViewPane showing multiple molecules, the problem is that I can be focused on molecule 2 but right click over molecule 23, then the popup menu displayed when I click the right button is referencing molecule 2 instead of 23.





I'd like the right click to focus on the molecule the pointer is over at that moment, and then show the popup menu.





Is that possible?





Thanks.

ChemAxon 7c2d26e5cf

16-12-2005 22:30:35

To avoid displaying of the popup menu, I suggest you to set the popup menu to disabled.


You can do it by the usage of the MarvinPane.setPopupMenusEnabled() method:
Quote:
viewPane.setPopupMenusEnabled(false);
By the way, the following Marvin Beans example demonstrates the usage of this method:


http://www.chemaxon.com/marvin/examples/view-popup/MViewPopupExample.java.txt

User 818520b6b8

19-12-2005 07:48:21

Yes, I saw your sample.





But I'm not sure if you understood what I meant.





I want to select the molecule from MViewPane with the right mouse button. The same that happens when you click over a molecule with the left mouse button, but with the right one.





Is it possible?

ChemAxon 7c2d26e5cf

19-12-2005 20:44:06

Yes. See the following code:
Quote:
private void selectCellByEvent(MouseEvent ev) {


JComponent comp = (JComponent)ev.getSource();


int cellindex = viewPane.getAbsoluteCellIndex(comp);


if (cellindex == -1) {


return;


}


viewPane.setSelectedIndex(cellindex);


}





/** Release a mouse button. */


public void mouseReleased(MouseEvent ev) {


int modifier = ev.getModifiers();


// if it comes from a right mouse button


if(modifier == MouseEvent.BUTTON3_MASK) {


selectCellByEvent(ev);


}


}





I have attached the whole code. Actually, it is the modification of the original MViewPopupExample.

User 818520b6b8

20-12-2005 08:21:29

Thank you very much Tamas !!!!!