public abstract class

CachedPainter

extends Object
java.lang.Object
   ↳ sun.swing.CachedPainter
Known Direct Subclasses

Class Overview

A base class used for icons or images that are expensive to paint. A subclass will do the following:

  1. Invoke paint when you want to paint the image, if you are implementing Icon you'll invoke this from paintIcon. The args argument is useful when additional state is needed.
  2. Override paintToImage to render the image. The code that lives here is equivalent to what previously would go in paintIcon, for an Icon.
The two ways to use this class are:
  1. Invoke paint to draw the cached reprensentation at the specified location.
  2. Invoke getImage to get the cached reprensentation and draw the image yourself. This is primarly useful when you are not using VolatileImage.

Summary

Public Constructors
CachedPainter(int cacheCount)
Creates an instance of CachedPainter that will cache up to cacheCount images of this class.
Public Methods
void paint(Component c, Graphics g, int x, int y, int w, int h, Object... args)
Renders the cached image to the the passed in Graphic.
Protected Methods
Image createImage(Component c, int w, int h, GraphicsConfiguration config, Object[] args)
Creates the image to cache.
void flush()
Clear the image cache
void paintImage(Component c, Graphics g, int x, int y, int w, int h, Image image, Object[] args)
Paints the image to the specified location.
abstract void paintToImage(Component c, Image image, Graphics g, int w, int h, Object[] args)
Paints the representation to cache to the supplied Graphics.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public CachedPainter (int cacheCount)

Creates an instance of CachedPainter that will cache up to cacheCount images of this class.

Parameters
cacheCount Max number of images to cache

Public Methods

public void paint (Component c, Graphics g, int x, int y, int w, int h, Object... args)

Renders the cached image to the the passed in Graphic. If there is no cached image paintToImage will be invoked. paintImage is invoked to paint the cached image.

Parameters
c Component rendering to, this may be null.
g Graphics to paint to
x X-coordinate to render to
y Y-coordinate to render to
w Width to render in
h Height to render in

Protected Methods

protected Image createImage (Component c, int w, int h, GraphicsConfiguration config, Object[] args)

Creates the image to cache. This returns an opaque image, subclasses that require translucency or transparency will need to override this method.

Parameters
c Component painting to
w Width of image to create
h Height to image to create
config GraphicsConfiguration that will be rendered to, this may be null.
args Arguments passed to paint

protected void flush ()

Clear the image cache

protected void paintImage (Component c, Graphics g, int x, int y, int w, int h, Image image, Object[] args)

Paints the image to the specified location.

Parameters
c Component painting to
g Graphics to paint to
x X coordinate to paint to
y Y coordinate to paint to
w Width to paint to
h Height to paint to
image Image to paint
args Arguments supplied to paint

protected abstract void paintToImage (Component c, Image image, Graphics g, int w, int h, Object[] args)

Paints the representation to cache to the supplied Graphics.

Parameters
c Component painting to, may be null.
image Image to paint to
g Graphics to paint to, obtained from the passed in Image.
w Width to paint to
h Height to paint to
args Arguments supplied to paint