java/cewolf-1.0/src/main/java/de/laures/cewolf/taglib/PlotTypes.java
changeset 1 639991d0808a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/java/cewolf-1.0/src/main/java/de/laures/cewolf/taglib/PlotTypes.java	Sat Feb 28 21:31:02 2009 +0100
     1.3 @@ -0,0 +1,116 @@
     1.4 +/* ================================================================
     1.5 + * Cewolf : Chart enabling Web Objects Framework
     1.6 + * ================================================================
     1.7 + *
     1.8 + * Project Info:  http://cewolf.sourceforge.net
     1.9 + * Project Lead:  Guido Laures (guido@laures.de);
    1.10 + *
    1.11 + * (C) Copyright 2002, by Guido Laures
    1.12 + *
    1.13 + * This library is free software; you can redistribute it and/or modify it under the terms
    1.14 + * of the GNU Lesser General Public License as published by the Free Software Foundation;
    1.15 + * either version 2.1 of the License, or (at your option) any later version.
    1.16 + *
    1.17 + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    1.18 + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    1.19 + * See the GNU Lesser General Public License for more details.
    1.20 + *
    1.21 + * You should have received a copy of the GNU Lesser General Public License along with this
    1.22 + * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
    1.23 + * Boston, MA 02111-1307, USA.
    1.24 + */
    1.25 +
    1.26 +package de.laures.cewolf.taglib;
    1.27 +
    1.28 +import java.util.Arrays;
    1.29 +import java.util.List;
    1.30 +
    1.31 +import org.jfree.chart.renderer.AbstractRenderer;
    1.32 +import org.jfree.chart.renderer.category.AreaRenderer;
    1.33 +import org.jfree.chart.renderer.category.BarRenderer;
    1.34 +import org.jfree.chart.renderer.category.LineAndShapeRenderer;
    1.35 +import org.jfree.chart.renderer.xy.CandlestickRenderer;
    1.36 +import org.jfree.chart.renderer.xy.HighLowRenderer;
    1.37 +import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
    1.38 +import org.jfree.chart.renderer.xy.XYAreaRenderer;
    1.39 +import org.jfree.chart.renderer.xy.XYBarRenderer;
    1.40 +import org.jfree.chart.renderer.xy.XYStepRenderer;
    1.41 +
    1.42 +/**
    1.43 + * Contains the list of all possible plot type string values which can be used
    1.44 + * in the <code>type</code> attribute of a &lt;chart&gt; tag.
    1.45 + *
    1.46 + * It also contains all the renders that correspond with the plot types
    1.47 + * @author  Chris McCann
    1.48 + */
    1.49 +public class PlotTypes {
    1.50 +
    1.51 +	/** All type strings in an array */
    1.52 +	public static final String[] typeNames =
    1.53 +		{
    1.54 +			"xyarea",
    1.55 +			"xyline",
    1.56 +			"xyshapesandlines",
    1.57 +			"scatter",
    1.58 +			"xyverticalbar",
    1.59 +			"step",
    1.60 +			"candlestick",
    1.61 +			"highlow",
    1.62 +			"signal",
    1.63 +			"verticalbar",
    1.64 +			"area",
    1.65 +			"line",
    1.66 +			"shapesandlines" };
    1.67 +
    1.68 +	/**
    1.69 +	 * The whole typeNames array inside of a list.
    1.70 +	 * @see #typeNames
    1.71 +	 */
    1.72 +	private static final List typeList = Arrays.asList(typeNames);
    1.73 +	
    1.74 +	/**
    1.75 +	 * Create a renderer for the given type index.
    1.76 +	 * We create a new renderer instance for each chart, because they may want to customize
    1.77 +	 * it in a post-processor.
    1.78 +	 * 
    1.79 +	 * @param idx The index of the type
    1.80 +	 * @return A new renderer instance
    1.81 +	 */
    1.82 +	public static AbstractRenderer getRenderer(int idx) {
    1.83 +		switch (idx) {
    1.84 +			case 0: return new XYAreaRenderer();
    1.85 +			case 1: return new StandardXYItemRenderer();
    1.86 +			case 2: return new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES);
    1.87 +			case 3: return new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES);
    1.88 +			case 4: return new XYBarRenderer();
    1.89 +			case 5: return new XYStepRenderer();
    1.90 +			case 6: return new CandlestickRenderer();
    1.91 +			case 7: return new HighLowRenderer();
    1.92 +			//case 8: return new SignalRenderer();
    1.93 +			case 9: return new BarRenderer();
    1.94 +			case 10: return new AreaRenderer();
    1.95 +			case 11: return new LineAndShapeRenderer(true,false);
    1.96 +			case 12: return new LineAndShapeRenderer(true,true);
    1.97 +			default:
    1.98 +				throw new RuntimeException("Invalid renderer index:" + idx);
    1.99 +		}		
   1.100 +	}
   1.101 +
   1.102 +	private PlotTypes() {
   1.103 +	}
   1.104 +
   1.105 +    /**
   1.106 +     * Get the renderer index for the given plot type.
   1.107 +     * @param plotType The type string of the plot
   1.108 +     * @return The index The index of renderer
   1.109 +     * @throws AttributeValidationException if unknown type
   1.110 +     */
   1.111 +    public static int getRendererIndex(String plotType) throws AttributeValidationException  {
   1.112 +        int rendererIndex = PlotTypes.typeList.indexOf(plotType.toLowerCase());
   1.113 +        if (rendererIndex < 0) {
   1.114 +          throw new AttributeValidationException("plot.type", plotType);
   1.115 +        }
   1.116 +        return rendererIndex;
   1.117 +    }
   1.118 +
   1.119 +}