Package org.jfree.pdf

Class PDFGraphics2D


public final class PDFGraphics2D extends Graphics2D
A Graphics2D implementation that writes to PDF format. For typical usage, see the documentation for the PDFDocument class.

For some demos of the use of this class, please check out the JFree Demos project at GitHub (https://github.com/jfree/jfree-demos).

  • Field Details

    • width

      int width
    • height

      int height
    • hints

      private RenderingHints hints
      Rendering hints (all ignored).
    • paint

      private Paint paint
    • color

      private Color color
    • background

      private Color background
    • composite

      private Composite composite
    • stroke

      private Stroke stroke
    • transform

      private AffineTransform transform
    • clip

      private Shape clip
      The user clip (can be null).
    • font

      private Font font
    • image

      private final BufferedImage image
      A hidden image used for font metrics.
    • line

      private Line2D line
      An instance that is lazily instantiated in drawLine and then subsequently reused to avoid creating a lot of garbage.
    • rect

      An instance that is lazily instantiated in fillRect and then subsequently reused to avoid creating a lot of garbage.
    • roundRect

      private RoundRectangle2D roundRect
      An instance that is lazily instantiated in draw/fillRoundRect and then subsequently reused to avoid creating a lot of garbage.
    • oval

      private Ellipse2D oval
      An instance that is lazily instantiated in draw/fillOval and then subsequently reused to avoid creating a lot of garbage.
    • arc

      private Arc2D arc
      An instance that is lazily instantiated in draw/fillArc and then subsequently reused to avoid creating a lot of garbage.
    • gs

      private GraphicsStream gs
      The content created by the Graphics2D instance.
    • deviceConfiguration

      private GraphicsConfiguration deviceConfiguration
    • fontRenderContext

      private final FontRenderContext fontRenderContext
      The font render context. The fractional metrics flag solves the glyph positioning issue identified by Christoph Nahr: http://news.kynosarges.org/2014/06/28/glyph-positioning-in-jfreesvg-orsonpdf/
    • originalTransform

      AffineTransform originalTransform
      When an instance is created via the create() method, a copy of the transform in effect is retained so it can be restored once the child instance is disposed. See issue #4 at GitHub.
  • Constructor Details

    • PDFGraphics2D

      PDFGraphics2D(GraphicsStream gs, int width, int height)
      Creates a new instance of PDFGraphics2D. You won't normally create this directly, instead you will call the Page.getGraphics2D() method.
      Parameters:
      gs - the graphics stream (null not permitted).
      width - the width.
      height - the height.
    • PDFGraphics2D

      PDFGraphics2D(GraphicsStream gs, int width, int height, boolean skipJava2DTransform)
      Creates a new instance of PDFGraphics2D. You won't normally create this directly, instead you will call the Page.getGraphics2D() method.
      Parameters:
      gs - the graphics stream (null not permitted).
      width - the width.
      height - the height.
      skipJava2DTransform - a flag that allows the PDF to Java2D transform to be skipped (used for watermarks which are appended to an existing stream that already has the transform).
  • Method Details

    • create

      public Graphics create()
      Returns a new PDFGraphics2D instance that is a copy of this instance.
      Specified by:
      create in class Graphics
      Returns:
      A new graphics object.
    • getPaint

      public Paint getPaint()
      Returns the paint used to draw or fill shapes (or text). The default value is Color.WHITE.
      Specified by:
      getPaint in class Graphics2D
      Returns:
      The paint (never null).
      See Also:
    • setPaint

      public void setPaint(Paint paint)
      Sets the paint used to draw or fill shapes (or text). If paint is an instance of Color, this method will also update the current color attribute (see getColor()). If you pass null to this method, it does nothing (in accordance with the JDK specification).
      Specified by:
      setPaint in class Graphics2D
      Parameters:
      paint - the paint (null is permitted but ignored).
      See Also:
    • getColor

      public Color getColor()
      Returns the foreground color. This method exists for backwards compatibility in AWT, you should normally use the getPaint() method instead.
      Specified by:
      getColor in class Graphics
      Returns:
      The foreground color (never null).
      See Also:
    • setColor

      public void setColor(Color c)
      Sets the foreground color. This method exists for backwards compatibility in AWT, you should normally use the setPaint(java.awt.Paint) method.
      Specified by:
      setColor in class Graphics
      Parameters:
      c - the color (null permitted but ignored).
      See Also:
    • getBackground

      public Color getBackground()
      Returns the background color. The default value is Color.BLACK. This is used by the clearRect(int, int, int, int) method.
      Specified by:
      getBackground in class Graphics2D
      Returns:
      The background color (possibly null).
      See Also:
    • setBackground

      public void setBackground(Color color)
      Sets the background color. This is used by the clearRect(int, int, int, int) method. The reference implementation allows null for the background color so we allow that too (but for that case, the clearRect() method will do nothing).
      Specified by:
      setBackground in class Graphics2D
      Parameters:
      color - the color (null permitted).
      See Also:
    • getComposite

      public Composite getComposite()
      Returns the current composite.
      Specified by:
      getComposite in class Graphics2D
      Returns:
      The current composite (never null).
      See Also:
    • setComposite

      public void setComposite(Composite comp)
      Sets the composite (only AlphaComposite is handled).
      Specified by:
      setComposite in class Graphics2D
      Parameters:
      comp - the composite (null not permitted).
      See Also:
    • getStroke

      public Stroke getStroke()
      Returns the current stroke (used when drawing shapes).
      Specified by:
      getStroke in class Graphics2D
      Returns:
      The current stroke (never null).
      See Also:
    • setStroke

      public void setStroke(Stroke s)
      Sets the stroke that will be used to draw shapes. Only BasicStroke is supported.
      Specified by:
      setStroke in class Graphics2D
      Parameters:
      s - the stroke (null not permitted).
      See Also:
    • getRenderingHint

      public Object getRenderingHint(RenderingHints.Key hintKey)
      Returns the current value for the specified hint. See the PDFHints class for details of the supported hints.
      Specified by:
      getRenderingHint in class Graphics2D
      Parameters:
      hintKey - the hint key (null permitted, but the result will be null also).
      Returns:
      The current value for the specified hint (possibly null).
      See Also:
    • setRenderingHint

      public void setRenderingHint(RenderingHints.Key hintKey, Object hintValue)
      Sets the value for a hint. See the PDFHints class for details of the supported hints.
      Specified by:
      setRenderingHint in class Graphics2D
      Parameters:
      hintKey - the hint key.
      hintValue - the hint value.
      See Also:
    • getRenderingHints

      public RenderingHints getRenderingHints()
      Returns a copy of the rendering hints. Modifying the returned copy will have no impact on the state of this Graphics2D instance.
      Specified by:
      getRenderingHints in class Graphics2D
      Returns:
      The rendering hints (never null).
      See Also:
    • setRenderingHints

      public void setRenderingHints(Map<?,?> hints)
      Sets the rendering hints to the specified collection.
      Specified by:
      setRenderingHints in class Graphics2D
      Parameters:
      hints - the new set of hints (null not permitted).
      See Also:
    • addRenderingHints

      public void addRenderingHints(Map<?,?> hints)
      Adds all the supplied rendering hints.
      Specified by:
      addRenderingHints in class Graphics2D
      Parameters:
      hints - the hints (null not permitted).
    • invTransformedClip

      private Shape invTransformedClip(Shape clip)
    • draw

      public void draw(Shape s)
      Draws the specified shape with the current paint and stroke. There is direct handling for Line2D and Path2D instances. All other shapes are mapped to a GeneralPath and then drawn (effectively as Path2D objects).
      Specified by:
      draw in class Graphics2D
      Parameters:
      s - the shape (null not permitted).
      See Also:
    • fill

      public void fill(Shape s)
      Fills the specified shape with the current paint. There is direct handling for Path2D instances. All other shapes are mapped to a GeneralPath and then filled.
      Specified by:
      fill in class Graphics2D
      Parameters:
      s - the shape (null not permitted).
      See Also:
    • getFont

      public Font getFont()
      Returns the current font used for drawing text.
      Specified by:
      getFont in class Graphics
      Returns:
      The current font (never null).
      See Also:
    • setFont

      public void setFont(Font font)
      Sets the font to be used for drawing text.
      Specified by:
      setFont in class Graphics
      Parameters:
      font - the font (null is permitted but ignored).
      See Also:
    • getFontMetrics

      public FontMetrics getFontMetrics(Font f)
      Returns the font metrics for the specified font.
      Specified by:
      getFontMetrics in class Graphics
      Parameters:
      f - the font.
      Returns:
      The font metrics.
    • getFontRenderContext

      public FontRenderContext getFontRenderContext()
      Returns the font render context. The implementation here returns the FontRenderContext for an image that is maintained internally (as for getFontMetrics(java.awt.Font)).
      Specified by:
      getFontRenderContext in class Graphics2D
      Returns:
      The font render context.
    • drawString

      public void drawString(String str, int x, int y)
      Draws a string at (x, y). The start of the text at the baseline level will be aligned with the (x, y) point.
      Specified by:
      drawString in class Graphics2D
      Parameters:
      str - the string (null not permitted).
      x - the x-coordinate.
      y - the y-coordinate.
      See Also:
    • drawString

      public void drawString(String str, float x, float y)
      Draws a string at (x, y). The start of the text at the baseline level will be aligned with the (x, y) point.
      Specified by:
      drawString in class Graphics2D
      Parameters:
      str - the string (null not permitted).
      x - the x-coordinate.
      y - the y-coordinate.
    • drawString

      public void drawString(AttributedCharacterIterator iterator, int x, int y)
      Draws a string of attributed characters at (x, y). The call is delegated to drawString(java.text.AttributedCharacterIterator, float, float).
      Specified by:
      drawString in class Graphics2D
      Parameters:
      iterator - an iterator for the characters.
      x - the x-coordinate.
      y - the x-coordinate.
    • drawString

      public void drawString(AttributedCharacterIterator iterator, float x, float y)
      Draws a string of attributed characters at (x, y).

      LIMITATION: in the current implementation, the string is drawn using the current font and the formatting is ignored.

      Specified by:
      drawString in class Graphics2D
      Parameters:
      iterator - an iterator over the characters (null not permitted).
      x - the x-coordinate.
      y - the y-coordinate.
    • drawGlyphVector

      public void drawGlyphVector(GlyphVector g, float x, float y)
      Draws the specified glyph vector at the location (x, y).
      Specified by:
      drawGlyphVector in class Graphics2D
      Parameters:
      g - the glyph vector (null not permitted).
      x - the x-coordinate.
      y - the y-coordinate.
    • translate

      public void translate(int tx, int ty)
      Applies the translation (tx, ty). This call is delegated to translate(double, double).
      Specified by:
      translate in class Graphics2D
      Parameters:
      tx - the x-translation.
      ty - the y-translation.
      See Also:
    • translate

      public void translate(double tx, double ty)
      Applies the translation (tx, ty).
      Specified by:
      translate in class Graphics2D
      Parameters:
      tx - the x-translation.
      ty - the y-translation.
    • rotate

      public void rotate(double theta)
      Applies a rotation (anti-clockwise) about (0, 0).
      Specified by:
      rotate in class Graphics2D
      Parameters:
      theta - the rotation angle (in radians).
    • rotate

      public void rotate(double theta, double x, double y)
      Applies a rotation (anti-clockwise) about (x, y).
      Specified by:
      rotate in class Graphics2D
      Parameters:
      theta - the rotation angle (in radians).
      x - the x-coordinate.
      y - the y-coordinate.
    • scale

      public void scale(double sx, double sy)
      Applies a scale transformation.
      Specified by:
      scale in class Graphics2D
      Parameters:
      sx - the x-scaling factor.
      sy - the y-scaling factor.
    • shear

      public void shear(double shx, double shy)
      Applies a shear transformation. This is equivalent to the following call to the transform method:
      • transform(AffineTransform.getShearInstance(shx, shy));
      Specified by:
      shear in class Graphics2D
      Parameters:
      shx - the x-shear factor.
      shy - the y-shear factor.
    • transform

      public void transform(AffineTransform t)
      Applies this transform to the existing transform by concatenating it.
      Specified by:
      transform in class Graphics2D
      Parameters:
      t - the transform (null not permitted).
    • getTransform

      public AffineTransform getTransform()
      Returns a copy of the current transform.
      Specified by:
      getTransform in class Graphics2D
      Returns:
      A copy of the current transform (never null).
      See Also:
    • setTransform

      public void setTransform(AffineTransform t)
      Sets the transform.
      Specified by:
      setTransform in class Graphics2D
      Parameters:
      t - the new transform (null permitted, resets to the identity transform).
      See Also:
    • hit

      public boolean hit(Rectangle rect, Shape s, boolean onStroke)
      Returns true if the rectangle (in device space) intersects with the shape (the interior, if onStroke is false, otherwise the stroked outline of the shape).
      Specified by:
      hit in class Graphics2D
      Parameters:
      rect - a rectangle (in device space).
      s - the shape.
      onStroke - test the stroked outline only?
      Returns:
      A boolean.
    • getDeviceConfiguration

      public GraphicsConfiguration getDeviceConfiguration()
      Returns the device configuration associated with this Graphics2D.
      Specified by:
      getDeviceConfiguration in class Graphics2D
      Returns:
      The graphics configuration.
    • setPaintMode

      public void setPaintMode()
      Does nothing in this PDFGraphics2D implementation.
      Specified by:
      setPaintMode in class Graphics
    • setXORMode

      public void setXORMode(Color c)
      Does nothing in this PDFGraphics2D implementation.
      Specified by:
      setXORMode in class Graphics
      Parameters:
      c - ignored
    • getClip

      public Shape getClip()
      Returns the user clipping region. The initial default value is null.
      Specified by:
      getClip in class Graphics
      Returns:
      The user clipping region (possibly null).
      See Also:
    • setClip

      public void setClip(Shape shape)
      Sets the user clipping region.
      Specified by:
      setClip in class Graphics
      Parameters:
      shape - the new user clipping region (null permitted).
      See Also:
    • getClipBounds

      public Rectangle getClipBounds()
      Returns the bounds of the user clipping region. If the user clipping region is null, this method will return null.
      Specified by:
      getClipBounds in class Graphics
      Returns:
      The clip bounds (possibly null).
      See Also:
    • clip

      public void clip(Shape s)
      Clips to the intersection of the current clipping region and the specified shape.

      According to the Oracle API specification, this method will accept a null argument, but there is an open bug report (since 2004) that suggests this is wrong:

      http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6206189

      Specified by:
      clip in class Graphics2D
      Parameters:
      s - the clip shape (null not permitted).
    • clipRect

      public void clipRect(int x, int y, int width, int height)
      Clips to the intersection of the current clipping region and the specified rectangle.
      Specified by:
      clipRect in class Graphics
      Parameters:
      x - the x-coordinate.
      y - the y-coordinate.
      width - the width.
      height - the height.
    • setClip

      public void setClip(int x, int y, int width, int height)
      Sets the user clipping region to the specified rectangle.
      Specified by:
      setClip in class Graphics
      Parameters:
      x - the x-coordinate.
      y - the y-coordinate.
      width - the width.
      height - the height.
      See Also:
    • drawLine

      public void drawLine(int x1, int y1, int x2, int y2)
      Draws a line from (x1, y1) to (x2, y2) using the current paint and stroke.
      Specified by:
      drawLine in class Graphics
      Parameters:
      x1 - the x-coordinate of the start point.
      y1 - the y-coordinate of the start point.
      x2 - the x-coordinate of the end point.
      y2 - the x-coordinate of the end point.
    • fillRect

      public void fillRect(int x, int y, int width, int height)
      Fills the specified rectangle with the current paint.
      Specified by:
      fillRect in class Graphics
      Parameters:
      x - the x-coordinate.
      y - the y-coordinate.
      width - the rectangle width.
      height - the rectangle height.
    • clearRect

      public void clearRect(int x, int y, int width, int height)
      Clears the specified rectangle by filling it with the current background color. If the background color is null, this method will do nothing.
      Specified by:
      clearRect in class Graphics
      Parameters:
      x - the x-coordinate.
      y - the y-coordinate.
      width - the width.
      height - the height.
      See Also:
    • drawRoundRect

      public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
      Draws a rectangle with rounded corners using the current paint and stroke.
      Specified by:
      drawRoundRect in class Graphics
      Parameters:
      x - the x-coordinate.
      y - the y-coordinate.
      width - the width.
      height - the height.
      arcWidth - the arc-width.
      arcHeight - the arc-height.
      See Also:
    • fillRoundRect

      public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
      Fills a rectangle with rounded corners.
      Specified by:
      fillRoundRect in class Graphics
      Parameters:
      x - the x-coordinate.
      y - the y-coordinate.
      width - the width.
      height - the height.
      arcWidth - the arc-width.
      arcHeight - the arc-height.
    • drawOval

      public void drawOval(int x, int y, int width, int height)
      Draws an oval framed by the rectangle (x, y, width, height) using the current paint and stroke.
      Specified by:
      drawOval in class Graphics
      Parameters:
      x - the x-coordinate.
      y - the y-coordinate.
      width - the width.
      height - the height.
      See Also:
    • fillOval

      public void fillOval(int x, int y, int width, int height)
      Fills an oval framed by the rectangle (x, y, width, height).
      Specified by:
      fillOval in class Graphics
      Parameters:
      x - the x-coordinate.
      y - the y-coordinate.
      width - the width.
      height - the height.
      See Also:
    • drawArc

      public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
      Draws an arc contained within the rectangle (x, y, width, height), starting at startAngle and continuing through arcAngle degrees using the current paint and stroke.
      Specified by:
      drawArc in class Graphics
      Parameters:
      x - the x-coordinate.
      y - the y-coordinate.
      width - the width.
      height - the height.
      startAngle - the start angle in degrees, 0 = 3 o'clock.
      arcAngle - the angle (anticlockwise) in degrees.
      See Also:
    • fillArc

      public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)
      Fills an arc contained within the rectangle (x, y, width, height), starting at startAngle and continuing through arcAngle degrees, using the current paint
      Specified by:
      fillArc in class Graphics
      Parameters:
      x - the x-coordinate.
      y - the y-coordinate.
      width - the width.
      height - the height.
      startAngle - the start angle in degrees, 0 = 3 o'clock.
      arcAngle - the angle (anticlockwise) in degrees.
      See Also:
    • drawPolyline

      public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints)
      Draws the specified multi-segment line using the current paint and stroke.
      Specified by:
      drawPolyline in class Graphics
      Parameters:
      xPoints - the x-points.
      yPoints - the y-points.
      nPoints - the number of points to use for the polyline.
    • drawPolygon

      public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
      Draws the specified polygon using the current paint and stroke.
      Specified by:
      drawPolygon in class Graphics
      Parameters:
      xPoints - the x-points.
      yPoints - the y-points.
      nPoints - the number of points to use for the polygon.
      See Also:
    • fillPolygon

      public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)
      Fills the specified polygon using the current paint.
      Specified by:
      fillPolygon in class Graphics
      Parameters:
      xPoints - the x-points.
      yPoints - the y-points.
      nPoints - the number of points to use for the polygon.
      See Also:
    • drawImage

      public boolean drawImage(Image img, AffineTransform xform, ImageObserver observer)
      Draws an image with the specified transform. Note that the obs is ignored.
      Specified by:
      drawImage in class Graphics2D
      Parameters:
      img - the image.
      xform - the transform (null permitted).
      observer - the image observer (ignored).
      Returns:
      true if the image is drawn.
    • drawImage

      public void drawImage(BufferedImage img, BufferedImageOp op, int x, int y)
      Draws the image resulting from applying the BufferedImageOp to the specified image at the location (x, y).
      Specified by:
      drawImage in class Graphics2D
      Parameters:
      img - the image.
      op - the operation.
      x - the x-coordinate.
      y - the y-coordinate.
    • drawRenderedImage

      public void drawRenderedImage(RenderedImage img, AffineTransform xform)
      Draws the rendered image. When img is null this method does nothing.
      Specified by:
      drawRenderedImage in class Graphics2D
      Parameters:
      img - the image (null permitted).
      xform - the transform.
    • drawRenderableImage

      public void drawRenderableImage(RenderableImage img, AffineTransform xform)
      Draws the renderable image.
      Specified by:
      drawRenderableImage in class Graphics2D
      Parameters:
      img - the renderable image.
      xform - the transform.
    • drawImage

      public boolean drawImage(Image img, int x, int y, ImageObserver observer)
      Draws an image at the location (x, y). Note that the observer is ignored.
      Specified by:
      drawImage in class Graphics
      Parameters:
      img - the image.
      x - the x-coordinate.
      y - the y-coordinate.
      observer - ignored.
      Returns:
      true if the image is drawn.
    • drawImage

      public boolean drawImage(Image img, int x, int y, int w, int h, ImageObserver observer)
      Draws the image into the rectangle defined by (x, y, w, h). Note that the observer is ignored (it is not useful in this context).
      Specified by:
      drawImage in class Graphics
      Parameters:
      img - the image.
      x - the x-coordinate.
      y - the y-coordinate.
      w - the width.
      h - the height.
      observer - ignored.
      Returns:
      true if the image is drawn.
    • drawImage

      public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer)
      Draws an image at the location (x, y). Note that the observer is ignored.
      Specified by:
      drawImage in class Graphics
      Parameters:
      img - the image.
      x - the x-coordinate.
      y - the y-coordinate.
      bgcolor - the background color (null permitted).
      observer - ignored.
      Returns:
      true if the image is drawn.
    • drawImage

      public boolean drawImage(Image img, int x, int y, int w, int h, Color bgcolor, ImageObserver observer)
      Draws an image to the rectangle (x, y, w, h) (scaling it if required), first filling the background with the specified color. Note that the observer is ignored.
      Specified by:
      drawImage in class Graphics
      Parameters:
      img - the image.
      x - the x-coordinate.
      y - the y-coordinate.
      w - the width.
      h - the height.
      bgcolor - the background color (null permitted).
      observer - ignored.
      Returns:
      true if the image is drawn.
    • drawImage

      public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer)
      Draws part of an image (defined by the source rectangle (sx1, sy1, sx2, sy2)) into the destination rectangle (dx1, dy1, dx2, dy2). Note that the observer is ignored.
      Specified by:
      drawImage in class Graphics
      Parameters:
      img - the image.
      dx1 - the x-coordinate for the top left of the destination.
      dy1 - the y-coordinate for the top left of the destination.
      dx2 - the x-coordinate for the bottom right of the destination.
      dy2 - the y-coordinate for the bottom right of the destination.
      sx1 - the x-coordinate for the top left of the source.
      sy1 - the y-coordinate for the top left of the source.
      sx2 - the x-coordinate for the bottom right of the source.
      sy2 - the y-coordinate for the bottom right of the source.
      Returns:
      true if the image is drawn.
    • drawImage

      public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer)
      Draws part of an image (defined by the source rectangle (sx1, sy1, sx2, sy2)) into the destination rectangle (dx1, dy1, dx2, dy2). The destination rectangle is first cleared by filling it with the specified bgcolor. Note that the observer is ignored.
      Specified by:
      drawImage in class Graphics
      Parameters:
      img - the image.
      dx1 - the x-coordinate for the top left of the destination.
      dy1 - the y-coordinate for the top left of the destination.
      dx2 - the x-coordinate for the bottom right of the destination.
      dy2 - the y-coordinate for the bottom right of the destination.
      sx1 - the x-coordinate for the top left of the source.
      sy1 - the y-coordinate for the top left of the source.
      sx2 - the x-coordinate for the bottom right of the source.
      sy2 - the y-coordinate for the bottom right of the source.
      bgcolor - the background color (null permitted).
      observer - ignored.
      Returns:
      true if the image is drawn.
    • copyArea

      public void copyArea(int x, int y, int width, int height, int dx, int dy)
      This method does nothing. The operation assumes that the output is in bitmap form, which is not the case for PDF, so we silently ignore this method call.
      Specified by:
      copyArea in class Graphics
      Parameters:
      x - the x-coordinate.
      y - the y-coordinate.
      width - the width of the area.
      height - the height of the area.
      dx - the delta x.
      dy - the delta y.
    • dispose

      public void dispose()
      Performs any actions required when the graphics instance is finished with. Here we restore the transform on the graphics stream if this instance was created via the create() method. See issue #4 at GitHub for background info.
      Specified by:
      dispose in class Graphics
    • setRect

      private void setRect(int x, int y, int width, int height)
      Sets the attributes of the reusable Rectangle2D object that is used by the Graphics.drawRect(int, int, int, int) and fillRect(int, int, int, int) methods.
      Parameters:
      x - the x-coordinate.
      y - the y-coordinate.
      width - the width.
      height - the height.
    • setRoundRect

      private void setRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
      Sets the attributes of the reusable RoundRectangle2D object that is used by the drawRoundRect(int, int, int, int, int, int) and fillRoundRect(int, int, int, int, int, int) methods.
      Parameters:
      x - the x-coordinate.
      y - the y-coordinate.
      width - the width.
      height - the height.
      arcWidth - the arc width.
      arcHeight - the arc height.
    • setOval

      private void setOval(int x, int y, int width, int height)
      Sets the attributes of the reusable Ellipse2D object that is used by the drawOval(int, int, int, int) and fillOval(int, int, int, int) methods.
      Parameters:
      x - the x-coordinate.
      y - the y-coordinate.
      width - the width.
      height - the height.
    • setArc

      private void setArc(int x, int y, int width, int height, int startAngle, int arcAngle)
      Sets the attributes of the reusable Arc2D object that is used by drawArc(int, int, int, int, int, int) and fillArc(int, int, int, int, int, int) methods.
      Parameters:
      x - the x-coordinate.
      y - the y-coordinate.
      width - the width.
      height - the height.
      startAngle - the start angle in degrees, 0 = 3 o'clock.
      arcAngle - the angle (anticlockwise) in degrees.