Quaqua 8.0 2011-10-02

ch.randelshofer.quaqua.border
Class CachedImageBevelBorder

java.lang.Object
  extended by ch.randelshofer.quaqua.util.CachedPainter
      extended by ch.randelshofer.quaqua.border.CachedImageBevelBorder
All Implemented Interfaces:
javax.swing.border.Border
Direct Known Subclasses:
CachedImageBevelBorder.UIResource

public class CachedImageBevelBorder
extends CachedPainter
implements javax.swing.border.Border

Draws a filled bevel border using an image and insets. The image must consist of a bevel and a fill area. Volatile images of the border are cached to speed up drawing.

The insets and the size of the image are used do determine which parts of the image shall be used to draw the corners and edges of the bevel as well the fill area.

For example, if you provide an image of size 10,10 and a insets of size 2, 2, 4, 4, then the corners of the border are made up of top left: 2,2, top right: 2,4, bottom left: 2,4, bottom right: 4,4 rectangle of the image. The inner area of the image is used to fill the inner area.

Version:
$Id: CachedImageBevelBorder.java 414 2011-07-29 20:55:05Z wrandelshofer $
Author:
Werner Randelshofer

Nested Class Summary
static class CachedImageBevelBorder.UIResource
           
 
Constructor Summary
CachedImageBevelBorder(java.awt.Image img, java.awt.Insets borderInsets)
          Creates a new instance with the given image and insets.
CachedImageBevelBorder(java.awt.Image img, java.awt.Insets imageInsets, java.awt.Insets borderInsets)
          Creates a new instance with the given image and insets.
CachedImageBevelBorder(java.awt.Image img, java.awt.Insets imageInsets, java.awt.Insets borderInsets, boolean fillContentArea)
          Creates a new instance with the given image and insets.
 
Method Summary
protected  java.awt.Image createImage(java.awt.Component c, int w, int h, java.awt.GraphicsConfiguration config)
          Creates the image to cache.
 java.awt.Insets getBorderInsets(java.awt.Component c)
          Returns the insets of the border.
 boolean isBorderOpaque()
          Returns true if the border is opaque.
 void paintBorder(java.awt.Component c, java.awt.Graphics gr, int x, int y, int width, int height)
          Paints the bevel image for the specified component with the specified position and size.
protected  void paintToImage(java.awt.Component c, java.awt.Graphics gr, int width, int height, java.lang.Object args)
          Paints the representation to cache to the supplied Graphics.
 
Methods inherited from class ch.randelshofer.quaqua.util.CachedPainter
getMaxCachedImageSize, paint, paintImage, paintToImage, setMaxCachedImageSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachedImageBevelBorder

public CachedImageBevelBorder(java.awt.Image img,
                              java.awt.Insets borderInsets)
Creates a new instance with the given image and insets. The image has the same insets as the border.


CachedImageBevelBorder

public CachedImageBevelBorder(java.awt.Image img,
                              java.awt.Insets imageInsets,
                              java.awt.Insets borderInsets)
Creates a new instance with the given image and insets. The image has different insets than the border.


CachedImageBevelBorder

public CachedImageBevelBorder(java.awt.Image img,
                              java.awt.Insets imageInsets,
                              java.awt.Insets borderInsets,
                              boolean fillContentArea)
Creates a new instance with the given image and insets. The image has different insets than the border.

Method Detail

isBorderOpaque

public boolean isBorderOpaque()
Returns true if the border is opaque. This implementation always returns false.

Specified by:
isBorderOpaque in interface javax.swing.border.Border

getBorderInsets

public java.awt.Insets getBorderInsets(java.awt.Component c)
Returns the insets of the border.

Specified by:
getBorderInsets in interface javax.swing.border.Border
Parameters:
c - the component for which this border insets value applies

paintBorder

public void paintBorder(java.awt.Component c,
                        java.awt.Graphics gr,
                        int x,
                        int y,
                        int width,
                        int height)
Paints the bevel image for the specified component with the specified position and size.

Specified by:
paintBorder in interface javax.swing.border.Border
Parameters:
c - the component for which this border is being painted
gr - the paint graphics
x - the x position of the painted border
y - the y position of the painted border
width - the width of the painted border
height - the height of the painted border

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 a translucent image.

Overrides:
createImage in class CachedPainter
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.

paintToImage

protected void paintToImage(java.awt.Component c,
                            java.awt.Graphics gr,
                            int width,
                            int height,
                            java.lang.Object args)
Description copied from class: CachedPainter
Paints the representation to cache to the supplied Graphics.

Specified by:
paintToImage in class CachedPainter
Parameters:
c - Component painting to
gr - Graphics to paint to
width - Width to paint to
height - Height to paint to
args - Arguments supplied to paint

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