Paint Component

I use the AffineTransform in the paint component all the time. If I get the transform like this:

t = g.getTransform()

it returns something like this:

AffineTransform[[1.0, 0.0, 383.0], [0.0, 1.0, 103.0]]

How can I get the individual values in t, i.e. 383.0? My life would be much easier if I could do that, but I’m missing something even though I scoured the j2d docs.


Try the following:

[code]m00 = t.getScaleX()
m11 = t.getScaleY()
m01 = t.getShearX()
m10 = t.getShearY()
m02 = t.getTranslateX()
m12 = t.getTranslateY()

xprime = [m00, m01, m02]
yprime = [m10, m11, m12][/code]

Thanks Mickey, I don’t know how I missed that. Works like a charm.

Hmm, quick techical question for the IA crew. I tried using getTranslateX() from the saved transform, i.e.:

t = g.getTransform()
print t.getTranslateX()

but I get odd results when the paint object refreshes automatically. For instance, when I click on the paint object and trigger my own repaint, the getTranslateX is what I would expect. But if I drag a window over the paint object (which forces it to repaint itself), the getTranslateX() returns wild numbers, although the image paints correctly. So, I went back to using my old method of storing and retrieving the calculated x translation instead, which also works fine.

So, just for my own curiousity, do the internal workings of the paint object handle its own transformation at another level and apply my translation on top of it, which is why the absolute getTranslateX() could have unexpected values? I hope what I just wrote made sense.

I think the answer to your question is: Yes. The graphics object is not always going to be anchored at the same spot, depending on the scope of the current repaint. You are applying a transformation on top of another, which you shouldn’t make any assumptions about.