Example usage for org.jfree.chart.title LegendTitle setBackgroundPaint

List of usage examples for org.jfree.chart.title LegendTitle setBackgroundPaint

Introduction

In this page you can find the example usage for org.jfree.chart.title LegendTitle setBackgroundPaint.

Prototype

public void setBackgroundPaint(Paint paint) 

Source Link

Document

Sets the background paint for the legend and sends a TitleChangeEvent to all registered listeners.

Usage

From source file:net.sf.jasperreports.chartthemes.simple.SimpleChartTheme.java

protected void setChartLegend(JFreeChart jfreeChart) {
    //The legend visibility is already taken into account in the jfreeChart object's constructor
    LegendTitle legend = jfreeChart.getLegend();
    if (legend != null) {
        LegendSettings legendSettings = getLegendSettings();
        JRBaseFont font = new JRBaseFont();
        FontUtil.copyNonNullOwnProperties(legendSettings.getFont(), font);
        FontUtil.copyNonNullOwnProperties(getChart().getLegendFont(), font);
        font = new JRBaseFont(getChart(), font);
        legend.setItemFont(getFontUtil().getAwtFont(font, getLocale()));

        Paint forePaint = getChart().getOwnLegendColor();
        if (forePaint == null && legendSettings.getForegroundPaint() != null) {
            forePaint = legendSettings.getForegroundPaint().getPaint();
        }//  w  w w.  ja v  a  2  s .c  o  m
        if (forePaint == null) {
            forePaint = getChart().getLegendColor();
        }
        if (forePaint != null)
            legend.setItemPaint(forePaint);

        Paint backPaint = getChart().getOwnLegendBackgroundColor();
        if (backPaint == null && legendSettings.getBackgroundPaint() != null) {
            backPaint = legendSettings.getBackgroundPaint().getPaint();
        }
        if (backPaint == null) {
            backPaint = getChart().getLegendBackgroundColor();
        }
        if (backPaint != null)
            legend.setBackgroundPaint(backPaint);

        BlockFrame blockFrame = legendSettings.getBlockFrame();
        if (blockFrame != null)
            legend.setFrame(blockFrame);

        HorizontalAlignment hAlign = legendSettings.getHorizontalAlignment();
        if (hAlign != null)
            legend.setHorizontalAlignment(hAlign);

        VerticalAlignment vAlign = legendSettings.getVerticalAlignment();
        if (vAlign != null)
            legend.setVerticalAlignment(vAlign);

        RectangleInsets padding = legendSettings.getPadding();
        if (padding != null)
            legend.setPadding(padding);

        legend.setPosition(getEdge(getChart().getLegendPositionValue(),
                getEdge(legendSettings.getPositionValue(), RectangleEdge.BOTTOM)));
    }
}