KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > annotations > AbstractXYAnnotation


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
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, 2005, 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.1 2005/10/25 16:51:14 mungady Exp $
36  *
37  * Changes:
38  * --------
39  * 29-Sep-2004 : Version 1 (DG);
40  *
41  */

42
43 package org.jfree.chart.annotations;
44
45 import java.awt.Graphics2D JavaDoc;
46 import java.awt.Shape JavaDoc;
47 import java.awt.geom.Rectangle2D JavaDoc;
48
49 import org.jfree.chart.axis.ValueAxis;
50 import org.jfree.chart.entity.EntityCollection;
51 import org.jfree.chart.entity.XYAnnotationEntity;
52 import org.jfree.chart.plot.PlotRenderingInfo;
53 import org.jfree.chart.plot.XYPlot;
54 import org.jfree.util.ObjectUtilities;
55
56 /**
57  * The interface that must be supported by annotations that are to be added to
58  * an {@link XYPlot}.
59  */

60 public abstract class AbstractXYAnnotation implements XYAnnotation {
61
62     /** The tool tip text. */
63     private String JavaDoc toolTipText;
64     
65     /** The URL. */
66     private String JavaDoc url;
67     
68     /**
69      * Creates a new instance that has no tool tip or URL specified.
70      */

71     protected AbstractXYAnnotation() {
72         this.toolTipText = null;
73         this.url = null;
74     }
75     
76     /**
77      * Returns the tool tip text for the annotation. This will be displayed in
78      * a {@link org.jfree.chart.ChartPanel} when the mouse pointer hovers over
79      * the annotation.
80      *
81      * @return The tool tip text (possibly <code>null</code>).
82      */

83     public String JavaDoc getToolTipText() {
84         return this.toolTipText;
85     }
86     
87     /**
88      * Sets the tool tip text for the annotation.
89      *
90      * @param text the tool tip text (<code>null</code> permitted).
91      */

92     public void setToolTipText(String JavaDoc text) {
93         this.toolTipText = text;
94     }
95     
96     /**
97      * Returns the URL for the annotation. This URL will be used to provide
98      * hyperlinks when an HTML image map is created for the chart.
99      *
100      * @return The URL (possibly <code>null</code>).
101      */

102     public String JavaDoc getURL() {
103         return this.url;
104     }
105     
106     /**
107      * Sets the URL for the annotation.
108      *
109      * @param url the URL (<code>null</code> permitted).
110      */

111     public void setURL(String JavaDoc url) {
112         this.url = url;
113     }
114     
115     /**
116      * Draws the annotation.
117      *
118      * @param g2 the graphics device.
119      * @param plot the plot.
120      * @param dataArea the data area.
121      * @param domainAxis the domain axis.
122      * @param rangeAxis the range axis.
123      * @param rendererIndex the renderer index.
124      * @param info if supplied, this info object will be populated with
125      * entity information.
126      */

127     public abstract void draw(Graphics2D JavaDoc g2, XYPlot plot, Rectangle2D JavaDoc dataArea,
128                               ValueAxis domainAxis, ValueAxis rangeAxis,
129                               int rendererIndex,
130                               PlotRenderingInfo info);
131
132     /**
133      * A utility method for adding an {@link XYAnnotationEntity} to
134      * a {@link PlotRenderingInfo} instance.
135      *
136      * @param info the plot rendering info (<code>null</code> permitted).
137      * @param hotspot the hotspot area.
138      * @param rendererIndex the renderer index.
139      * @param toolTipText the tool tip text.
140      * @param urlText the URL text.
141      */

142     protected void addEntity(PlotRenderingInfo info,
143                              Shape JavaDoc hotspot, int rendererIndex,
144                              String JavaDoc toolTipText, String JavaDoc urlText) {
145         if (info == null) {
146             return;
147         }
148         EntityCollection entities = info.getOwner().getEntityCollection();
149         if (entities == null) {
150             return;
151         }
152         XYAnnotationEntity entity = new XYAnnotationEntity(
153             hotspot, rendererIndex, toolTipText, urlText
154         );
155         entities.add(entity);
156     }
157
158     /**
159      * Tests this annotation for equality with an arbitrary object.
160      *
161      * @param obj the object (<code>null</code> permitted).
162      *
163      * @return A boolean.
164      */

165     public boolean equals(Object JavaDoc obj) {
166         if (obj == this) {
167             return true;
168         }
169         if (!(obj instanceof AbstractXYAnnotation)) {
170             return false;
171         }
172         AbstractXYAnnotation that = (AbstractXYAnnotation) obj;
173         if (!ObjectUtilities.equal(this.toolTipText, that.toolTipText)) {
174             return false;
175         }
176         if (!ObjectUtilities.equal(this.url, that.url)) {
177             return false;
178         }
179         return true;
180     }
181     
182 }
183
Popular Tags