For anyone who has similar problems with inverseTransform apparently not
working, the cause in my case was that I had the canvas in a JScrollPane.
The viewport in the JScrollPane add a translation to the graphics context
to keep the appropriate area of the canvas in view.  So inverseTransform
also needs to be followed by taking the view position into account, as
follows (where thePoint is a point in device space to start with, and is
converted to user space by the end):

        g2d.getTransform ().inverseTransform (thePoint, thePoint);
        Point temp = myViewport.getViewPosition ();
        thePoint.setLocation (thePoint.x - temp.x, thePoint.y - temp.y);

There's some exception handling and setup code omitted for brevity.

Jay

At 03:49 PM 5/17/99 -0400, you wrote:
>All,
>
>I'm trying to work out a rubber band selection mechanism, and as part of
>that I store off coordinates from the mouse events.  As far as I
>understand, these coordinates are in device space.
>
>Later, I use those coordinates to draw a selection rectangle.  I need to
>provide coordinates in user space for drawing the selection rectangle.
>I've tried using inverseTranform to convert the device coordinates back
>into user coordinates, but apparently inverseTransform is not doing what I
>expected.
>
>What is the recommended way to convert device coordinates back into user
>coordinates?
>
>Thanks,
>Jay Shaffstall
>
>
>=====================================================================
>To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
>Java 2D Home Page: http://java.sun.com/products/java-media/2D/
>
>

=====================================================================
To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
Java 2D Home Page: http://java.sun.com/products/java-media/2D/

Reply via email to