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: * AbstractXYAnnotation.java 29: * ------------------------- 30: * (C) Copyright 2004-2007, by Object Refinery Limited. 31: * 32: * Original Author: David Gilbert (for Object Refinery Limited); 33: * Contributor(s): -; 34: * 35: * $Id: AbstractXYAnnotation.java,v 1.3.2.3 2007/03/06 16:12:18 mungady Exp $ 36: * 37: * Changes: 38: * -------- 39: * 29-Sep-2004 : Version 1 (DG); 40: * ------------- JFREECHART 1.0.x --------------------------------------------- 41: * 06-Mar-2007 : Implemented hashCode() (DG); 42: * 43: */ 44: 45: package org.jfree.chart.annotations; 46: 47: import java.awt.Graphics2D; 48: import java.awt.Shape; 49: import java.awt.geom.Rectangle2D; 50: 51: import org.jfree.chart.axis.ValueAxis; 52: import org.jfree.chart.entity.EntityCollection; 53: import org.jfree.chart.entity.XYAnnotationEntity; 54: import org.jfree.chart.plot.PlotRenderingInfo; 55: import org.jfree.chart.plot.XYPlot; 56: import org.jfree.util.ObjectUtilities; 57: 58: /** 59: * The interface that must be supported by annotations that are to be added to 60: * an {@link XYPlot}. 61: */ 62: public abstract class AbstractXYAnnotation implements XYAnnotation { 63: 64: /** The tool tip text. */ 65: private String toolTipText; 66: 67: /** The URL. */ 68: private String url; 69: 70: /** 71: * Creates a new instance that has no tool tip or URL specified. 72: */ 73: protected AbstractXYAnnotation() { 74: this.toolTipText = null; 75: this.url = null; 76: } 77: 78: /** 79: * Returns the tool tip text for the annotation. This will be displayed in 80: * a {@link org.jfree.chart.ChartPanel} when the mouse pointer hovers over 81: * the annotation. 82: * 83: * @return The tool tip text (possibly <code>null</code>). 84: * 85: * @see #setToolTipText(String) 86: */ 87: public String getToolTipText() { 88: return this.toolTipText; 89: } 90: 91: /** 92: * Sets the tool tip text for the annotation. 93: * 94: * @param text the tool tip text (<code>null</code> permitted). 95: * 96: * @see #getToolTipText() 97: */ 98: public void setToolTipText(String text) { 99: this.toolTipText = text; 100: } 101: 102: /** 103: * Returns the URL for the annotation. This URL will be used to provide 104: * hyperlinks when an HTML image map is created for the chart. 105: * 106: * @return The URL (possibly <code>null</code>). 107: * 108: * @see #setURL(String) 109: */ 110: public String getURL() { 111: return this.url; 112: } 113: 114: /** 115: * Sets the URL for the annotation. 116: * 117: * @param url the URL (<code>null</code> permitted). 118: * 119: * @see #getURL() 120: */ 121: public void setURL(String url) { 122: this.url = url; 123: } 124: 125: /** 126: * Draws the annotation. 127: * 128: * @param g2 the graphics device. 129: * @param plot the plot. 130: * @param dataArea the data area. 131: * @param domainAxis the domain axis. 132: * @param rangeAxis the range axis. 133: * @param rendererIndex the renderer index. 134: * @param info if supplied, this info object will be populated with 135: * entity information. 136: */ 137: public abstract void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, 138: ValueAxis domainAxis, ValueAxis rangeAxis, 139: int rendererIndex, 140: PlotRenderingInfo info); 141: 142: /** 143: * A utility method for adding an {@link XYAnnotationEntity} to 144: * a {@link PlotRenderingInfo} instance. 145: * 146: * @param info the plot rendering info (<code>null</code> permitted). 147: * @param hotspot the hotspot area. 148: * @param rendererIndex the renderer index. 149: * @param toolTipText the tool tip text. 150: * @param urlText the URL text. 151: */ 152: protected void addEntity(PlotRenderingInfo info, 153: Shape hotspot, int rendererIndex, 154: String toolTipText, String urlText) { 155: if (info == null) { 156: return; 157: } 158: EntityCollection entities = info.getOwner().getEntityCollection(); 159: if (entities == null) { 160: return; 161: } 162: XYAnnotationEntity entity = new XYAnnotationEntity(hotspot, 163: rendererIndex, toolTipText, urlText); 164: entities.add(entity); 165: } 166: 167: /** 168: * Tests this annotation for equality with an arbitrary object. 169: * 170: * @param obj the object (<code>null</code> permitted). 171: * 172: * @return A boolean. 173: */ 174: public boolean equals(Object obj) { 175: if (obj == this) { 176: return true; 177: } 178: if (!(obj instanceof AbstractXYAnnotation)) { 179: return false; 180: } 181: AbstractXYAnnotation that = (AbstractXYAnnotation) obj; 182: if (!ObjectUtilities.equal(this.toolTipText, that.toolTipText)) { 183: return false; 184: } 185: if (!ObjectUtilities.equal(this.url, that.url)) { 186: return false; 187: } 188: return true; 189: } 190: 191: /** 192: * Returns a hash code for this instance. 193: * 194: * @return A hash code. 195: */ 196: public int hashCode() { 197: int result = 193; 198: if (this.toolTipText != null) { 199: result = 37 * result + this.toolTipText.hashCode(); 200: } 201: if (this.url != null) { 202: result = 37 * result + this.url.hashCode(); 203: } 204: return result; 205: } 206: 207: }