Hi all,
I would like to perform an action in my plugin when an image in ImageJ is renamed. I found the ImageListener interface which, however, triggers events only on opening, closing and updating images. Also the CommandListener interface does not help as my plugin should be notified after the renaming has taken place, not before as it happens if I implement the CommandListener interface. Does anyone have a suggestion how a plugin can react on a renaming action of an image taking place in the GUI? Thanks in advance, Birgit Moeller ------------------------------------------------------------------------ Dr. rer. nat. Birgit Moeller Pattern Recognition & Bioinformatics Institute of Computer Science, Faculty of Natural Sciences III Martin Luther University Halle-Wittenberg e-mail: [hidden email] www: http://www.informatik.uni-halle.de/moeller/ ------------------------------------------------------------------------ -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Birgit,
> Does anyone have a suggestion how a plugin can react on a renaming > action of an image taking place in the GUI? Looking at the source code of the JDK, it appears that the java.awt.Frame class fires a property change event called "title" whenever its setTitle(String) method is called. So you may be able to detect the change by adding a PropertyChangeListener to the ImagePlus's ImageWindow. Alternately, the "big hammer" solution to this sort of problem, which we use in ImageJ2, is bytecode manipulation. We use the Javassist library [1] to inject "seams" into methods. See: https://github.com/imagej/imagej/blob/v2.0.0-beta6/core/legacy/src/main/java/imagej/legacy/LegacyInjector.java https://github.com/imagej/imagej/blob/v2.0.0-beta6/core/legacy/src/main/java/imagej/legacy/CodeHacker.java https://github.com/imagej/imagej/tree/v2.0.0-beta6/core/legacy/src/main/java/imagej/legacy/patches Regards, Curtis [1] http://www.javassist.org/ On Mon, Mar 18, 2013 at 12:58 PM, Birgit Möller < [hidden email]> wrote: > Hi all, > I would like to perform an action in my plugin when an image in ImageJ is > renamed. I found the ImageListener interface which, however, triggers > events only on opening, closing and updating images. Also the > CommandListener interface does not help as my plugin should be notified > after the renaming has taken place, not before as it happens if I implement > the CommandListener interface. Does anyone have a suggestion how a plugin > can react on a renaming action of an image taking place in the GUI? > Thanks in advance, > > Birgit Moeller > > ------------------------------------------------------------------------ > Dr. rer. nat. Birgit Moeller > Pattern Recognition & Bioinformatics > Institute of Computer Science, Faculty of Natural Sciences III > Martin Luther University Halle-Wittenberg > e-mail: [hidden email] > www: http://www.informatik.uni-halle.de/moeller/ > ------------------------------------------------------------------------ > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi,
On Mon, 18 Mar 2013, Curtis Rueden wrote: > > Does anyone have a suggestion how a plugin can react on a renaming > > action of an image taking place in the GUI? > > Looking at the source code of the JDK, it appears that the > java.awt.Frame class fires a property change event called "title" > whenever its setTitle(String) method is called. So you may be able to > detect the change by adding a PropertyChangeListener to the ImagePlus's > ImageWindow. > > Alternately, the "big hammer" solution to this sort of problem, which we > use in ImageJ2, is bytecode manipulation. We use the Javassist library [1] > to inject "seams" into methods. There are more options... Here is one pretty hacky that I use in Fiji's Wiki Editor plugin: https://github.com/fiji/fiji/blob/master/src-plugins/Fiji_Developer/src/main/java/fiji/Wiki_Editor.java#L824 A gentler method would be to add a CommandListener: http://jenkins.imagej.net/job/ImageJ1-javadoc/javadoc/ij/Executer.html#addCommandListener%28ij.CommandListener%29 The disadvantage is that the CommandListener does not get called back upon a successful conclusion of a command, but before it. So something else needs to be done that is not described in the Javadoc. The return value of commandExecuting can be used to override executing a command: https://github.com/fiji/ImageJA/blob/master/src/main/java/ij/Executer.java#L54 Ciao, Johannes -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Birgit Möller
On Mar 18, 2013, at 1:58 PM, Birgit Möller wrote:
> Hi all, > I would like to perform an action in my plugin when an image in ImageJ is renamed. I found the ImageListener interface which, however, triggers events only on opening, closing and updating images. Also the CommandListener interface does not help as my plugin should be notified after the renaming has taken place, not before as it happens if I implement the CommandListener interface. Does anyone have a suggestion how a plugin can react on a renaming action of an image taking place in the GUI? Starting with the ImageJ 1.47n daily build, the ImageListener interface triggers an image updated event when an image is renamed. You can verify this by running the Plugins>Utilities>Monitor Events command and renaming an image. -wayne -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Birgit Möller
Hi Curtis, Johannes and Wayne,
thanks for your quick replies and interesting suggestions how to solve my issue. For the moment I went for Wayne's enhancement as it appears to me the easiest (and quickest) solution of all proposed approaches, thanks for that! Best regards, Birgit ------------------------------------------------------------------------ Dr. rer. nat. Birgit Moeller Pattern Recognition & Bioinformatics Institute of Computer Science, Faculty of Natural Sciences III Martin Luther University Halle-Wittenberg e-mail: [hidden email] www: http://www.informatik.uni-halle.de/moeller/ ------------------------------------------------------------------------ -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |