in trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/desktop/ColorPaletteRenderer.java [88:326]
private void _renderColorPalette(
UIXRenderingContext context,
UINode node,
List<Color> colorData,
int width,
int height) throws IOException
{
int colorCount = colorData.size();
if (colorCount > 0)
{
if (width <= 0 && height <= 0)
{
// default to a square
width = height = (int)Math.ceil(Math.sqrt(colorCount));
}
else if (width <= 0) // height > 0
{
// cast to double to avoid integer math
width = (int)Math.ceil(colorCount / (double)height);
}
else if (height <= 0) // width > 0
{
// cast to double to avoid integer math
height = (int)Math.ceil(colorCount / (double)width);
}
}
// if colors were provided, width and height must be determined
assert (colorCount == 0 || (width > 0 && height > 0));
boolean isNetscape = isNetscape(context);
ResponseWriter writer = context.getResponseWriter();
writer.startElement("table", null);
renderLayoutTableAttributes(context, "0", "1", null);
if (!isNetscape)
{
renderStyleClassAttribute(context, COLOR_PALETTE_STYLE_CLASS);
}
else // isNetscape
{
writer.startElement("tr", null);
writer.startElement("td", null);
renderStyleClassAttribute(context, COLOR_PALETTE_STYLE_CLASS);
writer.startElement("table", null);
renderLayoutTableAttributes(context, "0", "1", null);
}
Color color;
int index;
Object onColorSelect = getOnColorSelect(context, node);
boolean hasOnColorSelect = (onColorSelect != null);
boolean scriptWritten =
Boolean.TRUE.equals(getRenderingProperty(context,
_SCRIPT_WRITTEN_KEY));
// render dependent script
if (!scriptWritten)
{
// mark the script as written
setRenderingProperty(context, _SCRIPT_WRITTEN_KEY, Boolean.TRUE);
writer.startElement("script", null);
XhtmlLafRenderer.renderScriptDeferAttribute(context);
// Bug #3426092:
// render the type="text/javascript" attribute in accessibility mode
XhtmlLafRenderer.renderScriptTypeAttribute(context);
if (isNetscape)
{
writer.write(_ON_CP_SEL_NS);
}
else if (isIE(context))
{
writer.write(_ON_CP_SEL_IE);
}
else // Mozilla
{
writer.write(_ON_CP_SEL_MZ);
}
writer.endElement("script");
}
StringBuilder onCellClick = null;
int onCellClickLength = 0;
if (isNetscape)
{
Object id = getID(context, node);
if (id == null)
id = "null";
onCellClick = new StringBuilder(id.toString().length() +
onColorSelect.toString().length() +
16);
onCellClick.append("_onCPSel('");
onCellClick.append(id);
onCellClick.append("','");
BaseDesktopUtils.escapeJS(onCellClick,
onColorSelect.toString(),
true /* inQuotes */);
onCellClick.append('\'');
onCellClickLength = onCellClick.toString().length();
}
String pattern = "#RRGGBB";
for(int y=0; y < height; y++)
{
writer.startElement("tr", null);
writer.writeAttribute("height", _CELL_SIZE, null);
for(int x=0; x < width; x++)
{
// completed 'y' rows, each with 'width' cells,
// plus 'x' more cells in this row
index = (y * width) + x;
if (index < colorCount)
{
//colorData/customColorData binding is always expected to resolve to
// a java.util.List of java.awt.Color. An error otherwise.
color = colorData.get(index);
}
else
{
color = null;
}
writer.startElement("td", null);
if (color != null)
{
if (color.getAlpha() == 0) // transparent
{
String destination = null;
String onClick = null;
if (hasOnColorSelect)
{
destination = "#";
if (onCellClick != null)
{
onCellClick.setLength(onCellClickLength);
onCellClick.append("); return false");
onClick = onCellClick.toString();
}
}
renderIcon(context,
getBaseImageURI(context) +
COLOR_PALETTE_TRANSPARENT_ICON_NAME,
"af_chooseColor.TRANSPARENT",
destination,
null,
onClick,
null,
null, true);
}
else
{
String colorString = CSSUtils.getColorValue(color);
if (isNetscape)
writer.writeAttribute("bgcolor", colorString, null);
if (hasOnColorSelect)
{
writer.startElement("a", null);
if (onCellClick != null)
{
onCellClick.setLength(onCellClickLength);
onCellClick.append(",'");
onCellClick.append(colorString);
onCellClick.append("'); return false");
writer.writeAttribute("onclick", onCellClick.toString(), null);
}
writer.writeAttribute("href", "#", null);
}
writer.startElement("img", null);
writer.writeAttribute("border", "0", null);
writer.writeAttribute("width", _CELL_SIZE, null);
writer.writeAttribute("height", _CELL_SIZE, null);
if (!isNetscape)
{
writer.writeAttribute("style", "background-color:" + colorString,
null);
XhtmlLafRenderer.renderStyleClassAttribute(context,
"p_OraDisplayBlock");
}
writeAbsoluteImageURI(context, "src", TRANSPARENT_GIF);
renderAltAndTooltipForImage(context,
new RGBColorFormat(pattern).format(color));
writer.endElement("img");
if (hasOnColorSelect)
{
writer.endElement("a");
}
}
}
else
{
// empty cell
renderStyleClassAttribute(context,
COLOR_PALETTE_EMPTY_CELL_STYLE_CLASS);
if (isNetscape)
{
writer.startElement("img", null);
writer.writeAttribute("border", "0", null);
writer.writeAttribute("width", _CELL_SIZE, null);
writer.writeAttribute("height", _CELL_SIZE, null);
writeAbsoluteImageURI(context, "src", TRANSPARENT_GIF);
writer.endElement("img");
}
else
{
writer.writeAttribute("width", _CELL_SIZE, null);
}
}
writer.endElement("td");
}
writer.endElement("tr");
}
if (isNetscape)
{
writer.endElement("table");
writer.endElement("td");
writer.endElement("tr");
}
writer.endElement("table");
}