java/cewolf-1.0/src/main/java/de/laures/cewolf/taglib/PlotTypes.java
author František Kučera <franta-hg@frantovo.cz>
Sat, 28 Feb 2009 21:31:02 +0100
changeset 1 639991d0808a
permissions -rw-r--r--
Rozbalená knihovna verze 1.0
     1 /* ================================================================
     2  * Cewolf : Chart enabling Web Objects Framework
     3  * ================================================================
     4  *
     5  * Project Info:  http://cewolf.sourceforge.net
     6  * Project Lead:  Guido Laures (guido@laures.de);
     7  *
     8  * (C) Copyright 2002, by Guido Laures
     9  *
    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.
    13  *
    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.
    17  *
    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.
    21  */
    22 
    23 package de.laures.cewolf.taglib;
    24 
    25 import java.util.Arrays;
    26 import java.util.List;
    27 
    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;
    38 
    39 /**
    40  * Contains the list of all possible plot type string values which can be used
    41  * in the <code>type</code> attribute of a &lt;chart&gt; tag.
    42  *
    43  * It also contains all the renders that correspond with the plot types
    44  * @author  Chris McCann
    45  */
    46 public class PlotTypes {
    47 
    48 	/** All type strings in an array */
    49 	public static final String[] typeNames =
    50 		{
    51 			"xyarea",
    52 			"xyline",
    53 			"xyshapesandlines",
    54 			"scatter",
    55 			"xyverticalbar",
    56 			"step",
    57 			"candlestick",
    58 			"highlow",
    59 			"signal",
    60 			"verticalbar",
    61 			"area",
    62 			"line",
    63 			"shapesandlines" };
    64 
    65 	/**
    66 	 * The whole typeNames array inside of a list.
    67 	 * @see #typeNames
    68 	 */
    69 	private static final List typeList = Arrays.asList(typeNames);
    70 	
    71 	/**
    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.
    75 	 * 
    76 	 * @param idx The index of the type
    77 	 * @return A new renderer instance
    78 	 */
    79 	public static AbstractRenderer getRenderer(int idx) {
    80 		switch (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);
    94 			default:
    95 				throw new RuntimeException("Invalid renderer index:" + idx);
    96 		}		
    97 	}
    98 
    99 	private PlotTypes() {
   100 	}
   101 
   102     /**
   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
   107      */
   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);
   112         }
   113         return rendererIndex;
   114     }
   115 
   116 }