* @param rc the relevant <code>RenderContext</code>
* @param textComponent the text component
* @return the style
*/
protected CssStyle createBaseCssStyle(RenderContext rc, TextComponent textComponent) {
CssStyle cssStyle = new CssStyle();
boolean renderEnabled = textComponent.isRenderEnabled();
Border border;
Color foreground, background;
Font font;
FillImage backgroundImage;
if (!renderEnabled) {
// Retrieve disabled style information.
background = (Color) textComponent.getRenderProperty(TextComponent.PROPERTY_DISABLED_BACKGROUND);
backgroundImage = (FillImage) textComponent.getRenderProperty(TextComponent.PROPERTY_DISABLED_BACKGROUND_IMAGE);
border = (Border) textComponent.getRenderProperty(TextComponent.PROPERTY_DISABLED_BORDER);
font = (Font) textComponent.getRenderProperty(TextComponent.PROPERTY_DISABLED_FONT);
foreground = (Color) textComponent.getRenderProperty(TextComponent.PROPERTY_DISABLED_FOREGROUND);
// Fallback to normal styles.
if (background == null) {
background = (Color) textComponent.getRenderProperty(TextComponent.PROPERTY_BACKGROUND);
if (backgroundImage == null) {
// Special case:
// Disabled background without disabled background image will render disabled background instead of
// normal background image.
backgroundImage = (FillImage) textComponent.getRenderProperty(TextComponent.PROPERTY_BACKGROUND_IMAGE);
}
}
if (border == null) {
border = (Border) textComponent.getRenderProperty(TextComponent.PROPERTY_BORDER);
}
if (font == null) {
font = (Font) textComponent.getRenderProperty(TextComponent.PROPERTY_FONT);
}
if (foreground == null) {
foreground = (Color) textComponent.getRenderProperty(TextComponent.PROPERTY_FOREGROUND);
}
} else {
border = (Border) textComponent.getRenderProperty(TextComponent.PROPERTY_BORDER);
foreground = (Color) textComponent.getRenderProperty(TextComponent.PROPERTY_FOREGROUND);
background = (Color) textComponent.getRenderProperty(TextComponent.PROPERTY_BACKGROUND);
font = (Font) textComponent.getRenderProperty(TextComponent.PROPERTY_FONT);
backgroundImage = (FillImage) textComponent.getRenderProperty(TextComponent.PROPERTY_BACKGROUND_IMAGE);
}
Alignment alignment = (Alignment) textComponent.getRenderProperty(TextComponent.PROPERTY_ALIGNMENT);
if (alignment != null) {
int horizontalAlignment = AlignmentRender.getRenderedHorizontal(alignment, textComponent);
switch (horizontalAlignment) {
case Alignment.LEFT:
cssStyle.setAttribute("text-align", "left");
break;
case Alignment.CENTER:
cssStyle.setAttribute("text-align", "center");
break;
case Alignment.RIGHT:
cssStyle.setAttribute("text-align", "right");
break;
}
}
LayoutDirectionRender.renderToStyle(cssStyle, textComponent.getLayoutDirection(), textComponent.getLocale());
BorderRender.renderToStyle(cssStyle, border);
ColorRender.renderToStyle(cssStyle, foreground, background);
FontRender.renderToStyle(cssStyle, font);
FillImageRender.renderToStyle(cssStyle, rc, this, textComponent, IMAGE_ID_BACKGROUND, backgroundImage,
FillImageRender.FLAG_DISABLE_FIXED_MODE);
InsetsRender.renderToStyle(cssStyle, "padding", (Insets) textComponent.getRenderProperty(TextComponent.PROPERTY_INSETS));
Extent width = (Extent) textComponent.getRenderProperty(TextComponent.PROPERTY_WIDTH);
Extent height = (Extent) textComponent.getRenderProperty(TextComponent.PROPERTY_HEIGHT);
if (width != null) {
cssStyle.setAttribute("width", ExtentRender.renderCssAttributeValue(width));
}
if (height != null) {
cssStyle.setAttribute("height", ExtentRender.renderCssAttributeValue(height));
}
return cssStyle;
}