* Renders the legend.
*
**********************************************************************************************/
public void render()
{
Graphics2D g2d = this.chart.getGraphics2D();
//---get the bounds of the image
Rectangle2D.Float rectangle = new Rectangle2D.Float( this.x, this.y, width - 1, this.height - 1 );
//---fill the background of the Legend with the specified Paint
if( this.legendProperties.getBackgroundPaint() != null )
{
g2d.setPaint( this.legendProperties.getBackgroundPaint() );
g2d.fill( rectangle );
}
//---draw Legend border
if( this.legendProperties.getBorderStroke() != null )
{
this.legendProperties.getBorderStroke().draw( g2d, rectangle );
}
//---dont think we want this so text will be clean but leave commented out.
//g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF );
//---set the font and text color.
g2d.setFont( this.legendProperties.getChartFont().getFont() );
//---icon coordinates
rectangle.y += this.legendProperties.getEdgePadding() + (this.textProcessor.getTallestLabel() / 2) - (this.iconSide / 2);
rectangle.width = this.iconSide;
rectangle.height = this.iconSide;
float posX = this.x + this.legendProperties.getEdgePadding();
float fontY = rectangle.y + rectangle.height;
//---pre calculate utility values
float yIncrement = this.textProcessor.getTallestLabel() + this.legendProperties.getRowPadding();
float iconAndPaddingWidth = this.iconSide + this.legendProperties.getIconPadding();
int labelIndex = 0;
//LOOP
for( int j = 0; j < this.numRows; j++ )
{
//LOOP
for( int i = 0; i < this.numColumns; i++ )
{
rectangle.x = posX;
//---display icon
g2d.setPaint( (Paint) this.paints.get( labelIndex ) );
// only Point and Line Charts will have shapes drawn
if( this.shapes.size() > 0 && this.shapes.size() > labelIndex )
{
//Shape shape = (Shape)this.shapes.get( labelIndex);
//---get the original transform so can reset it
AffineTransform affineTransform = g2d.getTransform();
//---translate the Shape into position
g2d.translate( rectangle.x, rectangle.y );
if( this.fillPointsFlags.size() > 0 )
{
if( ((Boolean) this.fillPointsFlags.get( labelIndex )).booleanValue() )
{
g2d.fill( (Shape) this.shapes.get( labelIndex ) );
//---if we are filling the points, see if we should outline the Shape
//---applicable only to POINt charts
if( this.pointOutlinePaints.get( labelIndex ) != null )
{
g2d.setPaint( (Paint) this.pointOutlinePaints.get( labelIndex ) );
g2d.draw( (Shape) this.shapes.get( labelIndex ) );
}
}
}
else
{
// for Point Charts, only draw shape
if( chartType == ChartType.POINT)
{
g2d.draw( (Shape) this.shapes.get( labelIndex ) );
} else
// chartType == ChartType.LINE
// for Line Charts, fill the shape
{
//---get the bounds of the shape
Rectangle2D shapeBounds = ( (Shape) this.shapes.get( labelIndex ) ).getBounds2D();
double XOffset = shapeBounds.getWidth() / 2;
double YOffset = shapeBounds.getHeight() / 2;
g2d.setStroke(this.lineChartProperties.getLineStrokes()[ labelIndex]);
Line2D.Double line = new Line2D.Double(0, YOffset, this.legendProperties.getIconLineStrokeLength(), YOffset);
g2d.draw( line );
// move posX to account for the lineStroke before the shape. for example, ---o
posX += this.legendProperties.getIconLineStrokeLength();
//---translate the Shape to adjust for the IconLineStrokeLength
g2d.translate( this.legendProperties.getIconLineStrokeLength() - XOffset , 0 );
line.x1 = XOffset;
g2d.draw( line );
g2d.fill( (Shape) this.shapes.get( labelIndex ) );
//---border around icon
if( this.legendProperties.getIconBorderStroke() != null && this.pointOutlinePaints.size() != 0 )
{
if( this.pointOutlinePaints != null ) {
g2d.setStroke( this.legendProperties.getIconBorderStroke() );
g2d.setPaint( (Paint) this.pointOutlinePaints.get( labelIndex ) );
g2d.draw( (Shape) this.shapes.get( labelIndex ) );
}
}
// move posX to account for the lineStroke after the shape. for example, o---
posX += this.legendProperties.getIconLineStrokeLength();
}
}
//---reset original transform
g2d.setTransform( affineTransform );
}
// for other charts, just draw a rectangle
else
{
g2d.fill( rectangle );
//---border around icon
if( this.legendProperties.getIconBorderStroke() != null )
{
g2d.setStroke( this.legendProperties.getIconBorderStroke() );
g2d.setPaint( this.legendProperties.getIconBorderPaint() );
g2d.draw( rectangle );
}
}
//---draw the label
g2d.setPaint( this.legendProperties.getChartFont().getPaint() );
posX += iconAndPaddingWidth;
g2d.drawString( (String) this.labels.get( labelIndex ), posX, fontY );
if( this.legendProperties.getNumColumns() == LegendAreaProperties.COLUMNS_AS_MANY_AS_NEEDED
|| this.legendProperties.getNumColumns() >= this.labels.size() )
{