Frames | No Frames |
1: /* =========================================================== 2: * JFreeChart : a free chart library for the Java(tm) platform 3: * =========================================================== 4: * 5: * (C) Copyright 2000-2007, 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 20: * License along with this library; if not, write to the Free Software 21: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22: * USA. 23: * 24: * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 25: * in the United States and other countries.] 26: * 27: * ------------------------- 28: * CustomXYURLGenerator.java 29: * ------------------------- 30: * (C) Copyright 2002-2007, by Richard Atkinson and Contributors. 31: * 32: * Original Author: Richard Atkinson; 33: * Contributors: David Gilbert (for Object Refinery Limited); 34: * 35: * Changes: 36: * -------- 37: * 05-Aug-2002 : Version 1, contributed by Richard Atkinson; 38: * 09-Oct-2002 : Fixed errors reported by Checkstyle (DG); 39: * 23-Mar-2003 : Implemented Serializable (DG); 40: * 20-Jan-2005 : Minor Javadoc update (DG); 41: * ------------- JFREECHART 1.0.x --------------------------------------------- 42: * 02-Feb-2007 : Removed author tags from all over JFreeChart sources (DG); 43: * 44: */ 45: 46: package org.jfree.chart.urls; 47: 48: import java.io.Serializable; 49: import java.util.ArrayList; 50: import java.util.List; 51: 52: import org.jfree.data.xy.XYDataset; 53: 54: /** 55: * A custom URL generator. 56: */ 57: public class CustomXYURLGenerator implements XYURLGenerator, Serializable { 58: 59: /** For serialization. */ 60: private static final long serialVersionUID = -8565933356596551832L; 61: 62: /** Storage for the URLs. */ 63: private ArrayList urlSeries = new ArrayList(); 64: 65: /** 66: * Default constructor. 67: */ 68: public CustomXYURLGenerator() { 69: super(); 70: } 71: 72: /** 73: * Returns the number of URL lists stored by the renderer. 74: * 75: * @return The list count. 76: */ 77: public int getListCount() { 78: return this.urlSeries.size(); 79: } 80: 81: /** 82: * Returns the number of URLs in a given list. 83: * 84: * @param list the list index (zero based). 85: * 86: * @return The URL count. 87: */ 88: public int getURLCount(int list) { 89: int result = 0; 90: List urls = (List) this.urlSeries.get(list); 91: if (urls != null) { 92: result = urls.size(); 93: } 94: return result; 95: } 96: 97: /** 98: * Returns the URL for an item. 99: * 100: * @param series the series index. 101: * @param item the item index. 102: * 103: * @return The URL (possibly <code>null</code>). 104: */ 105: public String getURL(int series, int item) { 106: String result = null; 107: if (series < getListCount()) { 108: List urls = (List) this.urlSeries.get(series); 109: if (urls != null) { 110: if (item < urls.size()) { 111: result = (String) urls.get(item); 112: } 113: } 114: } 115: return result; 116: } 117: 118: /** 119: * Generates a URL. 120: * 121: * @param dataset the dataset. 122: * @param series the series (zero-based index). 123: * @param item the item (zero-based index). 124: * 125: * @return A string containing the URL (possibly <code>null</code>). 126: */ 127: public String generateURL(XYDataset dataset, int series, int item) { 128: return getURL(series, item); 129: } 130: 131: /** 132: * Adds a list of URLs. 133: * 134: * @param urls the list of URLs. 135: */ 136: public void addURLSeries(List urls) { 137: this.urlSeries.add(urls); 138: } 139: 140: /** 141: * Tests if this object is equal to another. 142: * 143: * @param o the other object. 144: * 145: * @return A boolean. 146: */ 147: public boolean equals(Object o) { 148: 149: if (o == null) { 150: return false; 151: } 152: if (o == this) { 153: return true; 154: } 155: 156: if (!(o instanceof CustomXYURLGenerator)) { 157: return false; 158: } 159: CustomXYURLGenerator generator = (CustomXYURLGenerator) o; 160: int listCount = getListCount(); 161: if (listCount != generator.getListCount()) { 162: return false; 163: } 164: 165: for (int series = 0; series < listCount; series++) { 166: int urlCount = getURLCount(series); 167: if (urlCount != generator.getURLCount(series)) { 168: return false; 169: } 170: 171: for (int item = 0; item < urlCount; item++) { 172: String u1 = getURL(series, item); 173: String u2 = generator.getURL(series, item); 174: if (u1 != null) { 175: if (!u1.equals(u2)) { 176: return false; 177: } 178: } 179: else { 180: if (u2 != null) { 181: return false; 182: } 183: } 184: } 185: } 186: return true; 187: 188: } 189: 190: }