APIdia Launch Partner
Top Description Inners Fields Constructors Methods
sun.swing

public abstract Class CachedPainter

extends Object
Class Inheritance
Known Direct Subclasses
sun.swing.plaf.synth.Paint9Painter, javax.swing.plaf.metal.MetalIconFactory.OceanVerticalSliderThumbIcon, javax.swing.plaf.metal.MetalIconFactory.OceanHorizontalSliderThumbIcon, javax.swing.plaf.metal.MetalUtils.GradientPainter
Imports
sun.awt.image.SurfaceManager, sun.java2d.SurfaceData, java.awt.Component, .Graphics, .Graphics2D, .GraphicsConfiguration, .Image, java.awt.geom.AffineTransform, java.awt.image.AbstractMultiResolutionImage, .BufferedImage, .ImageObserver, .VolatileImage, java.util.Arrays, .HashMap, .Map

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 representation at the specified location.
  2. Invoke getImage to get the cached representation and draw the image yourself. This is primarily useful when you are not using VolatileImage.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class

Field Summary

Modifier and TypeField and Description
private static final Map<Object, ImageCache>

Constructor Summary

AccessConstructor and Description
public
CachedPainter(int
Max number of images to cache
cacheCount
)

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

Method Summary

Modifier and TypeMethod and Description
protected Image
createImage(Component
Component painting to
c
,
int
Width of image to create
w
,
int
Height to image to create
h
,
GraphicsConfiguration
GraphicsConfiguration that will be rendered to, this may be null.
config
,
Object[]
Arguments passed to paint
args
)

Creates the image to cache.

protected void
flush()

Clear the image cache

private static ImageCache
private GraphicsConfiguration
private Image
getImage(Object key, Component c, int baseWidth, int baseHeight, int w, int h, Object... args)

public void
paint(Component
Component rendering to, this may be null.
c
,
Graphics
Graphics to paint to
g
,
int
X-coordinate to render to
x
,
int
Y-coordinate to render to
y
,
int
Width to render in
w
,
int
Height to render in
h
,
Object...
Variable arguments that will be passed to paintToImage
args
)

Renders the cached image to the passed in Graphic.

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

protected void
paintImage(Component
Component painting to
c
,
Graphics
Graphics to paint to
g
,
int
X coordinate to paint to
x
,
int
Y coordinate to paint to
y
,
int
Width to paint to
w
,
int
Height to paint to
h
,
Image
Image to paint
image
,
Object[]
Arguments supplied to paint
args
)

Paints the image to the specified location.

protected abstract void
paintToImage(Component
Component painting to, may be null.
c
,
Image
Image to paint to
image
,
Graphics
Graphics to paint to, obtained from the passed in Image.
g
,
int
Width to paint to
w
,
int
Height to paint to
h
,
Object[]
Arguments supplied to paint
args
)

Paints the representation to cache to the supplied Graphics.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cacheMapback to summary
private static final Map<Object, ImageCache> cacheMap

Constructor Detail

CachedPainterback to summary
public CachedPainter(int cacheCount)

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

Parameters
cacheCount:int

Max number of images to cache

Method Detail

createImageback to summary
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

Component painting to

w:int

Width of image to create

h:int

Height to image to create

config:GraphicsConfiguration

GraphicsConfiguration that will be rendered to, this may be null.

args:Object[]

Arguments passed to paint

flushback to summary
protected void flush()

Clear the image cache

getCacheback to summary
private static ImageCache getCache(Object key)
getGraphicsConfigurationback to summary
private GraphicsConfiguration getGraphicsConfiguration(Component c)
getImageback to summary
private Image getImage(Object key, Component c, int baseWidth, int baseHeight, int w, int h, Object... args)
paintback to summary
public void paint(Component c, Graphics g, int x, int y, int w, int h, Object... args)

Renders the cached image to 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

Component rendering to, this may be null.

g:Graphics

Graphics to paint to

x:int

X-coordinate to render to

y:int

Y-coordinate to render to

w:int

Width to render in

h:int

Height to render in

args:Object[]

Variable arguments that will be passed to paintToImage

paint0back to summary
private void paint0(Component c, Graphics g, int x, int y, int w, int h, Object... args)
paintImageback to summary
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

Component painting to

g:Graphics

Graphics to paint to

x:int

X coordinate to paint to

y:int

Y coordinate to paint to

w:int

Width to paint to

h:int

Height to paint to

image:Image

Image to paint

args:Object[]

Arguments supplied to paint

paintToImageback to summary
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

Component painting to, may be null.

image:Image

Image to paint to

g:Graphics

Graphics to paint to, obtained from the passed in Image.

w:int

Width to paint to

h:int

Height to paint to

args:Object[]

Arguments supplied to paint

sun.swing back to summary

pack-priv Class CachedPainter.PainterMultiResolutionCachedImage

extends AbstractMultiResolutionImage
Class Inheritance

Field Summary

Modifier and TypeField and Description
private Object[]
private final int
private final int
private Component
c

Constructor Summary

AccessConstructor and Description
public
PainterMultiResolutionCachedImage(int baseWidth, int baseHeight)

Method Summary

Modifier and TypeMethod and Description
protected Image
getBaseImage()

Implements abstract java.awt.image.AbstractMultiResolutionImage.getBaseImage.

Return the base image representing the best version of the image for rendering at the default width and height.

public int
getHeight(ImageObserver observer)

Overrides java.awt.image.AbstractMultiResolutionImage.getHeight.

This method simply delegates to the same method on the base image and it is equivalent to: getBaseImage().getHeight(observer).

public Image
getResolutionVariant(double destWidth, double destHeight)

Implements java.awt.image.MultiResolutionImage.getResolutionVariant.

Gets a specific image that is the best variant to represent this logical image at the indicated size.

public List<Image>
getResolutionVariants()

Implements java.awt.image.MultiResolutionImage.getResolutionVariants.

Gets a readable list of all resolution variants.

public int
getWidth(ImageObserver observer)

Overrides java.awt.image.AbstractMultiResolutionImage.getWidth.

This method simply delegates to the same method on the base image and it is equivalent to: getBaseImage().getWidth(observer).

public void
Inherited from java.awt.image.AbstractMultiResolutionImage:
getGraphicsgetPropertygetSource

Field Detail

argsback to summary
private Object[] args
baseHeightback to summary
private final int baseHeight
baseWidthback to summary
private final int baseWidth
cback to summary
private Component c

Constructor Detail

PainterMultiResolutionCachedImageback to summary
public PainterMultiResolutionCachedImage(int baseWidth, int baseHeight)

Method Detail

getBaseImageback to summary
protected Image getBaseImage()

Implements abstract java.awt.image.AbstractMultiResolutionImage.getBaseImage.

Doc from java.awt.image.AbstractMultiResolutionImage.getBaseImage.

Return the base image representing the best version of the image for rendering at the default width and height.

Annotations
@Override
getHeightback to summary
public int getHeight(ImageObserver observer)

Overrides java.awt.image.AbstractMultiResolutionImage.getHeight.

Doc from java.awt.image.AbstractMultiResolutionImage.getHeight.

This method simply delegates to the same method on the base image and it is equivalent to: getBaseImage().getHeight(observer).

Annotations
@Override
getResolutionVariantback to summary
public Image getResolutionVariant(double destWidth, double destHeight)

Implements java.awt.image.MultiResolutionImage.getResolutionVariant.

Doc from java.awt.image.MultiResolutionImage.getResolutionVariant.

Gets a specific image that is the best variant to represent this logical image at the indicated size.

Annotations
@Override
getResolutionVariantsback to summary
public List<Image> getResolutionVariants()

Implements java.awt.image.MultiResolutionImage.getResolutionVariants.

Doc from java.awt.image.MultiResolutionImage.getResolutionVariants.

Gets a readable list of all resolution variants. The list must be nonempty and contain at least one resolution variant.

Note that many implementations might return an unmodifiable list.

Annotations
@Override
getWidthback to summary
public int getWidth(ImageObserver observer)

Overrides java.awt.image.AbstractMultiResolutionImage.getWidth.

Doc from java.awt.image.AbstractMultiResolutionImage.getWidth.

This method simply delegates to the same method on the base image and it is equivalent to: getBaseImage().getWidth(observer).

Annotations
@Override
setParamsback to summary
public void setParams(Component c, Object[] args)