final Map<String, Painter> customPainters )
{
try
{
final SupportedComponent type = getSupportedComponentTypeImpl ( component );
final ComponentStyle style = getComponentStyleImpl ( component, type );
final ComponentUI ui = getComponentUIImpl ( component );
// Installing painters
for ( final PainterStyle painterStyle : style.getPainters () )
{
// Painter ID
final String painterId = painterStyle.getId ();
// Retrieving painter to install into component
// Custom painter can be null - that will just mean that component should not have painter installed
final Painter painter;
if ( customPainters != null && customPainters.containsKey ( painterId ) )
{
// Using provided custom painter
// This might be set using Web-component "set...Painter"-like methods
painter = customPainters.get ( painterId );
}
else
{
// Creating painter instance
// Be aware that all painters must have default constructor
painter = ReflectUtils.createInstanceSafely ( painterStyle.getPainterClass () );
if ( painter == null )
{
throw new StyleException (
"Unable to create painter \"" + painterStyle.getPainterClass () + "\" for component: " + component );
}
// Applying painter properties
// These properties are applied only for style-provided painters
// Customly provided painters are not affected by these properties to avoid unexpected changes in them
final Map<String, Object> cpp = getCustomPainterProperties ( customPainterProperties, painterStyle, painterId );
applyProperties ( painter, painterStyle.getProperties (), cpp );
}
// Installing painter into the UI
final String setterMethod = ReflectUtils.getSetterMethodName ( painterId );
ReflectUtils.callMethod ( ui, setterMethod, painter );
}
// Applying UI properties
// todo Check whether properties should be applied or not somehow? Additional settings?
applyProperties ( ui, style.getUIProperties (), null );
// Applying component properties
// todo Check whether properties should be applied or not somehow? Additional settings?
applyProperties ( component, style.getComponentProperties (), null );
return true;
}
catch ( final Throwable e )
{