|
JIDE 3.5.15 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.jidesoft.swing.ShadowFactory
public class ShadowFactory
A shadow factory generates a drop shadow for any given picture, respecting the transparency channel if present. The resulting picture contains the shadow only and to create a drop shadow effect you will need to stack the original picture and the shadow generated by the factory.
A shadow is defined by three properties:
ShadowFactory factory = new ShadowFactory(10, 0.5f, Color.GREEN); // .. factory = new ShadowFactory(); factory.setSize(10); factory.setOpacity(0.5f); factory.setColor(Color.GREEN);The default constructor provides the following default values:
The factory provides two shadow generation algorithms: fast quality blur and high quality blur. You can select your preferred algorithm by setting the appropriate rendering hint:
ShadowFactory factory = new ShadowFactory(); factory.setRenderingHint(ShadowFactory.KEY_BLUR_QUALITY, ShadowFactory.VALUE_BLUR_QUALITY_HIGH);The default rendering algorithm is
VALUE_BLUR_QUALITY_FAST
. The current implementation should provide the same quality with both algorithms but performances are guaranteed to be better (about 30 times faster) with the fast quality blur.
A shadow is generated as a
BufferedImage
from another BufferedImage
. Once the factory is set up, you must call createShadow(java.awt.image.BufferedImage)
to actually generate the shadow:
ShadowFactory factory = new ShadowFactory(); // factory setup BufferedImage shadow = factory.createShadow(bufferedImage);The resulting image is of type
BufferedImage.TYPE_INT_ARGB
. Both dimensions of this image are larger
than original image's: This factory allows to register property change listeners with addPropertyChangeListener(java.beans.PropertyChangeListener)
. Listening to properties changes is very useful when you embed the factory in a graphical
component and give the API user the ability to access the factory. By listening to properties changes, you can easily
repaint the component when needed.
ShadowFactory
is not guaranteed to
be thread-safe.
Field Summary | |
---|---|
static String |
COLOR_CHANGED_PROPERTY
Identifies a change to the color used to render the shadow. |
static String |
KEY_BLUR_QUALITY
Key for the blur quality rendering hint. |
static String |
OPACITY_CHANGED_PROPERTY
Identifies a change to the opacity used to render the shadow. |
static String |
SIZE_CHANGED_PROPERTY
Identifies a change to the size used to render the shadow. |
static String |
VALUE_BLUR_QUALITY_FAST
Selects the fast rendering algorithm. |
static String |
VALUE_BLUR_QUALITY_HIGH
Selects the high quality rendering algorithm. |
Constructor Summary | |
---|---|
ShadowFactory()
Creates a default good looking shadow generator. |
|
ShadowFactory(int size,
float opacity,
Color color)
A shadow factory needs three properties to generate shadows. |
Method Summary | |
---|---|
void |
addPropertyChangeListener(PropertyChangeListener listener)
Add a PropertyChangeListener to the listener list. |
BufferedImage |
createShadow(BufferedImage image)
Generates the shadow for a given picture and the current properties of the factory. |
Color |
getColor()
Gets the color used by the factory to generate shadows. |
float |
getOpacity()
Gets the opacity used by the factory to generate shadows. |
int |
getSize()
Gets the size in pixel used by the factory to generate shadows. |
void |
removePropertyChangeListener(PropertyChangeListener listener)
Remove a PropertyChangeListener from the listener list. |
void |
setColor(Color shadowColor)
Sets the color used by the factory to generate shadows. |
void |
setOpacity(float shadowOpacity)
Sets the opacity used by the factory to generate shadows. |
void |
setRenderingHint(Object key,
Object value)
Maps the specified rendering hint key to the specified value in this
SahdowFactory object. |
void |
setSize(int shadowSize)
Sets the size, in pixels, used by the factory to generate shadows. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String KEY_BLUR_QUALITY
Key for the blur quality rendering hint.
public static final String VALUE_BLUR_QUALITY_FAST
Selects the fast rendering algorithm. This is the default rendering hint for
KEY_BLUR_QUALITY
.
public static final String VALUE_BLUR_QUALITY_HIGH
Selects the high quality rendering algorithm. With current implementation, This algorithm does not guarantee a better rendering quality and should not be used.
public static final String SIZE_CHANGED_PROPERTY
Identifies a change to the size used to render the shadow.
When the property change event is fired, the
old value and the new value are provided as Integer
instances.
public static final String OPACITY_CHANGED_PROPERTY
Identifies a change to the opacity used to render the shadow.
When the property change event is fired,
the old value and the new value are provided as Float
instances.
public static final String COLOR_CHANGED_PROPERTY
Identifies a change to the color used to render the shadow.
Constructor Detail |
---|
public ShadowFactory()
Creates a default good looking shadow generator. The default shadow factory provides the following default values:
These properties provide a regular, good looking shadow.
public ShadowFactory(int size, float opacity, Color color)
A shadow factory needs three properties to generate shadows. These properties are:
Besides these properties you can set rendering hints to control the rendering process. The default rendering hints let the factory use the fastest shadow generation algorithm.
size
- The size of the shadow in pixels. Defines the fuzziness.opacity
- The opacity of the shadow.color
- The color of the shadow.setRenderingHint(Object, Object)
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
- public void setRenderingHint(Object key, Object value)
Maps the specified rendering hint key
to the specified value
in this
SahdowFactory
object.
key
- The rendering hint keyvalue
- The rendering hint valuepublic Color getColor()
Gets the color used by the factory to generate shadows.
public void setColor(Color shadowColor)
Sets the color used by the factory 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.
shadowColor
- the generated shadows colorpublic float getOpacity()
Gets the opacity used by the factory to generate shadows.
The opacity is comprised between 0.0f and 1.0f; 0.0f being fully transparent and 1.0f fully opaque.
public void setOpacity(float shadowOpacity)
Sets the opacity used by the factory to generate shadows.
Consecutive calls to createShadow(java.awt.image.BufferedImage)
will all use this color 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.
shadowOpacity
- the generated shadows opacitypublic int getSize()
Gets the size in pixel used by the factory to generate shadows.
public void setSize(int shadowSize)
Sets the size, in pixels, used by the factory 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 but it has an impact on shadow generation performances. The greater this value, the longer it will take to generate the shadow. Remember the generated shadow image dimensions are computed as follow:
shadowSize
- the generated shadows size in pixels (fuzziness)public BufferedImage createShadow(BufferedImage image)
Generates the shadow for a given picture and the current properties of the factory.
The generated shadow image dimensions are computed as follow:
The time taken by a call to this method depends on the size of the shadow, the larger the longer it takes, and on the selected rendering algorithm.
createShadow
in interface ShadowRenderer
image
- the picture from which the shadow must be cast
image
|
JIDE 3.5.15 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |