Package org.bzdev.gio

Class Graphics2DRecorder

java.lang.Object
org.bzdev.gio.Graphics2DRecorder
All Implemented Interfaces:
Cloneable, GraphicsCreator

public class Graphics2DRecorder extends Object implements GraphicsCreator, Cloneable
Class for creating Graphics2D instances that can be replayed.

While in most cases, instances of this class will just "do the right thing", one should note that the Graphics2D methods

  • getFontRenderContext()
  • getDeviceConfiguration()
  • toString()
may return values that are are different from the return values for the initial graphics content and one passed to playback(Graphics2D). One should avoid using these methods (except for the toString() method for diagnostics or debugging). By contrast, the methods
  • getBackground()
  • getComposite()
  • getPaint()
  • getRenderingHint(RenderingHints.Key)
  • getRenderingHints()
  • getStroke()
  • getTransform()
  • hit()
  • getClip()
  • getClipBounds()
  • getFont()
  • getFontMetrics()
  • hitClip()
may return values that are are different from the return values for the initial graphics content and one passed to playback(Graphics2D), but only if the corresponding 'set' methods have not been called. In other words, to get a desired background color, one should explicitly call Graphics2D.setBackground(Color) and not depend on a default value. Similarly, before calling Graphics.getFontMetrics(), one should call Graphics.setFont(Font).
  • Constructor Details

    • Graphics2DRecorder

      public Graphics2DRecorder(Graphics2D g2d)
      Constructor.
      Parameters:
      g2d - the Graphics2D used by createGraphics to create multiple Graphics 2D graphics contexts
  • Method Details

    • reset

      public void reset()
      Reset the recorder. It is the caller's responsibility to make sure that all graphics contexts previously created by the recorder are not used subsequently.
    • createGraphics

      public Graphics2D createGraphics()
      Create a graphics context.
      Specified by:
      createGraphics in interface GraphicsCreator
      Returns:
      the new graphics context
    • playback

      public void playback(Graphics2D tg2d)
      Play back all the operations perforemed on the graphics contexts created, except for a dispose as that will be handled separately for the target graphics context.
      Parameters:
      tg2d - the target graphics context for the playback