ingo@617: package de.intevation.gnv.chart; ingo@617: ingo@617: import java.util.Locale; ingo@617: ingo@617: import org.apache.log4j.Logger; ingo@617: ingo@617: import org.jfree.chart.ChartFactory; ingo@617: import org.jfree.chart.ChartTheme; ingo@617: import org.jfree.chart.JFreeChart; ingo@617: ingo@617: import org.jfree.chart.plot.PlotOrientation; ingo@617: import org.jfree.chart.plot.XYPlot; ingo@617: sascha@623: import org.jfree.chart.renderer.xy.XYBarRenderer; ingo@617: ingo@617: /** ingo@767: * This abstract class defines some methods to adjust chart settings after its ingo@767: * creation. ingo@767: * ingo@767: * @author Ingo Weinzierl ingo@617: */ ingo@617: public abstract class AbstractHistogram ingo@617: implements Chart ingo@617: { ingo@767: /** ingo@767: * Logger used for logging with Apache log4j. ingo@767: */ ingo@617: private Logger logger = Logger.getLogger(AbstractHistogram.class); ingo@617: ingo@767: /** ingo@767: * JFreeChart chart stored at this place after chart creation. ingo@767: */ ingo@617: protected JFreeChart chart; ingo@767: ingo@767: /** ingo@767: * Labels used for chart title, subtitle, axis description. ingo@767: */ ingo@617: protected ChartLabels labels; ingo@767: ingo@767: /** ingo@767: * Theme which is used to adjust the styling of this chart. ingo@767: */ ingo@617: protected ChartTheme theme; ingo@767: ingo@767: /** ingo@767: * Raw data which should be displayed in the chart. ingo@767: */ ingo@617: protected Object[] data; ingo@617: ingo@767: /** ingo@767: * Locale object used for i18n support. ingo@767: */ ingo@617: protected Locale locale; ingo@617: ingo@617: ingo@767: /** ingo@767: * Constructor for creating histogram charts. ingo@767: * ingo@767: * @param labels See {@link #labels} ingo@767: * @param data See {@link #data} ingo@767: * @param theme See {@link #theme} ingo@767: */ ingo@617: public AbstractHistogram( ingo@617: ChartLabels labels, Object[] data, ChartTheme theme ingo@617: ) { ingo@617: this.labels = labels; ingo@617: this.data = data; ingo@617: this.theme = theme; ingo@617: } ingo@617: ingo@617: ingo@767: /** ingo@767: * @see de.intevation.gnv.chart.Chart#generateChart() ingo@767: */ ingo@617: public JFreeChart generateChart() { ingo@617: ingo@617: if (chart != null) ingo@617: return chart; ingo@617: ingo@617: chart = ChartFactory.createHistogram( ingo@617: labels.getTitle(), ingo@617: labels.getDomainAxisLabel(), ingo@617: labels.getRangeAxisLabel(), ingo@617: null, ingo@617: PlotOrientation.VERTICAL, ingo@617: true, ingo@617: false, ingo@617: false); ingo@617: ingo@617: applyDatasets(); ingo@617: ingo@617: theme.apply(chart); ingo@617: adjustPlot(); ingo@617: ingo@617: return chart; ingo@617: } ingo@617: ingo@617: ingo@767: /** ingo@767: * Method to do some changes in plot settings. ingo@767: */ ingo@617: protected void adjustPlot() { ingo@617: XYPlot plot = (XYPlot) chart.getPlot(); ingo@617: XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); ingo@617: ingo@617: renderer.setShadowVisible(false); ingo@617: renderer.setSeriesVisibleInLegend(0, false); ingo@617: } ingo@617: ingo@617: ingo@767: /** ingo@767: * This method needs to be implemented by subclasses and should add valid ingo@767: * HistogramDataset objects to the created chart. It is called ingo@767: * by {@link #generateChart} after chart creation. ingo@767: */ ingo@617: protected abstract void applyDatasets(); ingo@617: } ingo@617: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :