Posted by
Michael P Ellis on
Dec 23, 2020; 12:59pm
URL: http://imagej.273.s1.nabble.com/Notification-of-File-Save-tp5024300.html
Is it possible to get notified or hook into when an image is saved?
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