Add listener to ResultsTable

Hi to all,
I would ask if does it exist the possibility to add a listener (mouse/key) to the ResultsTable?
and if not, if someone more able than me has some suggestion about how to implement it.
Thank you very much,
Emanuele Martini

Hi @emartini

I did something like this for TrackMate a while ago. Check this snippet:

Best
jy

3 Likes

thank you @tinevez I will try in next days and let you know!
have a nice day,
emartini

Hello @tinevez,
I am trying with this code :


import java.awt.Window;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import ij.IJ;
import ij.ImageJ;
import ij.ImagePlus;
import ij.WindowManager;
import ij.plugin.PlugIn;
import ij.text.TextPanel;
import ij.text.TextWindow;

'''
/**
 * ResultsTable_openOnClick
 *
 * Add a mouse listener to results table that opens the path in last column of the ResultsTable double click
 *
 * @author Emanuele Martini
 */
public class ResultsTable_openOnClick implements PlugIn {
    @Override
    public void run(String arg) {    
        Window window_1 = WindowManager.getWindow( "Results" );
        
        if (window_1!=null){
            TextWindow textwindow = (TextWindow) window_1;
        final TextPanel textPanel = textwindow.getTextPanel();

        textPanel.addMouseListener( new MouseAdapter()
        {
            @Override
            public void mouseClicked( final MouseEvent e )
            {

                if (e.getClickCount() == 2 && !e.isConsumed()){
                int line = textPanel.getSelectionStart();
                String selected_test=textPanel.getLine(line);
                
                String[] results_columns = selected_test.split("\\t+");
                
                String open_path= results_columns[results_columns.length-1];
                ImagePlus imp = IJ.openImage(open_path);
                imp.show();
                e.consume();}
                
            }
            
        
    });
    }

    }

I debugged it in Eclipse and it works fine when I double clicked on a row it opens the path present in the last column of a Results Table.

But I have a problem when I try it in Fiji.
I tried :

  1. Export as JAR and add to plugins folder (I did it usually and it works, so I think to did it in the proper manner) and it is not present in the plugins subfolder.

    so then I tried

  2. Try script editor directly from Fiji, launched it and it threw up this error :

     Started ResultsTable_openOnClic.java at Fri Feb 12 11:03:48 CET 2016
     Compiling 1 file in /var/folders/9k/wjdz_6c95_l98w49m_qp48pr0000gq/T/java3872476629000438021
     /var/folders/9k/wjdz_6c95_l98w49m_qp48pr0000gq/T/java3872476629000438021/src/main/java/ResultsTable_openOnClic.java:1: cannot access java.awt.Window
     bad class file: ZipFileIndexFileObject[/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/lib/ct.sym(META-INF/sym/rt.jar/java/awt/Window.class)]
     class file has wrong version 52.0, should be 50.0
     Please remove or make sure it appears in the correct subdirectory of the classpath.
     import java.awt.Window; 
    

Someone has some idea of what I am doing wrong?
Thank you very much,
have a nice day
Emanuele Martini

Hi @emartini
This seems like another problem.
I distribute and compile my plugins with maven and drop them into the Fiji plugin. Since it works well and the other methods are error prone, I don’t look for another method.

Yes I use maven and Eclipse jar too, I am not understanding why with this plugin doesn’t work.
I will retry in next hours/days.
Thank you very much,
emanuele m.

Ah ok!
Alors for the first error, plugins do not appear automatically in the Plugins menu in ImageJ1. You have to add a plugins.config file to the project. Like this one:

For the second one, it seems like you are using different versions of Java for Fiji and to compile your stuff. But on this, I do not know much.

Yes, I exported many plugins with this method and plugins.config and pom.xml and so on … and they all work :slightly_smiling:

I am having problem only with that and I think that it is a java problem, maybe similar to this one
http://fiji.sc/bugzilla/show_bug.cgi?id=1074

Thank you,
I will try and let know if I will find some solution.

update

I tried to launch Fiji with another version of Java : Java 1.6 instead of Java 1.8.
And installing it using “script editor->compile and run->Refresh Javas” it appears in the plugins menu and it works.
So, I am pretty sure that it is a java compatibility problem.
Have a nice day,
Emanuele