imagej / imagej2

Open scientific N-dimensional image processing :microscope: :sparkler:
https://imagej.net/
BSD 2-Clause "Simplified" License
1.2k stars 337 forks source link

RoiListener CREATED not firing #169

Closed MaxLeiter closed 7 years ago

MaxLeiter commented 7 years ago

code example: this is also present in the example EventListener plugin: https://raw.githubusercontent.com/imagej/ImageJA/ac7c554675133443b9e3d3883c5d727049c9d857/src/main/java/ij/plugin/EventListener.java

MODIFIED is fired correctly, however CREATED never is. Apologies if this is my mistake.

import ij.IJ;
import ij.ImagePlus;
import ij.gui.Roi;
import ij.gui.RoiListener;
import ij.plugin.PlugIn;

public class Event_Listener implements PlugIn, RoiListener {

    public void run(String arg) {
        if (IJ.versionLessThan("1.43o")) return;
        Roi.addRoiListener(this);
        IJ.log("Program started");
    }

    @Override
    public void roiModified(ImagePlus imp, int id) {
        System.out.println(id);
        switch(id) {
        case RoiListener.CREATED:
            System.out.println("ROI Created");
            break;
        case RoiListener.MODIFIED:
            System.out.println("ROI Modified");
            break;
        }
    }

}
ctrueden commented 7 years ago

Thanks for the report, @MaxLeiter. /cc @rasband since this is a question about ImageJ 1.x.

MaxLeiter commented 7 years ago

I believe the issue is here: https://github.com/imagej/ImageJA/blob/f940bc2910de7339589ef102309781f74a30db27/src/main/java/ij/gui/Roi.java

The constructors should probably notifyListeners(RoiListener.CREATED)

rasband commented 7 years ago

This bug is fixed in the latest ImageJ daily build (1.51q5). View the changes at https://github.com/imagej/imagej1/commits.