Posted by
Michael Ellis on
Jul 01, 2010; 9:33am
URL: http://imagej.273.s1.nabble.com/ImageListener-Adding-imageFocused-Activated-event-would-be-nice-tp3687738p3687740.html
As a followup I here's a simple but complete plugin that illustrates
things
package DSUKplugins;
import java.awt.AWTEvent;
import java.awt.event.AWTEventListener;
import java.awt.event.WindowEvent;
import ij.IJ;
import ij.plugin.frame.PlugInFrame;
/**
* Test_PlunginFrame Illustrate how a PlugIn can detect when there is a
* change in window focus
*
* @author Michael Ellis, DSUK Ltd.
*/
public class Test_PlunginFrame extends PlugInFrame implements
AWTEventListener {
public Test_PlunginFrame() {
super("Test_PluginFrame");
this.getToolkit().addAWTEventListener(this,
AWTEvent.WINDOW_FOCUS_EVENT_MASK);
this.setBounds(100, 100, 300, 100);
this.setVisible(true);
}
public void close() {
this.getToolkit().removeAWTEventListener(this);
super.close();
}
public void eventDispatched(AWTEvent event) {
try {
if (event.getID() == WindowEvent.WINDOW_GAINED_FOCUS) {
IJ.log("event " + event.getID() + " " + event.getSource());
}
} catch (Throwable t) {
}
}
}
On 1 Jul 2010, at 09:27, Wolfgang Gross wrote:
> Hi all,
>
> plugins that implement the ImageListener interface are notified when
> an image
> is Opened/Closed/Updated. In addition, it would be nice to get
> notified
> immediately when an image gets the focus so plugins can keep track
> of the
> current image.
> Calling WindowManager.getCurrentImage() when the plugin itself gains
> focus is
> not what I need.
>
> Regards
> Wolfgang
> --
> Dr. W. Gross, Chirurgische Klinik I, Exp. Chirurgie, Uniklinik
> Heidelberg
> Im Neuenheimer Feld 365, D-69120 Heidelberg, Germany
> Tel. ++49 (0)6221/566392, Fax: ++49 (0)6221/564208
>
[hidden email]