KickJava   Java API By Example, From Geeks To Geeks.

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


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  * StandardPieURLGenerator.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: StandardPieURLGenerator.java,v 1.4 2005/05/19 14:01:15 mungady Exp $
35  *
36  * Changes:
37  * --------
38  * 05-Aug-2002 : Version 1, contributed by Richard Atkinson;
39  * 09-Oct-2002 : Fixed errors reported by Checkstyle (DG);
40  * 07-Mar-2003 : Modified to use KeyedValuesDataset and added pieIndex
41  * parameter (DG);
42  * 21-Mar-2003 : Implemented Serializable (DG);
43  * 24-Apr-2003 : Switched around PieDataset and KeyedValuesDataset (DG);
44  * 31-Mar-2004 : Added an optional 'pieIndex' parameter (DG);
45  * 13-Jan-2005 : Fixed for compliance with XHTML 1.0 (DG):
46  *
47  */

48  
49 package org.jfree.chart.urls;
50
51 import java.io.Serializable JavaDoc;
52
53 import org.jfree.data.general.PieDataset;
54
55 /**
56  * A URL generator for pie charts.
57  *
58  * @author Richard Atkinson
59  */

60 public class StandardPieURLGenerator implements PieURLGenerator, Serializable JavaDoc {
61
62     /** For serialization. */
63     private static final long serialVersionUID = 1626966402065883419L;
64     
65     /** The prefix. */
66     private String JavaDoc prefix = "index.html";
67
68     /** The category parameter name. */
69     private String JavaDoc categoryParameterName = "category";
70     
71     /** The pie index parameter name. */
72     private String JavaDoc indexParameterName = "pieIndex";
73
74     /**
75      * Default constructor.
76      */

77     public StandardPieURLGenerator() {
78         super();
79     }
80
81     /**
82      * Creates a new generator.
83      *
84      * @param prefix the prefix.
85      */

86     public StandardPieURLGenerator(String JavaDoc prefix) {
87         this.prefix = prefix;
88     }
89
90     /**
91      * Creates a new generator.
92      *
93      * @param prefix the prefix.
94      * @param categoryParameterName the category parameter name.
95      */

96     public StandardPieURLGenerator(String JavaDoc prefix,
97                                    String JavaDoc categoryParameterName) {
98         this.prefix = prefix;
99         this.categoryParameterName = categoryParameterName;
100     }
101
102     /**
103      * Creates a new generator.
104      *
105      * @param prefix the prefix.
106      * @param categoryParameterName the category parameter name.
107      * @param indexParameterName the index parameter name
108      * (<code>null</code> permitted).
109      */

110     public StandardPieURLGenerator(String JavaDoc prefix,
111                                    String JavaDoc categoryParameterName,
112                                    String JavaDoc indexParameterName) {
113         this.prefix = prefix;
114         this.categoryParameterName = categoryParameterName;
115         this.indexParameterName = indexParameterName;
116     }
117
118     /**
119      * Generates a URL.
120      *
121      * @param data the dataset.
122      * @param key the item key.
123      * @param pieIndex the pie index (ignored).
124      *
125      * @return A string containing the generated URL.
126      */

127     public String JavaDoc generateURL(PieDataset data, Comparable JavaDoc key, int pieIndex) {
128
129         String JavaDoc url = this.prefix;
130         if (url.indexOf("?") > -1) {
131             url += "&amp;" + this.categoryParameterName + "=" + key.toString();
132         }
133         else {
134             url += "?" + this.categoryParameterName + "=" + key.toString();
135         }
136         if (this.indexParameterName != null) {
137             url += "&amp;" + this.indexParameterName + "="
138                    + String.valueOf(pieIndex);
139         }
140         return url;
141
142     }
143
144     /**
145      * Tests if this object is equal to another.
146      *
147      * @param obj the object (<code>null</code> permitted).
148      *
149      * @return A boolean.
150      */

151     public boolean equals(Object JavaDoc obj) {
152
153         if (obj == null) {
154             return false;
155         }
156         if (obj == this) {
157             return true;
158         }
159
160         if ((obj instanceof StandardPieURLGenerator) == false) {
161             return false;
162         }
163
164         StandardPieURLGenerator generator = (StandardPieURLGenerator) obj;
165         return (
166             this.categoryParameterName.equals(generator.categoryParameterName))
167             && (this.prefix.equals(generator.prefix)
168         );
169
170     }
171 }
172
Popular Tags