Mouse events with MViewPane

User 8250a1884c

15-11-2010 17:04:03

Hi,


I am trying to set up a Java application using JChem / MarvinBeans 5.3.7 that reads molecules from an SDF and displays them in a MViewPane.


So far, everything works fine, but I encounter a problem when I want to add customized MouseListeners to the MViewPane as described in the example "CustomMenuExample.java" or the MViewPane API.


mpane = new MViewPane();
mpane.setPopupMenusEnabled(false);   
tableSupport = mpane.getTableSupport();

int molcount = 0;
for(Molecule m : mols) {
  mpane.setM(molcount, m);
  molcount++;
 }

for(int i=0; i < mpane.getVisibleCellCount(); i++) {
    JComponent comp = mpane.getVisibleCellComponent(i);
    comp.addMouseListener(new MviewTableMouseListener());
}
       

When setting the molecules with the mpane.setM() method as in the code listing above, the mouse events are triggered correctly.


However, if I use the TableSupport.start() method to fill the MViewPane with molecules, there is no response from the mouse listeners:


mpane = new MViewPane();
mpane.setPopupMenusEnabled(false);   
tableSupport = mpane.getTableSupport();

tableSupport.start(new ArrayMDocSource(mols), "mols");

for(int i=0;i<mpane.getVisibleCellCount();i++) {
    JComponent comp = mpane.getVisibleCellComponent(i);
    comp.addMouseListener(new MviewTableMouseListener());
}

How can I trigger mouse events when clicking on a MViewPane table that has been filled with the tableSupport.start() method?


I prefer this way of loading the molecules because I would like to
display the molecules in a spreadsheet-like table (using the table options menu provided by TableSupport.makeTableMenu()) which doesn't seem to
work properly for the first code example. Or would you recommend another way of displaying such a molecule structure/property spreadsheet?


 


Any hints are much appreciated.


Regards


Lisa

ChemAxon 7c2d26e5cf

16-11-2010 16:29:09

We are going to check this issue.

ChemAxon 7c2d26e5cf

11-03-2011 10:38:01

Hi Lisa


As I have already mentioned in our private email discussion, MViewPane.getVisibleCellComponent(int) is designed for grid view. It has no sence in spreadsheet view since it is based on JTable model that does not include permanent molecule canvas objects. Instead of that, it operates with cell editor/render components.


We can implement a solution where MouseEvents can be posted to custom listeners too when the molecule cell is edited (molecule canvas is active).


But we do not know exactly what you would like to do.


I think that the typical usage of custom mouse listener where the user would like to substitute the default popup menu of MarvinView to a new one. In this case, the role of the mouse listener to catch the right moment (right mouse click) to show the custom popup menu.


If this is what you like, we are not sure that providing mouse listener to molecule canvas is necessary.


In this case, an API that subsitutes/customizes the default popup menu can be more useful.


Which solution would you prefer?