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.3 2005/03/09 13:45:32 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. package org.jfree.chart.urls;
  49. import java.io.Serializable;
  50. import org.jfree.data.general.PieDataset;
  51. /**
  52. * A URL generator for pie charts.
  53. *
  54. * @author Richard Atkinson
  55. */
  56. public class StandardPieURLGenerator implements PieURLGenerator, Serializable {
  57. /** The prefix. */
  58. private String prefix = "index.html";
  59. /** The category parameter name. */
  60. private String categoryParameterName = "category";
  61. /** The pie index parameter name. */
  62. private String indexParameterName = "pieIndex";
  63. /**
  64. * Default constructor.
  65. */
  66. public StandardPieURLGenerator() {
  67. super();
  68. }
  69. /**
  70. * Creates a new generator.
  71. *
  72. * @param prefix the prefix.
  73. */
  74. public StandardPieURLGenerator(String prefix) {
  75. this.prefix = prefix;
  76. }
  77. /**
  78. * Creates a new generator.
  79. *
  80. * @param prefix the prefix.
  81. * @param categoryParameterName the category parameter name.
  82. */
  83. public StandardPieURLGenerator(String prefix,
  84. String categoryParameterName) {
  85. this.prefix = prefix;
  86. this.categoryParameterName = categoryParameterName;
  87. }
  88. /**
  89. * Creates a new generator.
  90. *
  91. * @param prefix the prefix.
  92. * @param categoryParameterName the category parameter name.
  93. * @param indexParameterName the index parameter name
  94. * (<code>null</code> permitted).
  95. */
  96. public StandardPieURLGenerator(String prefix,
  97. String categoryParameterName,
  98. String indexParameterName) {
  99. this.prefix = prefix;
  100. this.categoryParameterName = categoryParameterName;
  101. this.indexParameterName = indexParameterName;
  102. }
  103. /**
  104. * Generates a URL.
  105. *
  106. * @param data the dataset.
  107. * @param key the item key.
  108. * @param pieIndex the pie index (ignored).
  109. *
  110. * @return A string containing the generated URL.
  111. */
  112. public String generateURL(PieDataset data, Comparable key, int pieIndex) {
  113. String url = this.prefix;
  114. if (url.indexOf("?") > -1) {
  115. url += "&" + this.categoryParameterName + "=" + key.toString();
  116. }
  117. else {
  118. url += "?" + this.categoryParameterName + "=" + key.toString();
  119. }
  120. if (this.indexParameterName != null) {
  121. url += "&" + this.indexParameterName + "="
  122. + String.valueOf(pieIndex);
  123. }
  124. return url;
  125. }
  126. /**
  127. * Tests if this object is equal to another.
  128. *
  129. * @param obj the object (<code>null</code> permitted).
  130. *
  131. * @return A boolean.
  132. */
  133. public boolean equals(Object obj) {
  134. if (obj == null) {
  135. return false;
  136. }
  137. if (obj == this) {
  138. return true;
  139. }
  140. if ((obj instanceof StandardPieURLGenerator) == false) {
  141. return false;
  142. }
  143. StandardPieURLGenerator generator = (StandardPieURLGenerator) obj;
  144. return (
  145. this.categoryParameterName.equals(generator.categoryParameterName))
  146. && (this.prefix.equals(generator.prefix)
  147. );
  148. }
  149. }