1 /* ================================================================
2 * Cewolf : Chart enabling Web Objects Framework
3 * ================================================================
5 * Project Info: http://cewolf.sourceforge.net
6 * Project Lead: Guido Laures (guido@laures.de);
8 * (C) Copyright 2002, by Guido Laures and contributers
10 * This library is free software; you can redistribute it and/or modify it under the terms
11 * of the GNU Lesser General Public License as published by the Free Software Foundation;
12 * either version 2.1 of
13 * the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
16 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 * See the GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License along with this
20 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
21 * Boston, MA 02111-1307, USA.
23 package de.laures.cewolf.taglib;
25 import java.io.Serializable;
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30 import org.jfree.chart.plot.CategoryPlot;
31 import org.jfree.chart.plot.DrawingSupplier;
32 import org.jfree.chart.plot.Plot;
33 import org.jfree.chart.plot.XYPlot;
34 import org.jfree.chart.renderer.AbstractRenderer;
35 import org.jfree.chart.renderer.category.CategoryItemRenderer;
36 import org.jfree.chart.renderer.xy.XYItemRenderer;
37 import org.jfree.data.category.CategoryDataset;
38 import org.jfree.data.general.Dataset;
39 import org.jfree.data.xy.IntervalXYDataset;
40 import org.jfree.data.xy.OHLCDataset;
41 import org.jfree.data.xy.XYDataset;
43 import de.laures.cewolf.ChartValidationException;
44 import de.laures.cewolf.DatasetProduceException;
45 import de.laures.cewolf.DatasetProducer;
48 * (sub) Plot definition for combined/overlaid charts.
50 * @author Chris McCann
51 * @author Guido Laures
53 public class PlotDefinition implements DataAware, Serializable, TaglibConstants, PlotConstants {
55 private transient Log log = LogFactory.getLog(getClass());
58 private String xAxisLabel; // [tb]
59 private String yAxisLabel; // [tb]
61 private DataContainer dataAware = new DataContainer();
62 private transient Plot plot;
63 private transient DrawingSupplier drawingSupplier = null;
65 public Plot getPlot(int chartType) throws DatasetProduceException, ChartValidationException {
66 log.debug("Plot.getPlot: chartType: " + chartType);
68 int rendererIndex = PlotTypes.getRendererIndex(type);
70 Dataset data = (Dataset) getDataset();
71 log.debug("Plot.getPlot: data name: " +data.getClass().getName());
72 AbstractRenderer rend = PlotTypes.getRenderer(rendererIndex);
73 log.debug("Plot.getPlot: rendererIndex: " + rendererIndex);
74 if (chartType == ChartConstants.OVERLAY_XY || chartType == ChartConstants.COMBINED_XY) {
75 switch (rendererIndex) {
78 case XY_SHAPES_AND_LINES :
81 check(data, XYDataset.class, rendererIndex);
82 plot = new XYPlot((XYDataset) data, null, null, (XYItemRenderer) rend);
84 case XY_VERTICAL_BAR :
85 check(data, IntervalXYDataset.class, rendererIndex);
86 plot = new XYPlot((IntervalXYDataset) data, null, null, (XYItemRenderer) rend);
90 check(data, OHLCDataset.class, rendererIndex);
91 plot = new XYPlot((OHLCDataset) data, null, null, (XYItemRenderer) rend);
94 // check(data, SignalsDataset.class, rendererIndex);
95 // plot = new XYPlot((SignalsDataset) data, null, null, (XYItemRenderer) rend);
97 throw new AttributeValidationException(chartType + ".type", type);
99 } else if (chartType == ChartConstants.OVERLAY_CATEGORY) {
100 switch (rendererIndex) {
104 case SHAPES_AND_LINES :
105 check(data, CategoryDataset.class, rendererIndex);
108 (CategoryDataset) data,
111 (CategoryItemRenderer) rend);
114 throw new AttributeValidationException(chartType + ".type", type);
118 plot.setDrawingSupplier(drawingSupplier);
122 public Object getDataset() throws DatasetProduceException {
123 return dataAware.getDataset();
127 * Gets the y-axis label. [tb]
129 * @return the y-axis label.
131 public String getXaxislabel() {
136 * Sets the x-axis label [tb]
138 * @return the x-axis label
140 public String getYaxislabel() {
145 * Sets the x-axis label [tb]
147 * @param xAxisLabel New value of property xAxisLabel.
149 public void setXaxislabel(String xAxisLabel) {
150 this.xAxisLabel = xAxisLabel;
154 * Sets the y-axis label [tb]
156 * @param yAxisLabel New value of property yAxisLabel.
158 public void setYaxislabel(String yAxisLabel) {
159 this.yAxisLabel = yAxisLabel;
163 * @param type The type to set
165 public void setType(String type) {
170 * @return type of plot as a String
172 public String getType() {
176 public void check(Dataset data, Class clazz, int plotType) throws IncompatibleDatasetException {
177 if (!clazz.isInstance(data)) {
178 throw new IncompatibleDatasetException(
179 "Plots of type " + PlotTypes.typeNames[plotType] + " need a dataset of type " + clazz.getName());
183 public void setDataProductionConfig(DatasetProducer dsp, Map params, boolean useCache) {
184 log.debug("setDataProductionConfig(" + dsp + ", " + params);
185 dataAware.setDataProductionConfig(dsp, params, useCache);
189 * Sets the drawingSupplier.
190 * @param drawingSupplier The drawingSupplier to set
192 public void setDrawingSupplier(DrawingSupplier drawingSupplier) {
193 this.drawingSupplier = drawingSupplier;