Quaqua 8.0 2011-10-02

ch.randelshofer.quaqua.util
Class CachedPainter

java.lang.Object
  extended by ch.randelshofer.quaqua.util.CachedPainter
Direct Known Subclasses:
CachedImageBevelBorder, QuaquaNativeBorder, QuaquaNativeButtonStateBorder, QuaquaNativeButtonStateIcon, QuaquaPlacardButtonBorder, QuaquaSquareButtonBorder

public abstract class CachedPainter
extends java.lang.Object

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.
This class has been derived from javax.swing.plaf.metal.CachedPainter 1.2 04/02/15

Version:
$Id: CachedPainter.java 432 2011-08-07 08:39:32Z wrandelshofer $
Author:
Werner Randelshofer

Constructor Summary
CachedPainter(int cacheCount)
          Creates an instance of CachedPainter that will cache up to cacheCount images of this class.
 
Method Summary
protected  java.awt.Image createImage(java.awt.Component c, int w, int h, java.awt.GraphicsConfiguration config)
          Creates the image to cache.
 int getMaxCachedImageSize()
           
protected  void paint(java.awt.Component c, java.awt.Graphics g, int x, int y, int w, int h, java.lang.Object args)
          Renders the cached image to the the passed in Graphic.
protected  void paintImage(java.awt.Component c, java.awt.Graphics g, int x, int y, int w, int h, java.awt.Image image, java.lang.Object args)
          Paints the image to the specified location.
protected abstract  void paintToImage(java.awt.Component c, java.awt.Graphics g, int w, int h, java.lang.Object args)
          Paints the representation to cache to the supplied Graphics.
protected  void paintToImage(java.awt.Component c, java.awt.Image image, int w, int h, java.lang.Object args)
          Paints the representation to cache to the supplied Graphics.
 void setMaxCachedImageSize(int maxCachedImageSize)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachedPainter

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
Method Detail

paint

protected void paint(java.awt.Component c,
                     java.awt.Graphics g,
                     int x,
                     int y,
                     int w,
                     int h,
                     java.lang.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.


paintToImage

protected void paintToImage(java.awt.Component c,
                            java.awt.Image image,
                            int w,
                            int h,
                            java.lang.Object args)
Paints the representation to cache to the supplied Graphics.

Parameters:
c - Component painting to
image - Image to paint to
w - Width to paint to
h - Height to paint to
args - Arguments supplied to paint

paintToImage

protected abstract void paintToImage(java.awt.Component c,
                                     java.awt.Graphics g,
                                     int w,
                                     int h,
                                     java.lang.Object args)
Paints the representation to cache to the supplied Graphics.

Parameters:
c - Component painting to
g - Graphics to paint to
w - Width to paint to
h - Height to paint to
args - Arguments supplied to paint

paintImage

protected void paintImage(java.awt.Component c,
                          java.awt.Graphics g,
                          int x,
                          int y,
                          int w,
                          int h,
                          java.awt.Image image,
                          java.lang.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

createImage

protected java.awt.Image createImage(java.awt.Component c,
                                     int w,
                                     int h,
                                     java.awt.GraphicsConfiguration config)
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.

getMaxCachedImageSize

public int getMaxCachedImageSize()

setMaxCachedImageSize

public void setMaxCachedImageSize(int maxCachedImageSize)

Copyright 2003-2007 (c) Werner Randelshofer.
All rights reserved.