I have a JPanel that draws shapes and allows those shapes to be selected. I'm starting to add the capability to transform this view using the AffineTransform object, in conjunction with the Graphics2D object.
In my paint() method, of course a Graphics object is passed in. I set a new transform on that object (in this case, just scaling things by 2), and everything in the paint() method draws correctly according to the AffineTransform I just set. At this point the drawing shapes part works great! Now on to the shape selection...
Shape selection starts in the mousePressed() event (My JPanel implements the MouseListener interface). When I have a mousePressed() event, I call this.getGraphics() to get the JPanel's Graphics object. I then case it to a Graphics2D object and call getTransform() on it to get my current transform so I can map the clicked point to the transformed point. When I call getTransform(), however, the AffineTransform is back to the default AffineTransform of [1, 0, 0], [0, 1, 0].
I'm thinking that maybe the Graphics object passed to the JPanel's paint() is different than the one I have in my JPanel, but I'm not sure on that. Does anyone have any idea what's going on here?