KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > urls > TimeSeriesURLGenerator


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jfreechart/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this library; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
24  * in the United States and other countries.]
25  *
26  * ---------------------------
27  * TimeSeriesURLGenerator.java
28  * ---------------------------
29  * (C) Copyright 2002-2005, by Richard Atkinson and Contributors.
30  *
31  * Original Author: Richard Atkinson;
32  * Contributors: David Gilbert (for Object Refinery Limited);
33  *
34  * $Id: TimeSeriesURLGenerator.java,v 1.5 2005/05/20 08:20:04 mungady Exp $
35  *
36  * Changes:
37  * --------
38  * 29-Aug-2002 : Initial version (RA);
39  * 09-Oct-2002 : Fixed errors reported by Checkstyle (DG);
40  * 23-Mar-2003 : Implemented Serializable (DG);
41  * 15-Jul-2004 : Switched getX() with getXValue() and getY() with
42  * getYValue() (DG);
43  * 13-Jan-2005 : Modified for XHTML 1.0 compliance (DG);
44  *
45  */

46
47 package org.jfree.chart.urls;
48
49 import java.io.Serializable JavaDoc;
50 import java.text.DateFormat JavaDoc;
51 import java.util.Date JavaDoc;
52
53 import org.jfree.data.xy.XYDataset;
54
55 /**
56  * A URL generator.
57  *
58  * @author Richard Atkinson
59  */

60 public class TimeSeriesURLGenerator implements XYURLGenerator, Serializable JavaDoc {
61
62     /** For serialization. */
63     private static final long serialVersionUID = -9122773175671182445L;
64     
65     /** A formatter for the date. */
66     private DateFormat JavaDoc dateFormat = DateFormat.getInstance();
67     
68     /** Prefix to the URL */
69     private String JavaDoc prefix = "index.html";
70
71     /** Name to use to identify the series */
72     private String JavaDoc seriesParameterName = "series";
73
74     /** Name to use to identify the item */
75     private String JavaDoc itemParameterName = "item";
76
77     /**
78      * Blank constructor
79      */

80     public TimeSeriesURLGenerator() {
81         super();
82     }
83
84     /**
85      * Construct TimeSeriesURLGenerator overriding defaults
86      *
87      * @param dDateFormat a formatter for the date.
88      * @param sPrefix the prefix of the URL.
89      * @param sSeriesParameterName the name of the series parameter in the URL.
90      * @param sItemParameterName the name of the item parameter in the URL.
91      */

92     public TimeSeriesURLGenerator(DateFormat JavaDoc dDateFormat, String JavaDoc sPrefix,
93                                   String JavaDoc sSeriesParameterName,
94                                   String JavaDoc sItemParameterName) {
95
96         this.dateFormat = dDateFormat;
97         this.prefix = sPrefix;
98         this.seriesParameterName = sSeriesParameterName;
99         this.itemParameterName = sItemParameterName;
100
101     }
102
103     /**
104      * Generates a URL for a particular item within a series.
105      *
106      * @param dataset the dataset.
107      * @param series the series number (zero-based index).
108      * @param item the item number (zero-based index).
109      *
110      * @return The generated URL.
111      */

112     public String JavaDoc generateURL(XYDataset dataset, int series, int item) {
113         String JavaDoc result = this.prefix;
114         boolean firstParameter = result.indexOf("?") == -1;
115         Comparable JavaDoc seriesKey = dataset.getSeriesKey(series);
116         if (seriesKey != null) {
117             result += firstParameter ? "?" : "&";
118             result += this.seriesParameterName + "=" + seriesKey.toString();
119             firstParameter = false;
120         }
121
122         long x = dataset.getX(series, item).longValue();
123         String JavaDoc xValue = this.dateFormat.format(new Date JavaDoc(x));
124         result += firstParameter ? "?" : "&";
125         result += this.itemParameterName + "=" + xValue;
126
127         return result;
128     }
129
130
131 }
132
Popular Tags