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
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 the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 * See the GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License along with this
19 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 * Boston, MA 02111-1307, USA.
23 package de.laures.cewolf.taglib;
25 import java.util.Arrays;
26 import java.util.List;
28 import org.jfree.chart.renderer.AbstractRenderer;
29 import org.jfree.chart.renderer.category.AreaRenderer;
30 import org.jfree.chart.renderer.category.BarRenderer;
31 import org.jfree.chart.renderer.category.LineAndShapeRenderer;
32 import org.jfree.chart.renderer.xy.CandlestickRenderer;
33 import org.jfree.chart.renderer.xy.HighLowRenderer;
34 import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
35 import org.jfree.chart.renderer.xy.XYAreaRenderer;
36 import org.jfree.chart.renderer.xy.XYBarRenderer;
37 import org.jfree.chart.renderer.xy.XYStepRenderer;
40 * Contains the list of all possible plot type string values which can be used
41 * in the <code>type</code> attribute of a <chart> tag.
43 * It also contains all the renders that correspond with the plot types
44 * @author Chris McCann
46 public class PlotTypes {
48 /** All type strings in an array */
49 public static final String[] typeNames =
66 * The whole typeNames array inside of a list.
69 private static final List typeList = Arrays.asList(typeNames);
72 * Create a renderer for the given type index.
73 * We create a new renderer instance for each chart, because they may want to customize
74 * it in a post-processor.
76 * @param idx The index of the type
77 * @return A new renderer instance
79 public static AbstractRenderer getRenderer(int idx) {
81 case 0: return new XYAreaRenderer();
82 case 1: return new StandardXYItemRenderer();
83 case 2: return new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES);
84 case 3: return new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES);
85 case 4: return new XYBarRenderer();
86 case 5: return new XYStepRenderer();
87 case 6: return new CandlestickRenderer();
88 case 7: return new HighLowRenderer();
89 //case 8: return new SignalRenderer();
90 case 9: return new BarRenderer();
91 case 10: return new AreaRenderer();
92 case 11: return new LineAndShapeRenderer(true,false);
93 case 12: return new LineAndShapeRenderer(true,true);
95 throw new RuntimeException("Invalid renderer index:" + idx);
103 * Get the renderer index for the given plot type.
104 * @param plotType The type string of the plot
105 * @return The index The index of renderer
106 * @throws AttributeValidationException if unknown type
108 public static int getRendererIndex(String plotType) throws AttributeValidationException {
109 int rendererIndex = PlotTypes.typeList.indexOf(plotType.toLowerCase());
110 if (rendererIndex < 0) {
111 throw new AttributeValidationException("plot.type", plotType);
113 return rendererIndex;