KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > plot > PieLabelRecord


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  * PieLabelRecord.java
29  * -------------------
30  * (C) Copyright 2004, by Object Refinery Limited and Contributors.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: PieLabelRecord.java,v 1.2.2.1 2005/10/25 20:52:07 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 08-Mar-2004 : Version 1 (DG);
40  *
41  */

42
43 package org.jfree.chart.plot;
44
45 import org.jfree.text.TextBox;
46
47 /**
48  * A structure that retains information about the label for a section in a pie
49  * chart.
50  */

51 public class PieLabelRecord implements Comparable JavaDoc {
52     
53     /** The key. */
54     private Comparable JavaDoc key;
55     
56     /** The angle. */
57     private double angle;
58     
59     /** The base y-coordinate. */
60     private double baseY;
61     
62     /** The allocated y-coordinate. */
63     private double allocatedY;
64
65     /** The label. */
66     private TextBox label;
67     
68     /** The label height. */
69     private double labelHeight;
70     
71     /** The gap. */
72     private double gap;
73     
74     /** The link percent. */
75     private double linkPercent;
76     
77     /**
78      * Creates a new record.
79      *
80      * @param key the key.
81      * @param angle the angle.
82      * @param baseY the base y-coordinate.
83      * @param label the label.
84      * @param labelHeight the label height (in Java2D units).
85      * @param gap the gap.
86      * @param linkPercent the link percent.
87      */

88     public PieLabelRecord(Comparable JavaDoc key, double angle, double baseY,
89                           TextBox label, double labelHeight, double gap,
90                           double linkPercent) {
91         this.key = key;
92         this.angle = angle;
93         this.baseY = baseY;
94         this.allocatedY = baseY;
95         this.label = label;
96         this.labelHeight = labelHeight;
97         this.gap = gap;
98         this.linkPercent = linkPercent;
99     }
100     
101     /**
102      * Returns the base y-coordinate. This is where the label will appear if
103      * there is no overlapping of labels.
104      *
105      * @return The base y-coordinate.
106      */

107     public double getBaseY() {
108         return this.baseY;
109     }
110     
111     /**
112      * Sets the base y-coordinate.
113      *
114      * @param base the base y-coordinate.
115      */

116     public void setBaseY(double base) {
117         this.baseY = base;
118     }
119     
120     /**
121      * Returns the lower bound of the label.
122      *
123      * @return The lower bound.
124      */

125     public double getLowerY() {
126         return this.allocatedY - this.labelHeight / 2.0;
127     }
128     
129     /**
130      * Returns the upper bound of the label.
131      *
132      * @return The upper bound.
133      */

134     public double getUpperY() {
135         return this.allocatedY + this.labelHeight / 2.0;
136     }
137     
138     /**
139      * Returns the angle.
140      *
141      * @return The angle.
142      */

143     public double getAngle() {
144         return this.angle;
145     }
146     
147     /**
148      * Returns the key for the section that the label applies to.
149      *
150      * @return The key.
151      */

152     public Comparable JavaDoc getKey() {
153         return this.key;
154     }
155     
156     /**
157      * Returns the label.
158      *
159      * @return The label.
160      */

161     public TextBox getLabel() {
162         return this.label;
163     }
164     
165     /**
166      * Returns the label height.
167      *
168      * @return The label height (in Java2D units).
169      */

170     public double getLabelHeight() {
171         return this.labelHeight;
172     }
173     
174     /**
175      * Returns the allocated y-coordinate.
176      *
177      * @return The allocated y-coordinate.
178      */

179     public double getAllocatedY() {
180         return this.allocatedY;
181     }
182     
183     /**
184      * Sets the allocated y-coordinate.
185      *
186      * @param y the y-coordinate.
187      */

188     public void setAllocatedY(double y) {
189         this.allocatedY = y;
190     }
191     
192     /**
193      * Returns the gap.
194      *
195      * @return The gap.
196      */

197     public double getGap() {
198         return this.gap;
199     }
200     
201     /**
202      * Returns the link percent.
203      *
204      * @return The link percent.
205      */

206     public double getLinkPercent() {
207         return this.linkPercent;
208     }
209     /**
210      * Compares this object to an arbitrary object.
211      *
212      * @param obj the object to compare against.
213      *
214      * @return An integer that specifies the relative order of the two objects.
215      */

216     public int compareTo(Object JavaDoc obj) {
217         int result = 0;
218         if (obj instanceof PieLabelRecord) {
219             PieLabelRecord plr = (PieLabelRecord) obj;
220             if (this.baseY < plr.baseY) {
221                 result = -1;
222             }
223             else if (this.baseY > plr.baseY) {
224                 result = 1;
225             }
226         }
227         return result;
228     }
229     
230     /**
231      * Returns a string describing the object. This is used for debugging only.
232      *
233      * @return A string.
234      */

235     public String JavaDoc toString() {
236         return this.baseY + ", " + this.key.toString();
237     }
238 }
239
Popular Tags