org.apache.tapestry.contrib.services.impl
Class ShadowRenderer

java.lang.Object
  extended by org.apache.tapestry.contrib.services.impl.ShadowRenderer

public class ShadowRenderer
extends Object


Constructor Summary
ShadowRenderer(int size, float opacity, Color color)
          A shadow renderer needs three properties to generate shadows.
 
Method Summary
 BufferedImage createShadow(BufferedImage image)
          Generates the shadow for a given picture and the current properties of the renderer.
 Color getColor()
          Gets the color used by the renderer to generate shadows.
 float getOpacity()
          Gets the opacity used by the renderer to generate shadows.
static int[] getPixels(BufferedImage img, int x, int y, int w, int h, int[] pixels)
          Returns an array of pixels, stored as integers, from a BufferedImage.
 int getSize()
          Gets the size in pixel used by the renderer to generate shadows.
 void setColor(Color shadowColor)
          Sets the color used by the renderer to generate shadows.
 void setOpacity(float shadowOpacity)
          Sets the opacity used by the renderer to generate shadows.
static void setPixels(BufferedImage img, int x, int y, int w, int h, int[] pixels)
          Writes a rectangular area of pixels in the destination BufferedImage.
 void setSize(int shadowSize)
          Sets the size, in pixels, used by the renderer to generate shadows.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ShadowRenderer

public ShadowRenderer(int size,
                      float opacity,
                      Color color)

A shadow renderer needs three properties to generate shadows. These properties are:

Parameters:
size - the size of the shadow in pixels. Defines the fuzziness.
opacity - the opacity of the shadow.
color - the color of the shadow.
Method Detail

getColor

public Color getColor()

Gets the color used by the renderer to generate shadows.

Returns:
this renderer's shadow color

setColor

public void setColor(Color shadowColor)

Sets the color used by the renderer to generate shadows.

Consecutive calls to createShadow(java.awt.image.BufferedImage) will all use this color until it is set again.

If the color provided is null, the previous color will be retained.

Parameters:
shadowColor - the generated shadows color

getOpacity

public float getOpacity()

Gets the opacity used by the renderer to generate shadows.

The opacity is comprised between 0.0f and 1.0f; 0.0f being fully transparent and 1.0f fully opaque.

Returns:
this renderer's shadow opacity

setOpacity

public void setOpacity(float shadowOpacity)

Sets the opacity used by the renderer to generate shadows.

Consecutive calls to createShadow(java.awt.image.BufferedImage) will all use this opacity until it is set again.

The opacity is comprised between 0.0f and 1.0f; 0.0f being fully transparent and 1.0f fully opaque. If you provide a value out of these boundaries, it will be restrained to the closest boundary.

Parameters:
shadowOpacity - the generated shadows opacity

getSize

public int getSize()

Gets the size in pixel used by the renderer to generate shadows.

Returns:
this renderer's shadow size

setSize

public void setSize(int shadowSize)

Sets the size, in pixels, used by the renderer to generate shadows.

The size defines the blur radius applied to the shadow to create the fuzziness.

There is virtually no limit to the size. The size cannot be negative. If you provide a negative value, the size will be 0 instead.

Parameters:
shadowSize - the generated shadows size in pixels (fuzziness)

createShadow

public BufferedImage createShadow(BufferedImage image)

Generates the shadow for a given picture and the current properties of the renderer.

The generated image dimensions are computed as following:

 width  = imageWidth  + 2 * shadowSize
 height = imageHeight + 2 * shadowSize
 

Parameters:
image - the picture from which the shadow must be cast
Returns:
the picture containing the shadow of image

getPixels

public static int[] getPixels(BufferedImage img,
                              int x,
                              int y,
                              int w,
                              int h,
                              int[] pixels)

Returns an array of pixels, stored as integers, from a BufferedImage. The pixels are grabbed from a rectangular area defined by a location and two dimensions. Calling this method on an image of type different from BufferedImage.TYPE_INT_ARGB and BufferedImage.TYPE_INT_RGB will unmanage the image.

Parameters:
img - the source image
x - the x location at which to start grabbing pixels
y - the y location at which to start grabbing pixels
w - the width of the rectangle of pixels to grab
h - the height of the rectangle of pixels to grab
pixels - a pre-allocated array of pixels of size w*h; can be null
Returns:
pixels if non-null, a new array of integers otherwise
Throws:
IllegalArgumentException - is pixels is non-null and of length < w*h

setPixels

public static void setPixels(BufferedImage img,
                             int x,
                             int y,
                             int w,
                             int h,
                             int[] pixels)

Writes a rectangular area of pixels in the destination BufferedImage. Calling this method on an image of type different from BufferedImage.TYPE_INT_ARGB and BufferedImage.TYPE_INT_RGB will unmanage the image.

Parameters:
img - the destination image
x - the x location at which to start storing pixels
y - the y location at which to start storing pixels
w - the width of the rectangle of pixels to store
h - the height of the rectangle of pixels to store
pixels - an array of pixels, stored as integers
Throws:
IllegalArgumentException - is pixels is non-null and of length < w*h


Copyright © 2006-2008 Apache Software Foundation. All Rights Reserved.