Login  Register

Re: Notification of File Save

Posted by Wayne Rasband-2 on Dec 25, 2020; 8:41pm
URL: http://imagej.273.s1.nabble.com/Notification-of-File-Save-tp5024300p5024314.html

> On Dec 23, 2020, at 7:59 AM, Michael Ellis <[hidden email]> wrote:
>
> Is it possible to get notified or hook into when an image is saved?

The ImageJ 1.53h17 daily build adds an imageSaved() method to the ImageListener interface. This method is defined using the "default” keyword (added in Java 8), so ImageJ now requires Java 8 or later. The Event Listener (Plugins>Utilities>Monitor Events) now reports image saved events.

-wayne

> The ImageListener interface allows notifications only for Open/Close and Updated.
>
> My reason for wanting this extra functionality is that I wish to save a thumbnail JPEG image whenever an image is saved.
>
> My current strategy is for my plugin to cache a BufferedImage when I receive an ImageListener Updated event through and then have Java File System watch service notice whenever a file is created or modified in a watched directory, recall the cached BufferedImage and write the thumbnail then. It's an inefficient strategy.
>
> If there is an existing means of doing this then I would be grateful to learn of it!
>
> If not, then, as I understand it, the "ImagePlus:: protected void notifyListeners(final int id)" is only called from ImagePlus and the derivative CompositeImage.
>
> Because notifyListeners() is also protected so not callable from the code that saves images such as in FileSaver.java
>
> Is there anyone else who would like to see a new interface added:
> public interface ImageListenerNew {
> public notifyListeners(final String id);
> }
>
> Which could be used for some additional notifications (such as Save, and perhaps Closing - gets called just before the images is closed) and potentially could be used for user-extensible events (say with a reverse domain string with your own event name as the string ID parameter)
>
> My thinking is that some standard IDs could be added for the existing "OPENED", "CLOSED", "UPDATED" that get called in addition to the existing notifyListeners(final int id)" so backward compatibility is maintained for existing plugins but PluginDeveloppers could choose the old ImageListener or the ImageListenerNew interface if they needed the extra functionality.
>
> Thanking anyone in advance and seasons greetings to you all
>
> -- Michael Ellis

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