> do I have to translate the coordinates (from mouse clicks, etc) based
> on the scaling factor?
Yes. Mouse coordinates are always in device space coordinates. If you
want to relate them to user space coordinates, you need to do the
necessary coordinate space transformation.
> hopefully not! if so, is there an easy way to
> make such a coordinate translation?
Are approx. five to ten lines of code to much?
* If you have complex scaling, rotation, translation, etc:
Use an explicit AffineTransform for the scaling, instead of just
manipulating the default one in Graphics2D. Keep that transform. In the
mouse listener use AffineTransform.inverseTransform() to transform the
device space coordinates into your user space coordinates.
* If you have a simple linear scaling:
Remember the zoom factor and just divide the coordinates in the mouse
listener by that factor.
/Thomas

Signature
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
Graham Street - 28 Dec 2005 18:16 GMT
I've realized that doing a zoom isn't going to work out, since that
will make the text appearing on my panel, etc get bigger... I just want
to increase the dimensions of my shape. So, I've settled on iterating
through my coordinates and adjusting the lengths of each line by a
scaling factor. This way the shape grows to fill the panel but the
other drawn items remain the same scale. But, this is getting pretty
challenging with non-rectangles... It's getting messy. I'm wondering
if there is a cleaner way. Does anyone know of any tricks for doing
coordinate scaling transforms like this? my problems seem to mostly be
related to trying to keep the position of the first point fixed.
I am dealing with the shape as "lines" consisting of two points each.
I go through each line and change the second point (x2 or y2
depending on the plane) to reflect the new length (multiplied by
scaling factor, eg len * 1.5). But once I get to the underside of the
shape, things get out of whack.
> > do I have to translate the coordinates (from mouse clicks, etc) based
> > on the scaling factor?
[quoted text clipped - 25 lines]
> ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
> http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/