Hello Imagers,
I wrote a plugin a long time ago (for browsing 4d datasets from disc) that extends the ImageWindow class, and creates a KeyListener to act on the up, down, left, and right arrow keys. This worked well before the default behavior was to magnify or reduce the ImageWindow using the right and left arrow keys, as in more recent versions of ImageJ. Now the plugin reads the key stroke and acts on it, but the key stroke is passed to ImageJ, which then magnifies or reduces the ImageWindow. I guess I'm stupid, but I don't see how to prevent this. Any ideas would be deeply appreciated! Cheers, Jeff ---------------------------------------------- Jeff Hardin Professor and Chair, Department of Zoology Director, Biology Core Curriculum University of Wisconsin 1117 W. Johnson St. Madison, WI 53706 voice: (608) 262-9634 fax: (608) 262-7319 email: [hidden email] web page: http://worms.zoology.wisc.edu |
Hi Jeff,
you mean, your plugin kets the keys as it should be, but it will ALSO be handled by ImageJ? I´m not sure, which happens first, just did a quick internet search, there is a KeyEvent.consume methods, which marks an event as already fully handled, you might give it a try!? Mit freundlichen Grüßen / Best regards Joachim Wesner Projektleiter Optik Technologiesysteme Leica Microsystems CMS GmbH | GmbH mit Sitz in Wetzlar | Amtsgericht Wetzlar HRB 2432 Geschäftsführer: Dr. Stefan Traeger | Dr. Wolf-Otto Reuter | Dr. David Roy Martyr | Colin Davis www.leica-microsystems.com Jeff Hardin <[hidden email] U> An Gesendet von: [hidden email] ImageJ Interest Kopie Group <[hidden email]. Thema GOV> Intercepting keystrokes in plugin 22.07.2009 07:39 Bitte antworten an ImageJ Interest Group <[hidden email]. GOV> Hello Imagers, I wrote a plugin a long time ago (for browsing 4d datasets from disc) that extends the ImageWindow class, and creates a KeyListener to act on the up, down, left, and right arrow keys. This worked well before the default behavior was to magnify or reduce the ImageWindow using the right and left arrow keys, as in more recent versions of ImageJ. Now the plugin reads the key stroke and acts on it, but the key stroke is passed to ImageJ, which then magnifies or reduces the ImageWindow. I guess I'm stupid, but I don't see how to prevent this. Any ideas would be deeply appreciated! Cheers, Jeff ---------------------------------------------- Jeff Hardin Professor and Chair, Department of Zoology Director, Biology Core Curriculum University of Wisconsin 1117 W. Johnson St. Madison, WI 53706 voice: (608) 262-9634 fax: (608) 262-7319 email: [hidden email] web page: http://worms.zoology.wisc.edu ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ |
Hi,
On Wed, 22 Jul 2009, Joachim Wesner wrote: > you mean, your plugin kets the keys as it should be, but it will ALSO be > handled by ImageJ? > > I´m not sure, which happens first, just did a quick internet search, there > is a > > KeyEvent.consume > > methods, which marks an event as already fully handled, you might give > it a try!? Better to removeKeyListener(IJ.getInstance()) on the ImageWindow to prevent ImageJ from handling the keys at all. You can then hand off the event (if it is not handled yet) to IJ.getInstance().keyPressed(). Ciao, Dscho |
Hi Joachim and Johannes,
>> you mean, your plugin kets the keys as it should be, but it will >> ALSO be >> handled by ImageJ? >> KeyEvent.consume >> >> methods, which marks an event as already fully handled, you might >> give >> it a try!? > > That relies on your KeyListener being called first, which is not good. Apparently, Listeners are called in reverse order of addition, which in this case should guarantee that the plugin's listener is called first. However, propagation of the InputEvent is not stopped when the consume function is called, rather, a Listener should check the isConsumed() flag on the inputEvent and take action accordingly. I had a quick look at the ImageJ code to handle KeyPresses and do not see the isConsumed() check there. It seems useful to add so that plugin writers can use the "consume" method to signal ImageJ that they have handled an event. I found the following link helpful: http://elliotth.blogspot.com/2004/08/implementing-java-listeners.html Best, Nico |
In reply to this post by Jeff Hardin
> Hello Imagers,
> > I wrote a plugin a long time ago (for browsing 4d datasets from disc) > that extends the ImageWindow class, and creates a KeyListener to act > on the up, down, left, and right arrow keys. This worked well before > the default behavior was to magnify or reduce the ImageWindow using > the right and left arrow keys, as in more recent versions of ImageJ. > Now the plugin reads the key stroke and acts on it, but the key stroke > is passed to ImageJ, which then magnifies or reduces the ImageWindow. > I guess I'm stupid, but I don't see how to prevent this. > > Any ideas would be deeply appreciated! You can keep key pressed events from being passed to ImageJ by removing it as a KeyListener using removeKeyListener(IJ.getInstance()); I updated the KeyListener example plugin at http://rsbweb.nih.gov/ij/plugins/key-listener.html to do this. I tried using KeyEvent.consume() but it didn't work because the plugin's keyPressed() method was called after ImageJ's keyPressed() method. -wayne |
In reply to this post by Jeff Hardin
Hi folks,
Oops! I meant, of course, "... to magnify or reduce the ImageWindow using the up and down arrow keys..." Cheers, Jeff ---------------------------------------------- Jeff Hardin Professor and Chair, Department of Zoology Director, Biology Core Curriculum University of Wisconsin 1117 W. Johnson St. Madison, WI 53706 voice: (608) 262-9634 fax: (608) 262-7319 email: [hidden email] web page: http://worms.zoology.wisc.edu On Jul 22, 2009, at 11:00 PM, IMAGEJ automatic digest system wrote: > Date: Wed, 22 Jul 2009 00:39:42 -0500 > From: Jeff Hardin <[hidden email]> > Subject: Intercepting keystrokes in plugin > > Hello Imagers, > > I wrote a plugin a long time ago (for browsing 4d datasets from disc) > that extends the ImageWindow class, and creates a KeyListener to act > on the up, down, left, and right arrow keys. This worked well before > the default behavior was to magnify or reduce the ImageWindow using > the right and left arrow keys, as in more recent versions of ImageJ. > Now the plugin reads the key stroke and acts on it, but the key stroke > is passed to ImageJ, which then magnifies or reduces the ImageWindow. > I guess I'm stupid, but I don't see how to prevent this. > > Any ideas would be deeply appreciated! > > Cheers, > > Jeff |
Free forum by Nabble | Edit this page |