|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jdesktop.swingx.graphics.ReflectionRenderer
public class ReflectionRenderer
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.
A reflection is defined by three properties:
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:
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);
This renderer allows to register property change listeners with
addPropertyChangeListener(java.beans.PropertyChangeListener)
. Listening to properties changes is very
useful when you emebed 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.
ReflectionRenderer
is not guaranteed to be thread-safe.
Field Summary | |
---|---|
static String |
BLUR_ENABLED_CHANGED_PROPERTY
Identifies a change to the blurring of the rendered reflection. |
static String |
LENGTH_CHANGED_PROPERTY
Identifies a change to the length of the rendered reflection. |
static String |
OPACITY_CHANGED_PROPERTY
Identifies a change to the opacity used to render the reflection. |
Constructor Summary | |
---|---|
ReflectionRenderer()
Creates a default good looking reflections generator. |
|
ReflectionRenderer(float opacity)
Creates a default good looking reflections generator with the specified opacity. |
|
ReflectionRenderer(float opacity,
float length,
boolean blurEnabled)
Creates a reflections generator with the specified properties. |
Method Summary | |
---|---|
void |
addPropertyChangeListener(PropertyChangeListener listener)
Add a PropertyChangeListener to the listener list. |
BufferedImage |
appendReflection(BufferedImage image)
Returns the source image and its reflection. |
BufferedImage |
createReflection(BufferedImage image)
Returns the reflection of the source image. |
int |
getBlurRadius()
Returns the radius, in pixels, of the blur used by this renderer when isBlurEnabled() is true. |
int |
getEffectiveBlurRadius()
Returns the effective radius, in pixels, of the blur used by this renderer when isBlurEnabled() is true. |
float |
getLength()
Returns the length of the reflection. |
float |
getOpacity()
Gets the opacity used by the factory to generate reflections. |
boolean |
isBlurEnabled()
Returns true if the blurring of the reflection is enabled, false otherwise. |
void |
removePropertyChangeListener(PropertyChangeListener listener)
Remove a PropertyChangeListener from the listener list. |
void |
setBlurEnabled(boolean blurEnabled)
Setting the blur to true will enable the blurring of the reflection when createReflection(java.awt.image.BufferedImage) is invoked. |
void |
setBlurRadius(int radius)
Sets the radius, in pixels, of the blur used by this renderer when isBlurEnabled() is true. |
void |
setLength(float length)
Sets the length of the reflection, as a fraction of the height of the source image. |
void |
setOpacity(float opacity)
Sets the opacity used by the factory to generate reflections. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String OPACITY_CHANGED_PROPERTY
Identifies a change to the opacity used to render the reflection.
public static final String LENGTH_CHANGED_PROPERTY
Identifies a change to the length of the rendered reflection.
public static final String BLUR_ENABLED_CHANGED_PROPERTY
Identifies a change to the blurring of the rendered reflection.
Constructor Detail |
---|
public ReflectionRenderer()
Creates a default good looking reflections generator. The default reflection renderer provides the following default values:
These properties provide a regular, good looking reflection.
getOpacity()
,
setOpacity(float)
,
getLength()
,
setLength(float)
,
isBlurEnabled()
,
setBlurEnabled(boolean)
,
getBlurRadius()
,
setBlurRadius(int)
public ReflectionRenderer(float opacity)
Creates a default good looking reflections generator with the specified opacity. The default reflection renderer provides the following default values:
opacity
- the opacity of the reflection, between 0.0 and 1.0getOpacity()
,
setOpacity(float)
,
getLength()
,
setLength(float)
,
isBlurEnabled()
,
setBlurEnabled(boolean)
,
getBlurRadius()
,
setBlurRadius(int)
public ReflectionRenderer(float opacity, float length, boolean blurEnabled)
Creates a reflections generator with the specified properties. Both opacity and length are numbers between 0.0 (0%) and 1.0 (100%). If the provided numbers are outside this range, they are clamped.
Enabling the blur generates a different kind of reflections that might look more natural. The default blur radius is 1 pixel
opacity
- the opacity of the reflectionlength
- the length of the reflectionblurEnabled
- if true, the reflection is blurredgetOpacity()
,
setOpacity(float)
,
getLength()
,
setLength(float)
,
isBlurEnabled()
,
setBlurEnabled(boolean)
,
getBlurRadius()
,
setBlurRadius(int)
Method Detail |
---|
public void addPropertyChangeListener(PropertyChangeListener listener)
Add a PropertyChangeListener to the listener list. The listener is
registered for all properties. The same listener object may be added
more than once, and will be called as many times as it is added. If
listener
is null, no exception is thrown and no action
is taken.
listener
- the PropertyChangeListener to be addedpublic void removePropertyChangeListener(PropertyChangeListener listener)
Remove a PropertyChangeListener from the listener list. This removes
a PropertyChangeListener that was registered for all properties. If
listener
was added more than once to the same event source,
it will be notified one less time after being removed. If
listener
is null, or was never added, no exception is thrown
and no action is taken.
listener
- the PropertyChangeListener to be removedpublic float getOpacity()
Gets the opacity used by the factory to generate reflections.
The opacity is comprised between 0.0f and 1.0f; 0.0f being fully transparent and 1.0f fully opaque.
getOpacity()
,
createReflection(java.awt.image.BufferedImage)
,
appendReflection(java.awt.image.BufferedImage)
public void setOpacity(float opacity)
Sets the opacity used by the factory to generate reflections.
Consecutive calls to createReflection(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.
opacity
- the generated reflection opacitysetOpacity(float)
,
createReflection(java.awt.image.BufferedImage)
,
appendReflection(java.awt.image.BufferedImage)
public float getLength()
Returns the length of the reflection. The result is a number between 0.0 and 1.0. This number is the fraction of the height of the source image that is used to compute the size of the reflection.
setLength(float)
,
createReflection(java.awt.image.BufferedImage)
,
appendReflection(java.awt.image.BufferedImage)
public void setLength(float length)
Sets the length of the reflection, as a fraction of the height of the source image.
Consecutive calls to createReflection(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.
length
- the length of the reflection, as a fraction of the source
image heightgetLength()
,
createReflection(java.awt.image.BufferedImage)
,
appendReflection(java.awt.image.BufferedImage)
public boolean isBlurEnabled()
Returns true if the blurring of the reflection is enabled, false otherwise. When blurring is enabled, the reflection is blurred to look more natural.
setBlurEnabled(boolean)
,
createReflection(java.awt.image.BufferedImage)
,
appendReflection(java.awt.image.BufferedImage)
public void setBlurEnabled(boolean blurEnabled)
Setting the blur to true will enable the blurring of the reflection
when createReflection(java.awt.image.BufferedImage)
is invoked.
Enabling the blurring of the reflection can yield to more natural results which may or may not be better looking, depending on the source picture.
Consecutive calls to createReflection(java.awt.image.BufferedImage)
will all use this
opacity until it is set again.
blurEnabled
- true to enable the blur, false otherwiseisBlurEnabled()
,
createReflection(java.awt.image.BufferedImage)
,
appendReflection(java.awt.image.BufferedImage)
public int getEffectiveBlurRadius()
Returns the effective radius, in pixels, of the blur used by this
renderer when isBlurEnabled()
is true.
isBlurEnabled
is trueisBlurEnabled()
,
setBlurEnabled(boolean)
,
setBlurRadius(int)
,
getBlurRadius()
public int getBlurRadius()
Returns the radius, in pixels, of the blur used by this renderer when
isBlurEnabled()
is true.
isBlurEnabled
is trueisBlurEnabled()
,
setBlurEnabled(boolean)
,
setBlurRadius(int)
,
getEffectiveBlurRadius()
public void setBlurRadius(int radius)
Sets the radius, in pixels, of the blur used by this renderer when
isBlurEnabled()
is true. This radius changes the size of the
generated image when blurring is applied.
radius
- the radius, in pixels, of the blurisBlurEnabled()
,
setBlurEnabled(boolean)
,
getBlurRadius()
public BufferedImage appendReflection(BufferedImage image)
Returns the source image and its reflection. The appearance of the reflection is defined by the opacity, the length and the blur properties.
*The width of the generated image will be augmented when
isBlurEnabled()
is true. The generated image will have the width
of the source image plus twice the effective blur radius (see
getEffectiveBlurRadius()
). The default blur radius is 1 so the
width will be augmented by 6. You might need to take this into account
at drawing time.
The returned image height depends on the value returned by
getLength()
and getEffectiveBlurRadius()
. For instance,
if the length is 0.5 (or 50%) and the source image is 480 pixels high,
then the reflection will be 246 (480 * 0.5 + 3 * 2) pixels high.
You can create only the reflection by calling
createReflection(java.awt.image.BufferedImage)
.
image
- the source image
createReflection(java.awt.image.BufferedImage)
public BufferedImage createReflection(BufferedImage image)
Returns the reflection of the source image. The appearance of the reflection is defined by the opacity, the length and the blur properties.
*The width of the generated image will be augmented when
isBlurEnabled()
is true. The generated image will have the width
of the source image plus twice the effective blur radius (see
getEffectiveBlurRadius()
). The default blur radius is 1 so the
width will be augmented by 6. You might need to take this into account
at drawing time.
The returned image height depends on the value returned by
getLength()
and getEffectiveBlurRadius()
. For instance,
if the length is 0.5 (or 50%) and the source image is 480 pixels high,
then the reflection will be 246 (480 * 0.5 + 3 * 2) pixels high.
The returned image contains only
the reflection. You will have to append it to the source image to produce
the illusion of a reflective environement. The method
appendReflection(java.awt.image.BufferedImage)
provides an easy
way to create an image containing both the source and the reflection.
image
- the source image
appendReflection(java.awt.image.BufferedImage)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |