001    /* ===========================================================
002     * JFreeChart : a free chart library for the Java(tm) platform
003     * ===========================================================
004     *
005     * (C) Copyright 2000-2005, 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     * PieLabelRecord.java
029     * -------------------
030     * (C) Copyright 2004, by Object Refinery Limited and Contributors.
031     *
032     * Original Author:  David Gilbert (for Object Refinery Limited);
033     * Contributor(s):   -;
034     *
035     * $Id: PieLabelRecord.java,v 1.2.2.1 2005/10/25 20:52:07 mungady Exp $
036     *
037     * Changes
038     * -------
039     * 08-Mar-2004 : Version 1 (DG);
040     *
041     */
042    
043    package org.jfree.chart.plot;
044    
045    import org.jfree.text.TextBox;
046    
047    /**
048     * A structure that retains information about the label for a section in a pie 
049     * chart.
050     */
051    public class PieLabelRecord implements Comparable {
052        
053        /** The key. */
054        private Comparable key;
055        
056        /** The angle. */
057        private double angle;
058        
059        /** The base y-coordinate. */
060        private double baseY;
061        
062        /** The allocated y-coordinate. */
063        private double allocatedY;
064    
065        /** The label. */
066        private TextBox label;
067        
068        /** The label height. */
069        private double labelHeight;
070        
071        /** The gap. */
072        private double gap;
073        
074        /** The link percent. */
075        private double linkPercent;
076        
077        /**
078         * Creates a new record.
079         * 
080         * @param key  the key.
081         * @param angle  the angle.
082         * @param baseY  the base y-coordinate.
083         * @param label  the label.
084         * @param labelHeight  the label height (in Java2D units).
085         * @param gap  the gap.
086         * @param linkPercent  the link percent.
087         */
088        public PieLabelRecord(Comparable key, double angle, double baseY, 
089                              TextBox label, double labelHeight, double gap, 
090                              double linkPercent) {
091            this.key = key;
092            this.angle = angle;
093            this.baseY = baseY;
094            this.allocatedY = baseY;
095            this.label = label;
096            this.labelHeight = labelHeight;
097            this.gap = gap;
098            this.linkPercent = linkPercent;
099        }
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 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 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 toString() {
236            return this.baseY + ", " + this.key.toString();   
237        }
238    }