Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6350026

add methods to save/restore the current Graphics status

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P5 P5
    • None
    • 5.0
    • client-libs
    • 2d
    • x86
    • windows_xp

      A DESCRIPTION OF THE REQUEST :
      While developing quite complex java2d applications I've faced a number of times the problem to save the current Graphics state (clip,transform,paint,etc.) and restore it later.

      it would be nice to have a Graphics2D api that allows saving and restoring the current graphics state. The api would look like this:

      g2d.pushContext(AFFINETRANSFORM|CLIP|PAINT); // save AFFINETRANSFORM, CLIP, PAINT
      g2d.setTransform(newTransform)
      g2d.blabla();
      ..
      g2d.pushContext(FONT); // save current font
      ...
      g2d.setFont(newfont)
      g2d.drawString(....);
      ...
      g2d.popContext(); // restore previous font
      ..
      g2d.drawString(....);
      ..
      g2d.popContext(); // restore previous AFFINETRANSFORM, CLIP, PAINT

      of course it should handle a stack of contexts.



      JUSTIFICATION :
      The current Java2D implementation forces me to make copies of the objects I'm going to modify and then re-set them in the graphics context later. An alternative is using create() and destroy() but this means creating a brand new context for each call. I suppose these approaches are both memory consuming and quite expensive in terms of performance. Even more they contribute to make us write a lot/complex code for doing simple things.

      I think that the Push/Pop approach would be of great help in order to keep code clean and execution very fast. I think it would also be helpful in order to optimize the new OGL pipeline.

            Unassigned Unassigned
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: