Hi Ted,

The answer is that you should restore the origAtx and not set an identity.

In many cases, on the screen, the transform that appeared in the Graphics
object that your Swing component was handed was Identity anyway.  In earlier
implementations, they would draw nested components by using translate and
clip, but as of one of the Java 2 releases (I forget where we added this
capability) they now use internal APIs to adjust the graphics for subcomponents
in a way that doesn't affect the translate and clip values.  In other words
they install a new coordinate system and clip underneath the user-accessible
transform and clip.  This fixed a number of bugs where the user could override
the Swing clip and draw outside the bounds of their JComponent.

So, you may not notice any difference the way you are currently implemented
but the following would all fail with the code as you currently have it:

        - printing - the "drawOnTopOfImage" stuff would appear at
          printer device pixel resolution.  For a 600 DPI printer
          those renderings would be about 8-9 times smaller than
          you would have expected

        - manual nesting - Swing has been fixed to adjust the coordinate
          system in a way that is hidden to your inspections/mods of the
          Graphics transform, but what if someone wanted to use your
          module/component as part of a display list system they were
          designing and they wanted to force you to draw in a translated
          (or even scaled) coordinate system?  You would ignore the
          context they are passing in.

        - older versions of Swing - while it isn't likely you will run
          against the versions of Swing that used to use the user
          coordinate system to translate the components, it is a
          real world example of where this code would have failed.

        - Accessibility? - I'm not positive but I believe that the
          accessibility mechanisms may want to hand you a scaled
          coordinate system on the screen.  On the other hand, maybe
          they have you draw into a bitmap and scale that up for all
          I know.  But, if it ever were to be implemented by having
          the components draw in a scaled coordinate system, your
          component would not behave well for Java users with poor
          eyesight.

Another caveat that we will cover at JavaOne is that when you modify
a Graphics object in your paintComponent method, you need to restore
its settings before you return as the same Graphics object is used in
paintChildren and paintBorder (rather than a clone) and so the transform
you leave in the Graphics will affect your children (but not siblings
and ancestors).

I hope this helps!

                                ...jim

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to