Login  Register

Re: Coordinates from MouseEvent / Magnification problem

Posted by William O'Connell on Mar 02, 2006; 5:06pm
URL: http://imagej.273.s1.nabble.com/Coordinates-from-MouseEvent-Magnification-problem-tp3703521p3703522.html

 -------------- 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){};