Class ReflectionRenderer

java.lang.Object
org.jdesktop.swingx.graphics.ReflectionRenderer

public class ReflectionRenderer extends Object

A reflection renderer generates the reflection of a given picture. The result can be either the reflection itself, or an image containing both the source image and its reflection.

Reflection Properties

A reflection is defined by three properties:

  • opacity: the opacity of the reflection. You will usually change this valued according to the background color.
  • length: the length of the reflection. The length is a fraction of the height of the source image.
  • blur enabled: perfect reflections are hardly natural. You can blur the reflection to make it look a bit more natural.
You can set these properties using the provided mutators or the appropriate constructor. Here are two ways of creating a blurred reflection, with an opacity of 50% and a length of 30% the height of the original image:
 ReflectionRenderer renderer = new ReflectionRenderer(0.5f, 0.3f, true);
 // ..
 renderer = new ReflectionRenderer();
 renderer.setOpacity(0.5f);
 renderer.setLength(0.3f);
 renderer.setBlurEnabled(true);
 
The default constructor provides the following default values:
  • opacity: 35%
  • length: 40%
  • blur enabled: false

Generating Reflections

A reflection is generated as a BufferedImage from another BufferedImage. Once the renderer is set up, you must call createReflection(java.awt.image.BufferedImage) to actually generate the reflection:

 ReflectionRenderer renderer = new ReflectionRenderer();
 // renderer setup
 BufferedImage reflection = renderer.createReflection(bufferedImage);
 

The returned image contains only the reflection. You will have to append it to the source image at painting time to get a realistic results. You can also asks the rendered to return a picture composed of both the source image and its reflection:

 ReflectionRenderer renderer = new ReflectionRenderer();
 // renderer setup
 BufferedImage reflection = renderer.appendReflection(bufferedImage);
 

Properties Changes

This renderer allows to register property change listeners with addPropertyChangeListener(java.beans.PropertyChangeListener). Listening to properties changes is very useful when you embed the renderer in a graphical component and give the API user the ability to access the renderer. By listening to properties changes, you can easily repaint the component when needed.

Threading Issues

ReflectionRenderer is not guaranteed to be thread-safe.