KickJava   Java API By Example, From Geeks To Geeks.

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


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  * CustomXYURLGenerator.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: CustomXYURLGenerator.java,v 1.5 2005/05/19 14:01:16 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  * 23-Mar-2003 : Implemented Serializable (DG);
41  * 20-Jan-2005 : Minor Javadoc update (DG);
42  *
43  */

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

58 public class CustomXYURLGenerator implements XYURLGenerator, Serializable JavaDoc {
59
60     /** For serialization. */
61     private static final long serialVersionUID = -8565933356596551832L;
62     
63     /** Storage for the URLs. */
64     private ArrayList JavaDoc urlSeries = new ArrayList JavaDoc();
65
66     /**
67      * Default constructor.
68      */

69     public CustomXYURLGenerator() {
70         super();
71     }
72
73     /**
74      * Returns the number of URL lists stored by the renderer.
75      *
76      * @return The list count.
77      */

78     public int getListCount() {
79         return this.urlSeries.size();
80     }
81
82     /**
83      * Returns the number of URLs in a given list.
84      *
85      * @param list the list index (zero based).
86      *
87      * @return The URL count.
88      */

89     public int getURLCount(int list) {
90         int result = 0;
91         List JavaDoc urls = (List JavaDoc) this.urlSeries.get(list);
92         if (urls != null) {
93             result = urls.size();
94         }
95         return result;
96     }
97
98     /**
99      * Returns the URL for an item.
100      *
101      * @param series the series index.
102      * @param item the item index.
103      *
104      * @return The URL (possibly <code>null</code>).
105      */

106     public String JavaDoc getURL(int series, int item) {
107         String JavaDoc result = null;
108         if (series < getListCount()) {
109             List JavaDoc urls = (List JavaDoc) this.urlSeries.get(series);
110             if (urls != null) {
111                 if (item < urls.size()) {
112                     result = (String JavaDoc) urls.get(item);
113                 }
114             }
115         }
116         return result;
117     }
118
119     /**
120      * Generates a URL.
121      *
122      * @param dataset the dataset.
123      * @param series the series (zero-based index).
124      * @param item the item (zero-based index).
125      *
126      * @return A string containing the URL (possibly <code>null</code>).
127      */

128     public String JavaDoc generateURL(XYDataset dataset, int series, int item) {
129         return getURL(series, item);
130     }
131
132     /**
133      * Adds a list of URLs.
134      *
135      * @param urls the list of URLs.
136      */

137     public void addURLSeries(List JavaDoc urls) {
138         this.urlSeries.add(urls);
139     }
140
141     /**
142      * Tests if this object is equal to another.
143      *
144      * @param o the other object.
145      *
146      * @return A boolean.
147      */

148     public boolean equals(Object JavaDoc o) {
149
150         if (o == null) {
151             return false;
152         }
153         if (o == this) {
154             return true;
155         }
156
157         if (!(o instanceof CustomXYURLGenerator)) {
158             return false;
159         }
160         CustomXYURLGenerator generator = (CustomXYURLGenerator) o;
161         int listCount = getListCount();
162         if (listCount != generator.getListCount()) {
163             return false;
164         }
165
166         for (int series = 0; series < listCount; series++) {
167             int urlCount = getURLCount(series);
168             if (urlCount != generator.getURLCount(series)) {
169                 return false;
170             }
171
172             for (int item = 0; item < urlCount; item++) {
173                 String JavaDoc u1 = getURL(series, item);
174                 String JavaDoc u2 = generator.getURL(series, item);
175                 if (u1 != null) {
176                     if (!u1.equals(u2)) {
177                         return false;
178                     }
179                 }
180                 else {
181                     if (u2 != null) {
182                         return false;
183                     }
184                 }
185             }
186         }
187         return true;
188
189     }
190
191 }
192
Popular Tags