001 /* =========================================================== 002 * JFreeChart : a free chart library for the Java(tm) platform 003 * =========================================================== 004 * 005 * (C) Copyright 2000-2006, 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 * StandardPieURLGenerator.java 029 * ---------------------------- 030 * (C) Copyright 2002-2006, by Richard Atkinson and Contributors. 031 * 032 * Original Author: Richard Atkinson; 033 * Contributors: David Gilbert (for Object Refinery Limited); 034 * 035 * $Id: StandardPieURLGenerator.java,v 1.4.2.2 2006/11/24 10:47:27 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 * 07-Mar-2003 : Modified to use KeyedValuesDataset and added pieIndex 042 * parameter (DG); 043 * 21-Mar-2003 : Implemented Serializable (DG); 044 * 24-Apr-2003 : Switched around PieDataset and KeyedValuesDataset (DG); 045 * 31-Mar-2004 : Added an optional 'pieIndex' parameter (DG); 046 * 13-Jan-2005 : Fixed for compliance with XHTML 1.0 (DG); 047 * ------------- JFREECHART 1.0.x --------------------------------------------- 048 * 24-Nov-2006 : Fixed equals() method and added argument checks (DG); 049 * 050 */ 051 052 package org.jfree.chart.urls; 053 054 import java.io.Serializable; 055 056 import org.jfree.data.general.PieDataset; 057 import org.jfree.util.ObjectUtilities; 058 059 /** 060 * A URL generator for pie charts. Instances of this class are immutable. 061 */ 062 public class StandardPieURLGenerator implements PieURLGenerator, Serializable { 063 064 /** For serialization. */ 065 private static final long serialVersionUID = 1626966402065883419L; 066 067 /** The prefix. */ 068 private String prefix = "index.html"; 069 070 /** The category parameter name. */ 071 private String categoryParameterName = "category"; 072 073 /** The pie index parameter name. */ 074 private String indexParameterName = "pieIndex"; 075 076 /** 077 * Default constructor. 078 */ 079 public StandardPieURLGenerator() { 080 this("index.html"); 081 } 082 083 /** 084 * Creates a new generator. 085 * 086 * @param prefix the prefix (<code>null</code> not permitted). 087 */ 088 public StandardPieURLGenerator(String prefix) { 089 this(prefix, "category"); 090 } 091 092 /** 093 * Creates a new generator. 094 * 095 * @param prefix the prefix (<code>null</code> not permitted). 096 * @param categoryParameterName the category parameter name 097 * (<code>null</code> not permitted). 098 */ 099 public StandardPieURLGenerator(String prefix, 100 String categoryParameterName) { 101 this(prefix, categoryParameterName, "pieIndex"); 102 } 103 104 /** 105 * Creates a new generator. 106 * 107 * @param prefix the prefix (<code>null</code> not permitted). 108 * @param categoryParameterName the category parameter name 109 * (<code>null</code> not permitted). 110 * @param indexParameterName the index parameter name (<code>null</code> 111 * permitted). 112 */ 113 public StandardPieURLGenerator(String prefix, 114 String categoryParameterName, 115 String indexParameterName) { 116 if (prefix == null) { 117 throw new IllegalArgumentException("Null 'prefix' argument."); 118 } 119 if (categoryParameterName == null) { 120 throw new IllegalArgumentException( 121 "Null 'categoryParameterName' argument."); 122 } 123 this.prefix = prefix; 124 this.categoryParameterName = categoryParameterName; 125 this.indexParameterName = indexParameterName; 126 } 127 128 /** 129 * Generates a URL. 130 * 131 * @param dataset the dataset (ignored). 132 * @param key the item key (<code>null</code> not permitted). 133 * @param pieIndex the pie index. 134 * 135 * @return A string containing the generated URL. 136 */ 137 public String generateURL(PieDataset dataset, Comparable key, int pieIndex) { 138 String url = this.prefix; 139 if (url.indexOf("?") > -1) { 140 url += "&" + this.categoryParameterName + "=" + key.toString(); 141 } 142 else { 143 url += "?" + this.categoryParameterName + "=" + key.toString(); 144 } 145 if (this.indexParameterName != null) { 146 url += "&" + this.indexParameterName + "=" 147 + String.valueOf(pieIndex); 148 } 149 return url; 150 } 151 152 /** 153 * Tests if this object is equal to another. 154 * 155 * @param obj the object (<code>null</code> permitted). 156 * 157 * @return A boolean. 158 */ 159 public boolean equals(Object obj) { 160 if (obj == this) { 161 return true; 162 } 163 if (!(obj instanceof StandardPieURLGenerator)) { 164 return false; 165 } 166 StandardPieURLGenerator that = (StandardPieURLGenerator) obj; 167 if (!this.prefix.equals(that.prefix)) { 168 return false; 169 } 170 if (!this.categoryParameterName.equals(that.categoryParameterName)) { 171 return false; 172 } 173 if (!ObjectUtilities.equal(this.indexParameterName, 174 that.indexParameterName)) { 175 return false; 176 } 177 return true; 178 } 179 }