001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jfreechart/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * -------------------------
028: * CustomXYURLGenerator.java
029: * -------------------------
030: * (C) Copyright 2002-2007, by Richard Atkinson and Contributors.
031: *
032: * Original Author: Richard Atkinson;
033: * Contributors: David Gilbert (for Object Refinery Limited);
034: *
035: * $Id: CustomXYURLGenerator.java,v 1.5.2.2 2007/02/02 15:51:05 mungady Exp $
036: *
037: * Changes:
038: * --------
039: * 05-Aug-2002 : Version 1, contributed by Richard Atkinson;
040: * 09-Oct-2002 : Fixed errors reported by Checkstyle (DG);
041: * 23-Mar-2003 : Implemented Serializable (DG);
042: * 20-Jan-2005 : Minor Javadoc update (DG);
043: * ------------- JFREECHART 1.0.x ---------------------------------------------
044: * 02-Feb-2007 : Removed author tags from all over JFreeChart sources (DG);
045: *
046: */
047:
048: package org.jfree.chart.urls;
049:
050: import java.io.Serializable;
051: import java.util.ArrayList;
052: import java.util.List;
053:
054: import org.jfree.data.xy.XYDataset;
055:
056: /**
057: * A custom URL generator.
058: */
059: public class CustomXYURLGenerator implements XYURLGenerator,
060: Serializable {
061:
062: /** For serialization. */
063: private static final long serialVersionUID = -8565933356596551832L;
064:
065: /** Storage for the URLs. */
066: private ArrayList urlSeries = new ArrayList();
067:
068: /**
069: * Default constructor.
070: */
071: public CustomXYURLGenerator() {
072: super ();
073: }
074:
075: /**
076: * Returns the number of URL lists stored by the renderer.
077: *
078: * @return The list count.
079: */
080: public int getListCount() {
081: return this .urlSeries.size();
082: }
083:
084: /**
085: * Returns the number of URLs in a given list.
086: *
087: * @param list the list index (zero based).
088: *
089: * @return The URL count.
090: */
091: public int getURLCount(int list) {
092: int result = 0;
093: List urls = (List) this .urlSeries.get(list);
094: if (urls != null) {
095: result = urls.size();
096: }
097: return result;
098: }
099:
100: /**
101: * Returns the URL for an item.
102: *
103: * @param series the series index.
104: * @param item the item index.
105: *
106: * @return The URL (possibly <code>null</code>).
107: */
108: public String getURL(int series, int item) {
109: String result = null;
110: if (series < getListCount()) {
111: List urls = (List) this .urlSeries.get(series);
112: if (urls != null) {
113: if (item < urls.size()) {
114: result = (String) urls.get(item);
115: }
116: }
117: }
118: return result;
119: }
120:
121: /**
122: * Generates a URL.
123: *
124: * @param dataset the dataset.
125: * @param series the series (zero-based index).
126: * @param item the item (zero-based index).
127: *
128: * @return A string containing the URL (possibly <code>null</code>).
129: */
130: public String generateURL(XYDataset dataset, int series, int item) {
131: return getURL(series, item);
132: }
133:
134: /**
135: * Adds a list of URLs.
136: *
137: * @param urls the list of URLs.
138: */
139: public void addURLSeries(List urls) {
140: this .urlSeries.add(urls);
141: }
142:
143: /**
144: * Tests if this object is equal to another.
145: *
146: * @param o the other object.
147: *
148: * @return A boolean.
149: */
150: public boolean equals(Object o) {
151:
152: if (o == null) {
153: return false;
154: }
155: if (o == this ) {
156: return true;
157: }
158:
159: if (!(o instanceof CustomXYURLGenerator)) {
160: return false;
161: }
162: CustomXYURLGenerator generator = (CustomXYURLGenerator) o;
163: int listCount = getListCount();
164: if (listCount != generator.getListCount()) {
165: return false;
166: }
167:
168: for (int series = 0; series < listCount; series++) {
169: int urlCount = getURLCount(series);
170: if (urlCount != generator.getURLCount(series)) {
171: return false;
172: }
173:
174: for (int item = 0; item < urlCount; item++) {
175: String u1 = getURL(series, item);
176: String u2 = generator.getURL(series, item);
177: if (u1 != null) {
178: if (!u1.equals(u2)) {
179: return false;
180: }
181: } else {
182: if (u2 != null) {
183: return false;
184: }
185: }
186: }
187: }
188: return true;
189:
190: }
191:
192: }
|