this.title, this.title, null, true, Color.black,
new BasicStroke(1.0f), Color.black, new BasicStroke(1.0f)
);
}
RectangularShape legendArea;
double availableWidth = available.getWidth();
// the translation point for the origin of the drawing system
Point2D translation;
// Create buffer for individual items within the legend
List items = new ArrayList();
// Compute individual rectangles in the legend, translation point as well
// as the bounding box for the legend.
if (horizontal) {
double xstart = available.getX() + getOuterGap().getLeftSpace(availableWidth);
double xlimit = available.getMaxX() - getOuterGap().getRightSpace(availableWidth);
double maxRowWidth = 0;
double xoffset = 0;
double rowHeight = 0;
double totalHeight = 0;
boolean wrappingAllowed = true;
if (titleItem != null) {
g2.setFont(getTitleFont());
legendTitle = createDrawableLegendItem(
g2, titleItem, xoffset, totalHeight
);
rowHeight = Math.max(0, legendTitle.getHeight());
xoffset += legendTitle.getWidth();
}
g2.setFont(this.itemFont);
for (int i = 0; i < legendItems.getItemCount(); i++) {
DrawableLegendItem item;
if (this.renderingOrder == LegendRenderingOrder.STANDARD) {
item = createDrawableLegendItem(
g2, legendItems.get(i), xoffset, totalHeight
);
}
else if (this.renderingOrder == LegendRenderingOrder.REVERSE) {
item = createDrawableLegendItem(
g2, legendItems.get(legendItems.getItemCount() - i - 1), xoffset,
totalHeight
);
}
else {
// we're not supposed to get here, will cause NullPointerException
item = null;
}
if (item.getMaxX() + xstart > xlimit && wrappingAllowed) {
// start a new row
maxRowWidth = Math.max(maxRowWidth, xoffset);
xoffset = 0;
totalHeight += rowHeight;
i--; // redo this item in the next row
// if item to big to fit, we dont want to attempt wrapping endlessly.
// we therefore disable wrapping for at least one item.
wrappingAllowed = false;
}
else {
// continue current row
rowHeight = Math.max(rowHeight, item.getHeight());
xoffset += item.getWidth();
// we placed an item in this row, re-allow wrapping for next item.
wrappingAllowed = true;
items.add(item);
}
}
maxRowWidth = Math.max(maxRowWidth, xoffset);
totalHeight += rowHeight;
// Create the bounding box
legendArea = new RoundRectangle2D.Double(
0, 0, maxRowWidth, totalHeight, this.boundingBoxArcWidth, this.boundingBoxArcHeight
);
translation = createTranslationPointForHorizontalDraw(
available, inverted, maxRowWidth, totalHeight
);
}
else { // vertical...
double totalHeight = 0;
double maxWidth = (this.preferredWidth == NO_PREFERRED_WIDTH) ? 0 : this.preferredWidth;
if (titleItem != null) {
g2.setFont(getTitleFont());
legendTitle = createDrawableLegendItem(g2, titleItem, 0, totalHeight);
totalHeight += legendTitle.getHeight();
maxWidth = Math.max(maxWidth, legendTitle.getWidth());
}
g2.setFont(this.itemFont);
int legendItemsLength = legendItems.getItemCount();
for (int i = 0; i < legendItemsLength; i++) {
List drawableParts;
if (this.renderingOrder == LegendRenderingOrder.STANDARD) {
drawableParts = createAllDrawableLinesForItem(g2,
legendItems.get(i), 0, totalHeight, maxWidth);
}
else if (this.renderingOrder == LegendRenderingOrder.REVERSE) {
drawableParts = createAllDrawableLinesForItem(
g2, legendItems.get(legendItemsLength - i - 1), 0, totalHeight, maxWidth
);
}
else {
// we're not supposed to get here, will cause NullPointerException
drawableParts = null;
}
for (Iterator j = drawableParts.iterator(); j.hasNext();) {
DrawableLegendItem item = (DrawableLegendItem) j.next();
totalHeight += item.getHeight();
maxWidth = Math.max(maxWidth, item.getWidth());
items.add(item);
}
}
// Create the bounding box
legendArea = new RoundRectangle2D.Float(
0, 0, (float) maxWidth, (float) totalHeight,
this.boundingBoxArcWidth, this.boundingBoxArcHeight
);
translation = createTranslationPointForVerticalDraw(
available, inverted, totalHeight, maxWidth
);
}
// Move the origin of the drawing to the appropriate location
g2.translate(translation.getX(), translation.getY());
LOGGER.debug("legendArea = " + legendArea.getWidth() + ", " + legendArea.getHeight());
drawLegendBox(g2, legendArea);
drawLegendTitle(g2, legendTitle);
drawSeriesElements(g2, items, translation, info);
// translate the origin back to what it was prior to drawing the legend