Coordinates from MouseEvent / Magnification problem

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

Coordinates from MouseEvent / Magnification problem

Thomas Radtke
Hi,

I have implemented a MouseListener in a plugin and read the coordinates
where the user has clicked from the MouseEvent class. Now I have two
problems with magnified images.

(1) I don't know how to find out what the magnification is. I've tried
to read it from

new ImageCanvas(my_imageplus).getMagnification()

but that always returns 1

(2) The Listener stops listening outside the original area after
magnifying the image

I've spent several hours on this problem and went through the message
archive but to no avail. Can anyone here point me in the right direction?

Thanks,

Thomas
Reply | Threaded
Open this post in threaded view
|

Re: Coordinates from MouseEvent / Magnification problem

William O'Connell
 -------------- Original message ----------------------
From: Thomas Radtke <[hidden email]>

> Hi,
>
> I have implemented a MouseListener in a plugin and read the coordinates
> where the user has clicked from the MouseEvent class. Now I have two
> problems with magnified images.
>
> (1) I don't know how to find out what the magnification is. I've tried
> to read it from
>
> new ImageCanvas(my_imageplus).getMagnification()
>
> but that always returns 1
>
> (2) The Listener stops listening outside the original area after
> magnifying the image
>
> I've spent several hours on this problem and went through the message
> archive but to no avail. Can anyone here point me in the right direction?
>
> Thanks,
>
> Thmas

Hi Thomas,
The snippet below works for me. I've probably included way more code than you need.
Best wishes, Bill
==============================================
public class Gradient_Edges implements PlugInFilter, MouseListener {
        ImageCanvas canvas;
        boolean click=false;
        Point clickPoint = new Point();
                 .
                 .
                 .
          canvas = imp.getWindow().getCanvas();
          canvas.addMouseListener(this);
          waitForClick();
          double mag = canvas.getMagnification();
          double cx = (int)(clickPoint.x/mag);
          double cy = (int)(clickPoint.y/mag);

        public void waitForClick() {
          while(!click) IJ.wait(300);
        }

        public void mouseClicked(MouseEvent e){
          click = true;
          clickPoint.x = e.getX();
          clickPoint.y = e.getY();                            .
       }
        public void mouseEntered(MouseEvent e){};
        public void mouseExited(MouseEvent e){};
        public void mouseReleased(MouseEvent e){};
        public void mousePressed(MouseEvent e){};
Reply | Threaded
Open this post in threaded view
|

Re: Coordinates from MouseEvent / Magnification problem

Thomas Radtke
Hi Bill,

William O'Connell schrieb:

>          canvas = imp.getWindow().getCanvas();
>  
>
[...]

>          double mag = canvas.getMagnification();
>
That was where my code failed. In the meantime, Wayne sent me an email
off list with the same tip. So, thanks to both of you, you're great. Of
course, it works perfect now:).

Thomas