scijava-common icon indicating copy to clipboard operation
scijava-common copied to clipboard

Interactive Command do not trigger cancel method when the user closes the window

Open NicoKiaru opened this issue 6 years ago • 0 comments

As descirbed in the title, it would be nice to have access to a method which is called when the user closes the window of an interactive command ( InteractiveCommand)

This minimal command example shows that the cancel method is never called:


import net.imagej.ImageJ;
import org.scijava.command.Command;
import org.scijava.command.InteractiveCommand;
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;

@Plugin(type = Command.class, menuPath = "Dummy")
public class DummyInteractiveCommand extends InteractiveCommand {

    @Parameter(min = "0", max = "255", style = "slider")
    double dummySlider;

    public void run() {
        System.out.println("Run called");
    }

    @Override
    public void cancel() {
        // Actually never called
        System.out.println("Cancel called");
    }
    

    public static void main(String... args) {
        final ImageJ ij = new ImageJ();
        ij.ui().showUI();
        // Launching dummy command
        ij.command().run(DummyInteractiveCommand.class,true);
    }

}

NicoKiaru avatar Jan 15 '20 15:01 NicoKiaru