KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jcckit > plot > SimpleCurveFactory


1 /*
2  * Copyright 2003-2004, Franz-Josef Elmer, All rights reserved
3  *
4  * This library is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation; either version 2.1 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details
13  * (http://www.gnu.org/copyleft/lesser.html).
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package jcckit.plot;
20
21 import java.util.Properties JavaDoc;
22 import java.util.StringTokenizer JavaDoc;
23
24 import jcckit.graphic.ClippingShape;
25 import jcckit.util.ConfigParameters;
26 import jcckit.util.PropertiesBasedConfigData;
27
28 /**
29  * Factory for {@link SimpleCurve SimpleCurves}.
30  *
31  * @author Franz-Josef Elmer
32  */

33 public class SimpleCurveFactory implements CurveFactory {
34   /** Configuration parameter key. */
35   public static final String JavaDoc DEFINITIONS_KEY = "definitions";
36
37   private ConfigParameters[] _configs = new ConfigParameters[]
38       {new ConfigParameters(new PropertiesBasedConfigData(new Properties JavaDoc()))};
39
40   /**
41    * Creates an instance from the specified configuration parameter.
42    * <table border=1 cellpadding=5>
43    * <tr><th>Key &amp; Default Value</th><th>Type</th><th>Mandatory</th>
44    * <th>Description</th></tr>
45    * <tr><td><tt>definitions = </tt><i>one empty <tt>ConfigParameters<tt>
46    * instance</i></td>
47    * <td><tt>String[]</tt></td><td>no</td>
48    * <td>Keys of subtrees defining {@link ConfigParameters}
49    * used by the {@link SimpleCurve#SimpleCurve constructor} of
50    * {@link SimpleCurve}.</td></tr>
51    * </table>
52    */

53   public SimpleCurveFactory(ConfigParameters config) {
54     String JavaDoc value = config.get(DEFINITIONS_KEY, null);
55     if (value != null) {
56       StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(value);
57       _configs = new ConfigParameters[tokenizer.countTokens()];
58       for (int i = 0; i < _configs.length; i++) {
59         _configs[i] = config.getNode(tokenizer.nextToken());
60       }
61     }
62   }
63
64   /**
65    * Creates an instance of {@link SimpleCurve}.
66    * @param curveIndex Index of the curve. Will be used to select the
67    * {@link ConfigParameters} object and the line attributes.
68    * In addition it will be used to calculate the y-coordinate
69    * of the legend symbol.
70    * @param numberOfCurves Number of curves. Will be needed to calculate
71    * the y-coordinate of the legend symbol.
72    * @param clippingShape The clipping shape.
73    * @param legend The legend. Will be needed to create the legend symbol.
74    */

75   public Curve create(int curveIndex, int numberOfCurves,
76                       ClippingShape clippingShape, Legend legend) {
77     return new SimpleCurve(_configs[curveIndex % _configs.length], curveIndex,
78                            numberOfCurves, clippingShape, legend);
79   }
80 }
81
Popular Tags