code: private void paint(SeaGlassPainter p, SynthContext ctx, Graphics g, int x, int y, int w, int h, AffineTransform transform) {
          if (p != null) {
  
              if (g instanceof Graphics2D) {
                  Graphics2D gfx = (Graphics2D) g;
  
                  if (transform != null) {
                      gfx.transform(transform);
                  }
  
                  gfx.translate(x, y);
                  p.paint(gfx, ctx.getComponent(), w, h);
                  gfx.translate(-x, -y);
  
                  if (transform != null) {
  
                      try {
                          gfx.transform(transform.createInverse());
                      } catch (NoninvertibleTransformException e) {
  
                          // this should never happen as we are in control of all
                          // calls into this method and only ever pass in simple
                          // transforms of rotate, flip and translates
                          e.printStackTrace();
                      }
                  }
              } else {
  
                  // use image if we are printing to a Java 1.1 PrintGraphics as
                  // it is not a instance of Graphics2D
                  BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
                  Graphics2D    gfx = img.createGraphics();
  
                  if (transform != null) {
                      gfx.transform(transform);
                  }
  
                  p.paint(gfx, ctx.getComponent(), w, h);
                  gfx.dispose();
                  g.drawImage(img, x, y, null);
                  img = null;
              }
          }
      }
docs: Paint the provided painter using the provided transform at the specified
  position and size. Handles if g is a non 2D Graphics by painting via a
  BufferedImage.
  
  @param p         the painter to use.
  @param ctx       the SynthContext describing the component/region, the
  style, and the state.
  @param g         the Graphics context to paint with.
  @param x         the left-most portion of the object to paint.
  @param y         the upper-most portion of the object to paint.
  @param w         the width to paint.
  @param h         the height to paint.
  @param transform the affine transform to apply, or {@code null} if none
  is to be applied.