Java Code Examples for org.jfree.chart.title.LegendTitle#setItemPaint()

The following examples show how to use org.jfree.chart.title.LegendTitle#setItemPaint() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StandardChartTheme.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Applies the attributes of this theme to the specified title.
 *
 * @param title  the title.
 */
protected void applyToTitle(Title title) {
    if (title instanceof TextTitle) {
        TextTitle tt = (TextTitle) title;
        tt.setFont(this.largeFont);
        tt.setPaint(this.subtitlePaint);
    }
    else if (title instanceof LegendTitle) {
        LegendTitle lt = (LegendTitle) title;
        if (lt.getBackgroundPaint() != null) {
            lt.setBackgroundPaint(this.legendBackgroundPaint);
        }
        lt.setItemFont(this.regularFont);
        lt.setItemPaint(this.legendItemPaint);
        if (lt.getWrapper() != null) {
            applyToBlockContainer(lt.getWrapper());
        }
    }
    else if (title instanceof PaintScaleLegend) {
        PaintScaleLegend psl = (PaintScaleLegend) title;
        psl.setBackgroundPaint(this.legendBackgroundPaint);
        ValueAxis axis = psl.getAxis();
        if (axis != null) {
            applyToValueAxis(axis);
        }
    }
    else if (title instanceof CompositeTitle) {
        CompositeTitle ct = (CompositeTitle) title;
        BlockContainer bc = ct.getContainer();
        List blocks = bc.getBlocks();
        Iterator iterator = blocks.iterator();
        while (iterator.hasNext()) {
            Block b = (Block) iterator.next();
            if (b instanceof Title) {
                applyToTitle((Title) b);
            }
        }
    }
}
 
Example 2
Source File: StandardChartTheme.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Applies the attributes of this theme to the specified title.
 *
 * @param title  the title.
 */
protected void applyToTitle(Title title) {
    if (title instanceof TextTitle) {
        TextTitle tt = (TextTitle) title;
        tt.setFont(this.largeFont);
        tt.setPaint(this.subtitlePaint);
    }
    else if (title instanceof LegendTitle) {
        LegendTitle lt = (LegendTitle) title;
        if (lt.getBackgroundPaint() != null) {
            lt.setBackgroundPaint(this.legendBackgroundPaint);
        }
        lt.setItemFont(this.regularFont);
        lt.setItemPaint(this.legendItemPaint);
        if (lt.getWrapper() != null) {
            applyToBlockContainer(lt.getWrapper());
        }
    }
    else if (title instanceof PaintScaleLegend) {
        PaintScaleLegend psl = (PaintScaleLegend) title;
        psl.setBackgroundPaint(this.legendBackgroundPaint);
        ValueAxis axis = psl.getAxis();
        if (axis != null) {
            applyToValueAxis(axis);
        }
    }
    else if (title instanceof CompositeTitle) {
        CompositeTitle ct = (CompositeTitle) title;
        BlockContainer bc = ct.getContainer();
        List blocks = bc.getBlocks();
        Iterator iterator = blocks.iterator();
        while (iterator.hasNext()) {
            Block b = (Block) iterator.next();
            if (b instanceof Title) {
                applyToTitle((Title) b);
            }
        }
    }
}
 
Example 3
Source File: StandardChartTheme.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Applies the attributes of this theme to the specified title.
 *
 * @param title  the title.
 */
protected void applyToTitle(Title title) {
    if (title instanceof TextTitle) {
        TextTitle tt = (TextTitle) title;
        tt.setFont(this.largeFont);
        tt.setPaint(this.subtitlePaint);
    }
    else if (title instanceof LegendTitle) {
        LegendTitle lt = (LegendTitle) title;
        if (lt.getBackgroundPaint() != null) {
            lt.setBackgroundPaint(this.legendBackgroundPaint);
        }
        lt.setItemFont(this.regularFont);
        lt.setItemPaint(this.legendItemPaint);
        if (lt.getWrapper() != null) {
            applyToBlockContainer(lt.getWrapper());
        }
    }
    else if (title instanceof PaintScaleLegend) {
        PaintScaleLegend psl = (PaintScaleLegend) title;
        psl.setBackgroundPaint(this.legendBackgroundPaint);
        ValueAxis axis = psl.getAxis();
        if (axis != null) {
            applyToValueAxis(axis);
        }
    }
    else if (title instanceof CompositeTitle) {
        CompositeTitle ct = (CompositeTitle) title;
        BlockContainer bc = ct.getContainer();
        List blocks = bc.getBlocks();
        Iterator iterator = blocks.iterator();
        while (iterator.hasNext()) {
            Block b = (Block) iterator.next();
            if (b instanceof Title) {
                applyToTitle((Title) b);
            }
        }
    }
}
 
Example 4
Source File: JFreeChartPlotEngine.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Creates {@link LegendTitle}s for all dimensions from the PlotConfiguration of this Plotter2D.
 * Expects that all {@link ValueSource} s in the provided PlotConfiguration use the same
 * {@link DimensionConfig} s.
 */
private List<LegendTitle> createLegendTitles() {
	List<LegendTitle> legendTitles = new LinkedList<LegendTitle>();
	LegendConfiguration legendConfiguration = plotInstance.getCurrentPlotConfigurationClone().getLegendConfiguration();

	LegendTitle legendTitle = new SmartLegendTitle(this,
			new FlowArrangement(HorizontalAlignment.CENTER, VerticalAlignment.CENTER, 30, 2),
			new ColumnArrangement(HorizontalAlignment.LEFT, VerticalAlignment.CENTER, 0, 2));
	legendTitle.setItemPaint(legendConfiguration.getLegendFontColor());

	RectangleEdge position = legendConfiguration.getLegendPosition().getPosition();
	if (position == null) {
		return legendTitles;
	}
	legendTitle.setPosition(position);

	if (legendConfiguration.isShowLegendFrame()) {
		legendTitle.setFrame(new BlockBorder(legendConfiguration.getLegendFrameColor()));
	}
	ColoredBlockContainer wrapper = new ColoredBlockContainer(legendConfiguration.getLegendBackgroundColor());
	wrapper.add(legendTitle.getItemContainer());
	wrapper.setPadding(3, 3, 3, 3);
	legendTitle.setWrapper(wrapper);

	legendTitles.add(legendTitle);
	return legendTitles;
}
 
Example 5
Source File: StandardChartTheme.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Applies the attributes of this theme to the specified title.
 *
 * @param title  the title.
 */
protected void applyToTitle(Title title) {
    if (title instanceof TextTitle) {
        TextTitle tt = (TextTitle) title;
        tt.setFont(this.largeFont);
        tt.setPaint(this.subtitlePaint);
    }
    else if (title instanceof LegendTitle) {
        LegendTitle lt = (LegendTitle) title;
        if (lt.getBackgroundPaint() != null) {
            lt.setBackgroundPaint(this.legendBackgroundPaint);
        }
        lt.setItemFont(this.regularFont);
        lt.setItemPaint(this.legendItemPaint);
        if (lt.getWrapper() != null) {
            applyToBlockContainer(lt.getWrapper());
        }
    }
    else if (title instanceof PaintScaleLegend) {
        PaintScaleLegend psl = (PaintScaleLegend) title;
        psl.setBackgroundPaint(this.legendBackgroundPaint);
        ValueAxis axis = psl.getAxis();
        if (axis != null) {
            applyToValueAxis(axis);
        }
    }
    else if (title instanceof CompositeTitle) {
        CompositeTitle ct = (CompositeTitle) title;
        BlockContainer bc = ct.getContainer();
        List blocks = bc.getBlocks();
        Iterator iterator = blocks.iterator();
        while (iterator.hasNext()) {
            Block b = (Block) iterator.next();
            if (b instanceof Title) {
                applyToTitle((Title) b);
            }
        }
    }
}
 
Example 6
Source File: StandardChartTheme.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Applies the attributes of this theme to the specified title.
 *
 * @param title  the title.
 */
protected void applyToTitle(Title title) {
    if (title instanceof TextTitle) {
        TextTitle tt = (TextTitle) title;
        tt.setFont(this.largeFont);
        tt.setPaint(this.subtitlePaint);
    }
    else if (title instanceof LegendTitle) {
        LegendTitle lt = (LegendTitle) title;
        if (lt.getBackgroundPaint() != null) {
            lt.setBackgroundPaint(this.legendBackgroundPaint);
        }
        lt.setItemFont(this.regularFont);
        lt.setItemPaint(this.legendItemPaint);
        if (lt.getWrapper() != null) {
            applyToBlockContainer(lt.getWrapper());
        }
    }
    else if (title instanceof PaintScaleLegend) {
        PaintScaleLegend psl = (PaintScaleLegend) title;
        psl.setBackgroundPaint(this.legendBackgroundPaint);
        ValueAxis axis = psl.getAxis();
        if (axis != null) {
            applyToValueAxis(axis);
        }
    }
    else if (title instanceof CompositeTitle) {
        CompositeTitle ct = (CompositeTitle) title;
        BlockContainer bc = ct.getContainer();
        List blocks = bc.getBlocks();
        Iterator iterator = blocks.iterator();
        while (iterator.hasNext()) {
            Block b = (Block) iterator.next();
            if (b instanceof Title) {
                applyToTitle((Title) b);
            }
        }
    }
}
 
Example 7
Source File: ChartFormatter.java    From nmonvisualizer with Apache License 2.0 5 votes vote down vote up
void formatLegend(LegendTitle legend) {
    legend.setItemFont(LEGEND_FONT);
    legend.setItemPaint(textColor);
    legend.setBorder(0, 0, 0, 0);
    legend.setPosition(RectangleEdge.BOTTOM);

    legend.setItemLabelPadding(new RectangleInsets(5, 5, 5, 5));
}
 
Example 8
Source File: StandardChartTheme.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Applies the attributes of this theme to the specified title.
 *
 * @param title  the title.
 */
protected void applyToTitle(Title title) {
    if (title instanceof TextTitle) {
        TextTitle tt = (TextTitle) title;
        tt.setFont(this.largeFont);
        tt.setPaint(this.subtitlePaint);
    }
    else if (title instanceof LegendTitle) {
        LegendTitle lt = (LegendTitle) title;
        if (lt.getBackgroundPaint() != null) {
            lt.setBackgroundPaint(this.legendBackgroundPaint);
        }
        lt.setItemFont(this.regularFont);
        lt.setItemPaint(this.legendItemPaint);
        if (lt.getWrapper() != null) {
            applyToBlockContainer(lt.getWrapper());
        }
    }
    else if (title instanceof PaintScaleLegend) {
        PaintScaleLegend psl = (PaintScaleLegend) title;
        psl.setBackgroundPaint(this.legendBackgroundPaint);
        ValueAxis axis = psl.getAxis();
        if (axis != null) {
            applyToValueAxis(axis);
        }
    }
    else if (title instanceof CompositeTitle) {
        CompositeTitle ct = (CompositeTitle) title;
        BlockContainer bc = ct.getContainer();
        List blocks = bc.getBlocks();
        Iterator iterator = blocks.iterator();
        while (iterator.hasNext()) {
            Block b = (Block) iterator.next();
            if (b instanceof Title) {
                applyToTitle((Title) b);
            }
        }
    }
}
 
Example 9
Source File: StandardChartTheme.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Applies the attributes of this theme to the specified title.
 *
 * @param title  the title.
 */
protected void applyToTitle(Title title) {
    if (title instanceof TextTitle) {
        TextTitle tt = (TextTitle) title;
        tt.setFont(this.largeFont);
        tt.setPaint(this.subtitlePaint);
    }
    else if (title instanceof LegendTitle) {
        LegendTitle lt = (LegendTitle) title;
        if (lt.getBackgroundPaint() != null) {
            lt.setBackgroundPaint(this.legendBackgroundPaint);
        }
        lt.setItemFont(this.regularFont);
        lt.setItemPaint(this.legendItemPaint);
        if (lt.getWrapper() != null) {
            applyToBlockContainer(lt.getWrapper());
        }
    }
    else if (title instanceof PaintScaleLegend) {
        PaintScaleLegend psl = (PaintScaleLegend) title;
        psl.setBackgroundPaint(this.legendBackgroundPaint);
        ValueAxis axis = psl.getAxis();
        if (axis != null) {
            applyToValueAxis(axis);
        }
    }
    else if (title instanceof CompositeTitle) {
        CompositeTitle ct = (CompositeTitle) title;
        BlockContainer bc = ct.getContainer();
        List blocks = bc.getBlocks();
        Iterator iterator = blocks.iterator();
        while (iterator.hasNext()) {
            Block b = (Block) iterator.next();
            if (b instanceof Title) {
                applyToTitle((Title) b);
            }
        }
    }
}
 
Example 10
Source File: DefaultChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 *
 */
protected void configureChart(JFreeChart jfreeChart) throws JRException
{
	if (getChart().getModeValue() == ModeEnum.OPAQUE)
	{
		jfreeChart.setBackgroundPaint(getChart().getBackcolor());
	}
	else
	{
		jfreeChart.setBackgroundPaint(null);
	}
	
	RectangleEdge titleEdge = getEdge(getChart().getTitlePositionValue(), RectangleEdge.TOP);
	
	if (jfreeChart.getTitle() != null)
	{
		TextTitle title = jfreeChart.getTitle();
		title.setPaint(getChart().getTitleColor());

		title.setFont(fontUtil.getAwtFont(getFont(getChart().getTitleFont()), getLocale()));
		title.setPosition(titleEdge);
	}

	String subtitleText = evaluateTextExpression(getChart().getSubtitleExpression());
	if (subtitleText != null)
	{
		TextTitle subtitle = new TextTitle(subtitleText);
		subtitle.setPaint(getChart().getSubtitleColor());

		subtitle.setFont(fontUtil.getAwtFont(getFont(getChart().getSubtitleFont()), getLocale()));
		subtitle.setPosition(titleEdge);

		jfreeChart.addSubtitle(subtitle);
	}

	// Apply all of the legend formatting options
	LegendTitle legend = jfreeChart.getLegend();
	if (legend != null)
	{
		legend.setItemPaint(getChart().getLegendColor());

		if (getChart().getOwnLegendBackgroundColor() == null)// in a way, legend backcolor inheritance from chart is useless
		{
			legend.setBackgroundPaint(null);
		}
		else
		{
			legend.setBackgroundPaint(getChart().getLegendBackgroundColor());
		}

		legend.setItemFont(fontUtil.getAwtFont(getFont(getChart().getLegendFont()), getLocale()));
		legend.setPosition(getEdge(getChart().getLegendPositionValue(), RectangleEdge.BOTTOM));
	}
	
	configurePlot(jfreeChart.getPlot());
}
 
Example 11
Source File: GenericChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected void setChartLegend(JFreeChart jfreeChart, Integer baseFontSize)
{

	//The legend visibility is already taken into account in the jfreeChart object's constructor
	
	LegendTitle legend = jfreeChart.getLegend();
	if (legend != null)
	{
		Font themeLegendFont = getFont((JRFont)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_FONT), getChart().getLegendFont(), baseFontSize);
		legend.setItemFont(themeLegendFont);

		Color legendForecolor = getChart().getOwnLegendColor() != null ? 
				getChart().getOwnLegendColor() :
				(getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_FORECOLOR) != null ? 
						(Color)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_FORECOLOR) :
						getChart().getLegendColor());
		if (legendForecolor != null)
			legend.setItemPaint(legendForecolor);

		Color legendBackcolor = getChart().getOwnLegendBackgroundColor() != null ? 
				getChart().getOwnLegendBackgroundColor() :
				(getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_BACKCOLOR) != null ? 
						(Color)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_BACKCOLOR) :
						getChart().getLegendBackgroundColor());
		if (legendBackcolor != null)
			legend.setBackgroundPaint(legendBackcolor);
		
		BlockFrame frame = (BlockFrame)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_FRAME);
		if (frame != null)
			legend.setFrame(frame);
		
		HorizontalAlignment defaultLegendHAlignment = (HorizontalAlignment)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_HORIZONTAL_ALIGNMENT);
		if (defaultLegendHAlignment != null)
			legend.setHorizontalAlignment(defaultLegendHAlignment);
		
		VerticalAlignment defaultLegendVAlignment = (VerticalAlignment)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_VERTICAL_ALIGNMENT);
		if (defaultLegendVAlignment != null)
			legend.setVerticalAlignment(defaultLegendVAlignment);
		
		RectangleInsets defaultLegendPadding = (RectangleInsets)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_PADDING);
		RectangleInsets legendPadding = legend.getPadding() != null ? legend.getPadding() : defaultLegendPadding;
		if (legendPadding != null)
			legend.setPadding(legendPadding);

		RectangleEdge defaultLegendPosition = (RectangleEdge)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_POSITION);
		if (getEdge(getChart().getLegendPositionValue(), defaultLegendPosition) != null)
			legend.setPosition(getEdge(getChart().getLegendPositionValue(), defaultLegendPosition));
		
	}
}
 
Example 12
Source File: SimpleChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
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();
		}
		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
					)
				)
			);
	}
}
 
Example 13
Source File: cfCHART.java    From openbd-core with GNU General Public License v3.0 4 votes vote down vote up
private void setLegend(JFreeChart chart, boolean bShowLegend, Font font, Color foregroundColor, Color backgroundColor, cfCHARTLEGENDData legendData) throws cfmRunTimeException {
	LegendTitle legend = new LegendTitle(chart.getPlot());
	legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));

	// If a CFCHARTLEGEND tag was used then use it's attributes to configure the
	// legend
	if (legendData != null) {
		// A CFCHARTLEGEND tag is present so use its attributes to configure the
		// legend
		legend.setItemFont(getFont(legendData.getFont(), legendData.getFontBold(), legendData.getFontItalic(), legendData.getFontSize()));
		legend.setItemPaint(convertStringToColor(legendData.getLabelColor()));
		legend.setBackgroundPaint(convertStringToColor(legendData.getBackgroundColor()));

		String pos = legendData.getPosition();
		if (pos.equals("top"))
			legend.setPosition(RectangleEdge.TOP);
		else if (pos.equals("bottom"))
			legend.setPosition(RectangleEdge.BOTTOM);
		else if (pos.equals("left"))
			legend.setPosition(RectangleEdge.LEFT);
		else if (pos.equals("right"))
			legend.setPosition(RectangleEdge.RIGHT);

		if (!legendData.getShowBorder())
			legend.setBorder(BlockBorder.NONE);
		else
			legend.setBorder(new BlockBorder());
	} else {
		// A CFCHARTLEGEND tag is NOT present so use the attributes from the
		// CFCHART tag to configure the legend
		if (!bShowLegend)
			return;

		legend.setItemFont(font);
		legend.setItemPaint(foregroundColor);
		legend.setBackgroundPaint(backgroundColor);

		// By default CFMX 7 places the legend at the top with no border
		legend.setPosition(RectangleEdge.TOP);
		legend.setBorder(BlockBorder.NONE);
	}

	// Add the legend to the chart
	chart.addSubtitle(legend);
}
 
Example 14
Source File: AbstractChartExpression.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected void configureChart( final JFreeChart chart ) {
  // Misc Properties
  final TextTitle chartTitle = chart.getTitle();
  if ( chartTitle != null ) {
    final Font titleFont = Font.decode( getTitleFont() );
    chartTitle.setFont( titleFont );
  }

  if ( isAntiAlias() == false ) {
    chart.setAntiAlias( false );
  }

  chart.setBorderVisible( isShowBorder() );

  final Color backgroundColor = parseColorFromString( getBackgroundColor() );
  if ( backgroundColor != null ) {
    chart.setBackgroundPaint( backgroundColor );
  }

  if ( plotBackgroundColor != null ) {
    chart.getPlot().setBackgroundPaint( plotBackgroundColor );
  }
  chart.getPlot().setBackgroundAlpha( plotBackgroundAlpha );
  chart.getPlot().setForegroundAlpha( plotForegroundAlpha );
  final Color borderCol = parseColorFromString( getBorderColor() );
  if ( borderCol != null ) {
    chart.setBorderPaint( borderCol );
  }

  //remove legend if showLegend = false
  if ( !isShowLegend() ) {
    chart.removeLegend();
  } else { //if true format legend
    final LegendTitle chLegend = chart.getLegend();
    if ( chLegend != null ) {
      final RectangleEdge loc = translateEdge( legendLocation.toLowerCase() );
      if ( loc != null ) {
        chLegend.setPosition( loc );
      }
      if ( getLegendFont() != null ) {
        chLegend.setItemFont( Font.decode( getLegendFont() ) );
      }
      if ( !isDrawLegendBorder() ) {
        chLegend.setBorder( BlockBorder.NONE );
      }
      if ( legendBackgroundColor != null ) {
        chLegend.setBackgroundPaint( legendBackgroundColor );
      }
      if ( legendTextColor != null ) {
        chLegend.setItemPaint( legendTextColor );
      }
    }

  }

  final Plot plot = chart.getPlot();
  plot.setNoDataMessageFont( Font.decode( getLabelFont() ) );

  final String message = getNoDataMessage();
  if ( message != null ) {
    plot.setNoDataMessage( message );
  }

  plot.setOutlineVisible( isChartSectionOutline() );

  if ( backgroundImage != null ) {
    if ( plotImageCache != null ) {
      plot.setBackgroundImage( plotImageCache );
    } else {
      final ExpressionRuntime expressionRuntime = getRuntime();
      final ProcessingContext context = expressionRuntime.getProcessingContext();
      final ResourceKey contentBase = context.getContentBase();
      final ResourceManager manager = context.getResourceManager();
      try {
        final ResourceKey key = createKeyFromString( manager, contentBase, backgroundImage );
        final Resource resource = manager.create( key, null, Image.class );
        final Image image = (Image) resource.getResource();
        plot.setBackgroundImage( image );
        plotImageCache = image;
      } catch ( Exception e ) {
        logger.error( "ABSTRACTCHARTEXPRESSION.ERROR_0007_ERROR_RETRIEVING_PLOT_IMAGE", e ); //$NON-NLS-1$
        throw new IllegalStateException( "Failed to process chart" );
      }
    }
  }
}
 
Example 15
Source File: MultiPieChartExpression.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected void configureSubChart( final JFreeChart chart ) {
  final TextTitle chartTitle = chart.getTitle();
  if ( chartTitle != null ) {
    if ( getPieTitleFont() != null ) {
      chartTitle.setFont( getPieTitleFont() );
    } else {
      final Font titleFont = Font.decode( getTitleFont() );
      chartTitle.setFont( titleFont );
    }
  }

  if ( isAntiAlias() == false ) {
    chart.setAntiAlias( false );
  }

  final LegendTitle chLegend = chart.getLegend();
  if ( chLegend != null ) {
    final RectangleEdge loc = translateEdge( getLegendLocation().toLowerCase() );
    if ( loc != null ) {
      chLegend.setPosition( loc );
    }
    if ( getLegendFont() != null ) {
      chLegend.setItemFont( Font.decode( getLegendFont() ) );
    }
    if ( !isDrawLegendBorder() ) {
      chLegend.setBorder( BlockBorder.NONE );
    }
    if ( getLegendBackgroundColor() != null ) {
      chLegend.setBackgroundPaint( getLegendBackgroundColor() );
    }
    if ( getLegendTextColor() != null ) {
      chLegend.setItemPaint( getLegendTextColor() );
    }
  }

  final Plot plot = chart.getPlot();
  plot.setNoDataMessageFont( Font.decode( getLabelFont() ) );

  final String pieNoData = getPieNoDataMessage();
  if ( pieNoData != null ) {
    plot.setNoDataMessage( pieNoData );
  } else {
    final String message = getNoDataMessage();
    if ( message != null ) {
      plot.setNoDataMessage( message );
    }
  }
}