Mouse Events and Zoomed Images

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Mouse Events and Zoomed Images

nellypledge
Hi all, I hope the data treats you well.

I'm looking to use a mouse wheel event on an image even if it's been zoomed.  I have everything in place for the image at the default zoom, but if I zoom the getX and getY locations from my mouse event are offset from the point on the image I need.  I can get the scale difference from the Dimensions of the ImagePlus and the Canvas respectively to get the ratio.  The trouble comes when the image is zoomed to the point where only a section shows in the frame and if I pan around I still get the same X and Y.  This is expected as I've added the added the mouseWheelListener to the Canvas, and I'm wondering if there's a way to get the info of the offset so I can adjust, or if there's a way to get the physical units location from the mouse wheel event location.

Or, in retrospect, should I add the mouseWheelListener to a different object?

My class implements MouseListener and MouseWheelListener.  In my mouseWheelMoved method I use the MouseWheelEvent getX() and getY().

Thanks in advance for your time thinking on this question.

Neil
Reply | Threaded
Open this post in threaded view
|

Re: Mouse Events and Zoomed Images

John Hayes
Hi Neil,

If you just want coordinates of the mouse wrt the window, I believe you
would need to add your listeners to the ImageWindow. That class should also
contain the ImageCanvas offset, but I don't have the source code or API in
front of me right now.

HTH,

John
On Feb 20, 2016 3:36 PM, "nellypledge" <[hidden email]> wrote:

> Hi all, I hope the data treats you well.
>
> I'm looking to use a mouse wheel event on an image even if it's been
> zoomed.
> I have everything in place for the image at the default zoom, but if I zoom
> the getX and getY locations from my mouse event are offset from the point
> on
> the image I need.  I can get the scale difference from the Dimensions of
> the
> ImagePlus and the Canvas respectively to get the ratio.  The trouble comes
> when the image is zoomed to the point where only a section shows in the
> frame and if I pan around I still get the same X and Y.  This is expected
> as
> I've added the added the mouseWheelListener to the Canvas, and I'm
> wondering
> if there's a way to get the info of the offset so I can adjust, or if
> there's a way to get the physical units location from the mouse wheel event
> location.
>
> Or, in retrospect, should I add the mouseWheelListener to a different
> object?
>
> My class implements MouseListener and MouseWheelListener.  In my
> mouseWheelMoved method I use the MouseWheelEvent getX() and getY().
>
> Thanks in advance for your time thinking on this question.
>
> Neil
>
>
>
>
> --
> View this message in context:
> http://imagej.1557.x6.nabble.com/Mouse-Events-and-Zoomed-Images-tp5015681.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Mouse Events and Zoomed Images

nellypledge
Hi John, thanks for the pointer.

It's not the ImageWindow class that contains the details I need, but the subclass ImageCanvas does.  I was using the java.awt.Canvas, when I should have been using the ij.gui.ImageCanvas.  Now that I'm adding my listener to the right kind of canvas, I can use the details that save me even thinking about scaling etc.

Using the getCursorLoc() in the ImageCanvas object returns the pixel location independent of the scaling  Perfect!

Thanks for the tips.

Neil