I am not sure if this is a bug or a feature, but it caused me some head
scratching.

An imageListener registered with ImagePlus.addImageListener() does NOT get
called when an ImagePlus is closed unless an instance of an ImageJ has been
created. This is not the behaviour for imageOpened() and ImageUpdate()
which do get called.

=== SSC ===

package biz.dsuk.testimagejimpclose;

import ij.ImageJ;
import ij.ImageListener;
import ij.ImagePlus;
import ij.process.ByteProcessor;

public class TestImageJImpClose {

    public static void main(String[] args) {

        ImagePlus.addImageListener(new ImageListener() {
            @Override
            public void imageOpened(ImagePlus ip) {
                System.out.printf("Opened image%n");
            }

            @Override
            public void imageClosed(ImagePlus ip) {
                System.out.printf("Closed image%n");
            }

            @Override
            public void imageUpdated(ImagePlus ip) {
                System.out.printf("Updated image%n");
            }
        });

        /**
         * When an ImageJ instance is not created, our image listener is NOT
         * called when the image is closed. Run this and close the "Image"
window
         * by clicking on its close icon.
         */
        //t imageJ = new ImageJ();
        ByteProcessor bp = new ByteProcessor(256, 256);
        ImagePlus imp = new ImagePlus("Image", bp);
        imp.show();
    }
}

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

Reply via email to