}
public void paint(final Graphics g, final float x, final float y,
final float w, final float h,
final View v, final int item) {
final View child = v.getView(item);
if (!(child instanceof BlockView)) {
return;
}
final AttributeSet attr = child.getAttributes();
final StyleSheet ss = ((BlockView)child).getStyleSheet();
Font font = ss.getFont(attr);
final Color color = ss.getForeground(attr);
final CSS.ListStyleType listStyle =
(CSS.ListStyleType)attr.getAttribute(Attribute.LIST_STYLE_TYPE);
String decorator = null;
int index;
if (listStyle == null) {
final String name = v.getElement().getName();
if (HTML.Tag.OL.toString().equals(name)) {
index = CSS.ListStyleType.LIST_STYLE_DECIMAL;
} else if (HTML.Tag.UL.toString().equals(name)) {
index = CSS.ListStyleType.LIST_STYLE_DISC;
} else {
index = CSS.ListStyleType.LIST_STYLE_NONE;
}
} else {
index = listStyle.getIndex();
}
switch (index) {
case CSS.ListStyleType.LIST_STYLE_DISC:
decorator = DISC;
font = font.deriveFont(font.getSize2D() * 0.7f);
break;
case CSS.ListStyleType.LIST_STYLE_CIRCLE:
decorator = CIRCLE;
font = font.deriveFont(font.getSize2D() * 0.7f);
break;
case CSS.ListStyleType.LIST_STYLE_SQUARE:
decorator = SQUARE;
font = font.deriveFont(font.getSize2D() * 0.7f);
break;
case CSS.ListStyleType.LIST_STYLE_DECIMAL:
decorator = Integer.toString(item + 1) + ".";
break;
case CSS.ListStyleType.LIST_STYLE_LOWER_ROMAN:
decorator = Integer.toString(item + 1) + "r.";
break;
case CSS.ListStyleType.LIST_STYLE_UPPER_ROMAN:
decorator = Integer.toString(item + 1) + "R.";
break;
case CSS.ListStyleType.LIST_STYLE_LOWER_ALPHA:
decorator = (char)('a' + item) + ".";
break;
case CSS.ListStyleType.LIST_STYLE_UPPER_ALPHA:
decorator = (char)('A' + item) + ".";
break;
case CSS.ListStyleType.LIST_STYLE_NONE:
default:
}
if (decorator == null) {
return;
}
Color oldColor = g.getColor();
Font oldFont = g.getFont();
g.setColor(color);
g.setFont(font);
FontMetrics metrics = g.getFontMetrics(font);
int width = metrics.stringWidth(decorator);
Rectangle pAlloc = new Rectangle((int)x, (int)y, (int)w, (int)h);
pAlloc = (Rectangle)child.getChildAllocation(0, pAlloc);
g.drawString(decorator,
(int)(x - width - DECORATOR_MARGIN),
(int)(pAlloc.y
+ pAlloc.height * child.getView(0)
.getAlignment(View.Y_AXIS)
+ metrics.getHeight() / 2f
- metrics.getDescent()));
g.setFont(oldFont);