KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > laures > cewolf > example > RandomXYData


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.example;
24
25 import java.io.Serializable JavaDoc;
26 import java.util.Date JavaDoc;
27 import java.util.Map JavaDoc;
28
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31 import org.jfree.data.xy.XYSeries;
32 import org.jfree.data.xy.XYSeriesCollection;
33
34 import de.laures.cewolf.DatasetProduceException;
35 import de.laures.cewolf.DatasetProducer;
36
37 /**
38  * Sample DatasetProducer whioh creates random XYDatasets.
39  * @author Guido Laures
40  */

41 public class RandomXYData implements DatasetProducer, Serializable JavaDoc {
42
43     private static final Log log = LogFactory.getLog(RandomXYData.class);
44
45     /**
46      * Produces a random XYDataset.
47      * @return a random XYDataset
48      */

49     public Object JavaDoc produceDataset(Map JavaDoc params) throws DatasetProduceException {
50         log.debug("prodcing data.");
51         XYSeries xys = new XYSeries("Example XY Dataset");
52         int maxVal = 100;
53         if (params.containsKey("maxVal")) {
54             maxVal = ((Integer JavaDoc)params.get("maxVal")).intValue();
55         }
56         int minVal = -100;
57         if (params.containsKey("minVal")) {
58             minVal = ((Integer JavaDoc)params.get("minVal")).intValue();
59         }
60         final int inset = (maxVal - minVal) / 2;
61         double last = maxVal - inset;
62         for (int i = -10; i <= 10; i++) {
63             final double y = Math.max(Math.min(last + ((Math.random() * inset) - inset / 2), maxVal), minVal);
64             xys.add(i, y);
65             last = y;
66         }
67         return new XYSeriesCollection(xys);
68     }
69
70     /**
71      * @see de.laures.cewolf.DatasetProducer#hasExpired(Map, Date)
72      */

73     public boolean hasExpired(Map JavaDoc params, Date JavaDoc since) {
74         log.debug(this + ".hasExpired()");
75         return false;
76     }
77     
78     public String JavaDoc getProducerId(){
79         return "RandomXYData DatsetProducer";
80     }
81
82 }
83
Popular Tags