Java Doc for ShadowFactory.java in  » Swing-Library » jide-common » com » jidesoft » swing » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Swing Library » jide common » com.jidesoft.swing 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   com.jidesoft.swing.ShadowFactory

ShadowFactory
public class ShadowFactory (Code)

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.

Shadow Properties

A shadow is defined by three properties:

  • size: The size, in pixels, of the shadow. This property also defines the fuzzyness.
  • opacity: The opacity, between 0.0 and 1.0, of the shadow.
  • color: The color of the shadow. Shadows are not meant to be black only.
You can set these properties using the provided mutaters or the appropriate constructor. Here are two ways of creating a green shadow of size 10 and with an opacity of 50%:
 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:
  • size: 5 pixels
  • opacity: 50%
  • color: Black

Shadow Quality

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 algorihtm 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.

Generating a Shadow

A shadow is generated as a BufferedImage from another BufferedImage. Once the factory is set up, you must call ShadowFactory.createShadow 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:
  • new width = original width + 2 * shadow size
  • new height = original height + 2 * shadow size
This must be taken into account when you need to create a drop shadow effect.

Properties Changes

This factory allows to register property change listeners with ShadowFactory.addPropertyChangeListener . Listening to properties changes is very useful when you emebed 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.

Threading Issues

ShadowFactory is not guaranteed to be thread-safe.


author:
   Romain Guy
author:
   Sebastien Petrucci


Field Summary
final public static  StringCOLOR_CHANGED_PROPERTY
    
final public static  StringKEY_BLUR_QUALITY
    
final public static  StringOPACITY_CHANGED_PROPERTY
    
final public static  StringSIZE_CHANGED_PROPERTY
    
final public static  StringVALUE_BLUR_QUALITY_FAST
    

Selects the fast rendering algorithm.

final public static  StringVALUE_BLUR_QUALITY_HIGH
    

Selects the high quality rendering algorithm.


Constructor Summary
public  ShadowFactory()
    

Creates a default good looking shadow generator.

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

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

  • size: The size, in pixels, of the shadow.

Method Summary
public  voidaddPropertyChangeListener(PropertyChangeListener listener)
    

Add a PropertyChangeListener to the listener list.

public  BufferedImagecreateShadow(BufferedImage image)
    
public  ColorgetColor()
    
public  floatgetOpacity()
    
public  intgetSize()
    
public  voidremovePropertyChangeListener(PropertyChangeListener listener)
    

Remove a PropertyChangeListener from the listener list.

public  voidsetColor(Color shadowColor)
    
public  voidsetOpacity(float shadowOpacity)
    

Sets the opacity used by the factory to generate shadows.

Consecutive calls to ShadowFactory.createShadow 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.

public  voidsetRenderingHint(Object key, Object value)
    
public  voidsetSize(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.


Field Detail
COLOR_CHANGED_PROPERTY
final public static String COLOR_CHANGED_PROPERTY(Code)

Identifies a change to the color used to render the shadow.




KEY_BLUR_QUALITY
final public static String KEY_BLUR_QUALITY(Code)

Key for the blur quality rendering hint.




OPACITY_CHANGED_PROPERTY
final public static String OPACITY_CHANGED_PROPERTY(Code)

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.




SIZE_CHANGED_PROPERTY
final public static String SIZE_CHANGED_PROPERTY(Code)

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.




VALUE_BLUR_QUALITY_FAST
final public static String VALUE_BLUR_QUALITY_FAST(Code)

Selects the fast rendering algorithm. This is the default rendering hint for KEY_BLUR_QUALITY.




VALUE_BLUR_QUALITY_HIGH
final public static String VALUE_BLUR_QUALITY_HIGH(Code)

Selects the high quality rendering algorithm. With current implementation, This algorithm does not guarantee a better rendering quality and should not be used.





Constructor Detail
ShadowFactory
public ShadowFactory()(Code)

Creates a default good looking shadow generator. The default shadow factory provides the following default values:

  • size: 5 pixels
  • opacity: 50%
  • color: Black
  • rendering quality: VALUE_BLUR_QUALITY_FAST

These properties provide a regular, good looking shadow.




ShadowFactory
public ShadowFactory(int size, float opacity, Color color)(Code)

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

  • size: The size, in pixels, of the shadow. This property also defines the fuzzyness.
  • opacity: The opacity, between 0.0 and 1.0, of the shadow.
  • color: The color of the shadow. Shadows are not meant to be black only.

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.


Parameters:
  size - The size of the shadow in pixels. Defines the fuzziness.
Parameters:
  opacity - The opacity of the shadow.
Parameters:
  color - The color of the shadow.
See Also:   ShadowFactory.setRenderingHint(Object,Object)




Method Detail
addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener listener)(Code)

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.


Parameters:
  listener - the PropertyChangeListener to be added



createShadow
public BufferedImage createShadow(BufferedImage image)(Code)

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

The generated shadow image dimensions are computed as follow:

  • new width = original width + 2 * shadow size
  • new height = original height + 2 * shadow size

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.


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



getColor
public Color getColor()(Code)

Gets the color used by the factory to generate shadows.

this factory's shadow color



getOpacity
public float getOpacity()(Code)

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.

this factory's shadow opacity



getSize
public int getSize()(Code)

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

this factory's shadow size



removePropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener listener)(Code)

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.


Parameters:
  listener -



setColor
public void setColor(Color shadowColor)(Code)

Sets the color used by the factory to generate shadows.

Consecutive calls to ShadowFactory.createShadow 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



setOpacity
public void setOpacity(float shadowOpacity)(Code)

Sets the opacity used by the factory to generate shadows.

Consecutive calls to ShadowFactory.createShadow 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.


Parameters:
  shadowOpacity - the generated shadows opacity



setRenderingHint
public void setRenderingHint(Object key, Object value)(Code)

Maps the specified rendering hint key to the specified value in this SahdowFactory object.


Parameters:
  key - The rendering hint key
Parameters:
  value - The rendering hint value



setSize
public void setSize(int shadowSize)(Code)

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:

  • new width = original width + 2 * shadow size
  • new height = original height + 2 * shadow 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)



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.