Q:

Show values inside LegendItems graphical shape

I'm trying to reproduce a piechart/ringplot produced by a different tool. Everything is fine except for the legend. I need to put values inside the graphical part of each LegendItem:
Image

I think that I have the outlines of a solution but would like you experienced jfreecharters to ack that I'm on the right track. I'm wondering if this couldn't be done in an easier way?
One way could be to subclass LegendTitle and override createLegendItemBlock(..). Copy most of the content but instead of contructing a LegendGraphic, construct a subclassed LegendGraphic which knows how to handle text inside the shape.
Any comments would be very welcome.

A:

I implemented the solution outlined in the question and it works fine. If anyone else should come across the problem, here's the subclassed LegendGraphic which handles text. The subclassed LegendTitle and overridden createLegendItemBlock(..) method are straightforward.
class CustomLegendGraphic extends LegendGraphic {
    String label;

    public CustomLegendGraphic(Shape shape, Paint fillPaint, String label) {
        super(shape, fillPaint);
        this.label = label;
    }

    @Override
    public Object draw(Graphics2D g2, Rectangle2D area, Object params) {
        Object result = super.draw(g2, area, params);

        area = trimMargin(area);
        Point2D location = RectangleAnchor.coordinates(area, this.getShapeLocation());

        TextBlock textBlock = TextUtilities.createTextBlock(label, getItemFont(), Color.white);
        textBlock.draw(g2, (float)location.getX(), (float)location.getY(), TextBlockAnchor.CENTER);

        return result;
    }
}

