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: * CustomXYItemLabelGenerator.java
029: * -------------------------------
030: * (C) Copyright 2002-2007, by Richard Atkinson and Contributors.
031: *
032: * Original Author: Richard Atkinson;
033: * Contributor(s): David Gilbert (for Object Refinery Limited);
034: *
035: * $Id: CustomXYToolTipGenerator.java,v 1.3.2.2 2007/02/02 15:52:42 mungady Exp $
036: *
037: * Changes:
038: * --------
039: * 05-Aug-2002 : Version 1, contributed by Richard Atkinson (RA);
040: * 26-Sep-2002 : Fixed errors reported by Checkstyle (DG);
041: * 21-Mar-2003 : Implemented Serializable (DG);
042: * 13-Aug-2003 : Implemented Cloneable (DG);
043: * 17-Nov-2003 : Implemented PublicCloneable (DG);
044: * 25-Feb-2004 : Renamed XYToolTipGenerator --> XYItemLabelGenerator (DG);
045: * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG);
046: *
047: */
048:
049: package org.jfree.chart.labels;
050:
051: import java.io.Serializable;
052: import java.util.List;
053:
054: import org.jfree.data.xy.XYDataset;
055: import org.jfree.util.PublicCloneable;
056:
057: /**
058: * A tool tip generator that stores custom tooltips. The dataset passed into
059: * the generateToolTip method is ignored.
060: */
061: public class CustomXYToolTipGenerator implements XYToolTipGenerator,
062: Cloneable, PublicCloneable, Serializable {
063:
064: /** For serialization. */
065: private static final long serialVersionUID = 8636030004670141362L;
066:
067: /** Storage for the tooltip lists. */
068: private List toolTipSeries = new java.util.ArrayList();
069:
070: /**
071: * Default constructor.
072: */
073: public CustomXYToolTipGenerator() {
074: super ();
075: }
076:
077: /**
078: * Returns the number of tool tip lists stored by the renderer.
079: *
080: * @return The list count.
081: */
082: public int getListCount() {
083: return this .toolTipSeries.size();
084: }
085:
086: /**
087: * Returns the number of tool tips in a given list.
088: *
089: * @param list the list index (zero based).
090: *
091: * @return The tooltip count.
092: */
093: public int getToolTipCount(int list) {
094:
095: int result = 0;
096: List tooltips = (List) this .toolTipSeries.get(list);
097: if (tooltips != null) {
098: result = tooltips.size();
099: }
100: return result;
101: }
102:
103: /**
104: * Returns the tool tip text for an item.
105: *
106: * @param series the series index.
107: * @param item the item index.
108: *
109: * @return The tool tip text.
110: */
111: public String getToolTipText(int series, int item) {
112:
113: String result = null;
114:
115: if (series < getListCount()) {
116: List tooltips = (List) this .toolTipSeries.get(series);
117: if (tooltips != null) {
118: if (item < tooltips.size()) {
119: result = (String) tooltips.get(item);
120: }
121: }
122: }
123:
124: return result;
125: }
126:
127: /**
128: * Adds a list of tooltips for a series.
129: *
130: * @param toolTips the list of tool tips.
131: */
132: public void addToolTipSeries(List toolTips) {
133: this .toolTipSeries.add(toolTips);
134: }
135:
136: /**
137: * Generates a tool tip text item for a particular item within a series.
138: *
139: * @param data the dataset (ignored in this implementation).
140: * @param series the series (zero-based index).
141: * @param item the item (zero-based index).
142: *
143: * @return The tooltip text.
144: */
145: public String generateToolTip(XYDataset data, int series, int item) {
146:
147: return getToolTipText(series, item);
148:
149: }
150:
151: /**
152: * Returns an independent copy of the generator.
153: *
154: * @return A clone.
155: *
156: * @throws CloneNotSupportedException if cloning is not supported.
157: */
158: public Object clone() throws CloneNotSupportedException {
159:
160: CustomXYToolTipGenerator clone = (CustomXYToolTipGenerator) super
161: .clone();
162: if (this .toolTipSeries != null) {
163: clone.toolTipSeries = new java.util.ArrayList(
164: this .toolTipSeries);
165: }
166: return clone;
167:
168: }
169:
170: /**
171: * Tests if this object is equal to another.
172: *
173: * @param obj the other object.
174: *
175: * @return A boolean.
176: */
177: public boolean equals(Object obj) {
178:
179: if (obj == this ) {
180: return true;
181: }
182:
183: if (obj instanceof CustomXYToolTipGenerator) {
184: CustomXYToolTipGenerator generator = (CustomXYToolTipGenerator) obj;
185: boolean result = true;
186: for (int series = 0; series < getListCount(); series++) {
187: for (int item = 0; item < getToolTipCount(series); item++) {
188: String t1 = getToolTipText(series, item);
189: String t2 = generator.getToolTipText(series, item);
190: if (t1 != null) {
191: result = result && t1.equals(t2);
192: } else {
193: result = result && (t2 == null);
194: }
195: }
196: }
197: return result;
198: }
199:
200: return false;
201:
202: }
203:
204: }
|