KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > DrawableLegendItem


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  * DrawableLegendItem.java
28  * -----------------------
29  * (C) Copyright 2002-2005, by Object Refinery Limited and Contributors.
30  *
31  * Original Author: David Gilbert (for Object Refinery Limited);
32  * Contributor(s): Luke Quinane;
33  * Barak Naveh;
34  *
35  * $Id: DrawableLegendItem.java,v 1.3 2005/03/28 19:38:39 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 07-Feb-2002 : Version 1 (DG);
40  * 23-Sep-2002 : Renamed LegendItem --> DrawableLegendItem (DG);
41  * 02-Oct-2002 : Fixed errors reported by Checkstyle (DG);
42  * 08-Oct-2003 : Applied patch for displaying series line style, contributed by
43  * Luke Quinane (DG);
44  * 27-Mar-2004 : Added getMaxX() and getMaxY() methods (BN);
45  * 27-Jan-2005 : Cleared out code that belongs in the LegendItem class (DG);
46  *
47  */

48
49 package org.jfree.chart;
50
51 import java.awt.Shape JavaDoc;
52 import java.awt.geom.Line2D JavaDoc;
53 import java.awt.geom.Point2D JavaDoc;
54
55 /**
56  * This class contains a single legend item along with position details for
57  * drawing the item on a particular chart.
58  */

59 public class DrawableLegendItem {
60
61     /**
62      * The legend item (encapsulates information about the label, color and
63      * shape).
64      */

65     private LegendItem item;
66
67     /** The x-coordinate for the item's location. */
68     private double x;
69
70     /** The y-coordinate for the item's location. */
71     private double y;
72
73     /** The width of the item. */
74     private double width;
75
76     /** The height of the item. */
77     private double height;
78
79     /** A shape used to indicate color on the legend. */
80     private Shape JavaDoc marker;
81     
82     /** A line used to indicate the series stroke on the legend */
83     private Line2D JavaDoc line;
84
85     /** The label position within the item. */
86     private Point2D JavaDoc labelPosition;
87
88     /**
89      * Create a legend item.
90      *
91      * @param item the legend item for display.
92      */

93     public DrawableLegendItem(LegendItem item) {
94         this.item = item;
95     }
96
97     /**
98      * Returns the legend item.
99      *
100      * @return The legend item.
101      */

102     public LegendItem getItem() {
103         return this.item;
104     }
105
106     /**
107      * Get the x-coordinate for the item's location.
108      *
109      * @return The x-coordinate for the item's location.
110      */

111     public double getX() {
112         return this.x;
113     }
114
115     /**
116      * Set the x-coordinate for the item's location.
117      *
118      * @param x the x-coordinate.
119      */

120     public void setX(double x) {
121         this.x = x;
122     }
123
124     /**
125      * Get the y-coordinate for the item's location.
126      *
127      * @return The y-coordinate for the item's location.
128      */

129     public double getY() {
130         return this.y;
131     }
132
133     /**
134      * Set the y-coordinate for the item's location.
135      *
136      * @param y the y-coordinate.
137      */

138     public void setY(double y) {
139         this.y = y;
140     }
141
142     /**
143      * Get the width of this item.
144      *
145      * @return The width.
146      */

147     public double getWidth() {
148         return this.width;
149     }
150
151     /**
152      * Get the height of this item.
153      *
154      * @return The height.
155      */

156     public double getHeight() {
157         return this.height;
158     }
159
160     /**
161      * Returns the largest X coordinate of the framing rectangle of this legend
162      * item.
163      *
164      * @return The largest x coordinate of the framing rectangle of this legend
165      * item.
166      */

167     public double getMaxX() {
168         return getX() + getWidth();
169     }
170
171     /**
172      * Returns the largest Y coordinate of the framing rectangle of this legend
173      * item.
174      *
175      * @return The largest Y coordinate of the framing rectangle of this legend
176      * item.
177      */

178     public double getMaxY() {
179         return getY() + getHeight();
180     }
181     
182     /**
183      * Get the marker.
184      *
185      * @return The shape used to indicate color on the legend for this item.
186      */

187     public Shape JavaDoc getMarker() {
188         return this.marker;
189     }
190
191     /**
192      * Set the marker.
193      *
194      * @param marker a shape used to indicate color on the legend for this
195      * item.
196      */

197     public void setMarker(Shape JavaDoc marker) {
198         this.marker = marker;
199     }
200     
201     /**
202      * Sets the line used to label this series.
203      *
204      * @param l the new line to use.
205      */

206     public void setLine(Line2D JavaDoc l) {
207         this.line = l;
208     }
209
210     /**
211      * Returns the list.
212      *
213      * @return The line.
214      */

215     public Line2D JavaDoc getLine() {
216         return this.line;
217     }
218
219     /**
220      * Returns the label position.
221      *
222      * @return The label position.
223      */

224     public Point2D JavaDoc getLabelPosition() {
225         return this.labelPosition;
226     }
227
228     /**
229      * Sets the label position.
230      *
231      * @param position the label position.
232      */

233     public void setLabelPosition(Point2D JavaDoc position) {
234         this.labelPosition = position;
235     }
236
237     /**
238      * Set the bounds of this item.
239      *
240      * @param x x-coordinate for the item's location.
241      * @param y y-coordinate for the item's location.
242      * @param width the width of this item.
243      * @param height the height of this item.
244      */

245     public void setBounds(double x, double y, double width, double height) {
246         this.x = x;
247         this.y = y;
248         this.width = width;
249         this.height = height;
250     }
251
252 }
253
Popular Tags