Login  Register

Re: ImageListener: Adding imageFocused/Activated event would be nice

Posted by Michael Ellis on Jul 01, 2010; 9:03am
URL: http://imagej.273.s1.nabble.com/ImageListener-Adding-imageFocused-Activated-event-would-be-nice-tp3687738p3687745.html

Dear Wolfgang, I wanted to to do this too for my plugi. I solved the  
problem with the AWT toolkit AWTEventListener

In my plugIn's constructor I have:

this.getToolkit().addAWTEventListener(this,  
AWTEvent.WINDOW_FOCUS_EVENT_MASK);

When my PlugIn finishes I call

this.getToolkit().removeAWTEventListener(this);


My plugin implements the AWTEventListener interface with:


        /**
         * Invoked by AWT when windows are opened, closed, made active etc
         *
         * @see  
java.awt.event.AWTEventListener#eventDispatched(java.awt.AWTEvent)
         */
        public void eventDispatched(AWTEvent e) {
                try {
                        if (e.getID() == WindowEvent.WINDOW_GAINED_FOCUS) {
                        // do things
                        }
                } catch (Throwable t) {
                }
        }

Hope this is of some help.

Regards -- Michael Ellis

Does anyone know of a more ImageJ specific way to tackle this situation?

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]