KickJava   Java API By Example, From Geeks To Geeks.

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


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  * StandardXYURLGenerator.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: StandardXYURLGenerator.java,v 1.6 2005/05/19 14:01:16 mungady Exp $
35  *
36  * Changes:
37  * --------
38  * 05-Aug-2002 : Version 1, contributed by Richard Atkinson;
39  * 29-Aug-2002 : New constructor and member variables to customise series and
40  * item parameter names (RA);
41  * 09-Oct-2002 : Fixed errors reported by Checkstyle (DG);
42  * 23-Mar-2003 : Implemented Serializable (DG);
43  * 01-Mar-2004 : Added equals() method (DG);
44  * 13-Jan-2005 : Modified for XHTML 1.0 compliance (DG);
45  *
46  */

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

60 public class StandardXYURLGenerator implements XYURLGenerator, Serializable JavaDoc {
61     
62     /** For serialization. */
63     private static final long serialVersionUID = -1771624523496595382L;
64     
65     /** The default prefix. */
66     public static final String JavaDoc DEFAULT_PREFIX = "index.html";
67     
68     /** The default series parameter. */
69     public static final String JavaDoc DEFAULT_SERIES_PARAMETER = "series";
70     
71     /** The default item parameter. */
72     public static final String JavaDoc DEFAULT_ITEM_PARAMETER = "item";
73     
74     /** Prefix to the URL */
75     private String JavaDoc prefix;
76
77     /** Series parameter name to go in each URL */
78     private String JavaDoc seriesParameterName;
79
80     /** Item parameter name to go in each URL */
81     private String JavaDoc itemParameterName;
82
83     /**
84      * Creates a new default generator. This constructor is equivalent to
85      * calling <code>StandardXYURLGenerator("index.html", "series", "item");
86      * </code>.
87      */

88     public StandardXYURLGenerator() {
89         this(DEFAULT_PREFIX, DEFAULT_SERIES_PARAMETER, DEFAULT_ITEM_PARAMETER);
90     }
91
92     /**
93      * Creates a new generator with the specified prefix. This constructor
94      * is equivalent to calling
95      * <code>StandardXYURLGenerator(prefix, "series", "item");</code>.
96      *
97      * @param prefix the prefix to the URL (<code>null</code> not permitted).
98      */

99     public StandardXYURLGenerator(String JavaDoc prefix) {
100         this(prefix, DEFAULT_SERIES_PARAMETER, DEFAULT_ITEM_PARAMETER);
101     }
102
103     /**
104      * Constructor that overrides all the defaults
105      *
106      * @param prefix the prefix to the URL (<code>null</code> not permitted).
107      * @param seriesParameterName the name of the series parameter to go in
108      * each URL (<code>null</code> not permitted).
109      * @param itemParameterName the name of the item parameter to go in each
110      * URL (<code>null</code> not permitted).
111      */

112     public StandardXYURLGenerator(String JavaDoc prefix,
113                                   String JavaDoc seriesParameterName,
114                                   String JavaDoc itemParameterName) {
115         if (prefix == null) {
116             throw new IllegalArgumentException JavaDoc("Null 'prefix' argument.");
117         }
118         if (seriesParameterName == null) {
119             throw new IllegalArgumentException JavaDoc(
120                 "Null 'seriesParameterName' argument."
121             );
122         }
123         if (itemParameterName == null) {
124             throw new IllegalArgumentException JavaDoc(
125                 "Null 'itemParameterName' argument."
126             );
127         }
128         this.prefix = prefix;
129         this.seriesParameterName = seriesParameterName;
130         this.itemParameterName = itemParameterName;
131     }
132
133     /**
134      * Generates a URL for a particular item within a series.
135      *
136      * @param dataset the dataset.
137      * @param series the series number (zero-based index).
138      * @param item the item number (zero-based index).
139      *
140      * @return The generated URL.
141      */

142     public String JavaDoc generateURL(XYDataset dataset, int series, int item) {
143         String JavaDoc url = this.prefix;
144         boolean firstParameter = url.indexOf("?") == -1;
145         url += firstParameter ? "?" : "&amp;";
146         url += this.seriesParameterName + "=" + series
147             + "&amp;" + this.itemParameterName + "=" + item;
148         return url;
149     }
150
151     /**
152      * Tests this generator for equality with an arbitrary object.
153      *
154      * @param obj the object (<code>null</code> permitted).
155      *
156      * @return A boolean.
157      */

158     public boolean equals(Object JavaDoc obj) {
159         if (obj == this) {
160             return true;
161         }
162         if (!(obj instanceof StandardXYURLGenerator)) {
163             return false;
164         }
165         StandardXYURLGenerator that = (StandardXYURLGenerator) obj;
166         if (!ObjectUtilities.equal(that.prefix, this.prefix)) {
167             return false;
168         }
169         if (!ObjectUtilities.equal(that.seriesParameterName,
170                 this.seriesParameterName)) {
171             return false;
172         }
173         if (!ObjectUtilities.equal(that.itemParameterName,
174                 this.itemParameterName)) {
175             return false;
176         }
177         return true;
178     }
179     
180 }
181
Popular Tags