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: * PieLabelRecord.java 29: * ------------------- 30: * (C) Copyright 2004, 2007, by Object Refinery Limited and Contributors. 31: * 32: * Original Author: David Gilbert (for Object Refinery Limited); 33: * Contributor(s): -; 34: * 35: * Changes 36: * ------- 37: * 08-Mar-2004 : Version 1 (DG); 38: * 14-Jun-2007 : Implemented Serializable, updated API docs (DG); 39: * 40: */ 41: 42: package org.jfree.chart.plot; 43: 44: import java.io.Serializable; 45: 46: import org.jfree.text.TextBox; 47: 48: /** 49: * A structure that retains information about the label for a section in a pie 50: * chart. 51: */ 52: public class PieLabelRecord implements Comparable, Serializable { 53: 54: /** The section key. */ 55: private Comparable key; 56: 57: /** The angle of the centre of the section (in radians). */ 58: private double angle; 59: 60: /** The base y-coordinate. */ 61: private double baseY; 62: 63: /** The allocated y-coordinate. */ 64: private double allocatedY; 65: 66: /** The label. */ 67: private TextBox label; 68: 69: /** The label height. */ 70: private double labelHeight; 71: 72: /** The gap. */ 73: private double gap; 74: 75: /** The link percent. */ 76: private double linkPercent; 77: 78: /** 79: * Creates a new record. 80: * 81: * @param key the section key. 82: * @param angle the angle to the middle of the section (in radians). 83: * @param baseY the base y-coordinate. 84: * @param label the section label. 85: * @param labelHeight the label height (in Java2D units). 86: * @param gap the offset to the left. 87: * @param linkPercent the link percent. 88: */ 89: public PieLabelRecord(Comparable key, double angle, double baseY, 90: TextBox label, double labelHeight, double gap, 91: double linkPercent) { 92: this.key = key; 93: this.angle = angle; 94: this.baseY = baseY; 95: this.allocatedY = baseY; 96: this.label = label; 97: this.labelHeight = labelHeight; 98: this.gap = gap; 99: this.linkPercent = linkPercent; 100: } 101: 102: /** 103: * Returns the base y-coordinate. This is where the label will appear if 104: * there is no overlapping of labels. 105: * 106: * @return The base y-coordinate. 107: */ 108: public double getBaseY() { 109: return this.baseY; 110: } 111: 112: /** 113: * Sets the base y-coordinate. 114: * 115: * @param base the base y-coordinate. 116: */ 117: public void setBaseY(double base) { 118: this.baseY = base; 119: } 120: 121: /** 122: * Returns the lower bound of the label. 123: * 124: * @return The lower bound. 125: */ 126: public double getLowerY() { 127: return this.allocatedY - this.labelHeight / 2.0; 128: } 129: 130: /** 131: * Returns the upper bound of the label. 132: * 133: * @return The upper bound. 134: */ 135: public double getUpperY() { 136: return this.allocatedY + this.labelHeight / 2.0; 137: } 138: 139: /** 140: * Returns the angle of the middle of the section, in radians. 141: * 142: * @return The angle, in radians. 143: */ 144: public double getAngle() { 145: return this.angle; 146: } 147: 148: /** 149: * Returns the key for the section that the label applies to. 150: * 151: * @return The key. 152: */ 153: public Comparable getKey() { 154: return this.key; 155: } 156: 157: /** 158: * Returns the label. 159: * 160: * @return The label. 161: */ 162: public TextBox getLabel() { 163: return this.label; 164: } 165: 166: /** 167: * Returns the label height (you could derive this from the label itself, 168: * but we cache the value so it can be retrieved quickly). 169: * 170: * @return The label height (in Java2D units). 171: */ 172: public double getLabelHeight() { 173: return this.labelHeight; 174: } 175: 176: /** 177: * Returns the allocated y-coordinate. 178: * 179: * @return The allocated y-coordinate. 180: */ 181: public double getAllocatedY() { 182: return this.allocatedY; 183: } 184: 185: /** 186: * Sets the allocated y-coordinate. 187: * 188: * @param y the y-coordinate. 189: */ 190: public void setAllocatedY(double y) { 191: this.allocatedY = y; 192: } 193: 194: /** 195: * Returns the gap. 196: * 197: * @return The gap. 198: */ 199: public double getGap() { 200: return this.gap; 201: } 202: 203: /** 204: * Returns the link percent. 205: * 206: * @return The link percent. 207: */ 208: public double getLinkPercent() { 209: return this.linkPercent; 210: } 211: 212: /** 213: * Compares this object to an arbitrary object. 214: * 215: * @param obj the object to compare against. 216: * 217: * @return An integer that specifies the relative order of the two objects. 218: */ 219: public int compareTo(Object obj) { 220: int result = 0; 221: if (obj instanceof PieLabelRecord) { 222: PieLabelRecord plr = (PieLabelRecord) obj; 223: if (this.baseY < plr.baseY) { 224: result = -1; 225: } 226: else if (this.baseY > plr.baseY) { 227: result = 1; 228: } 229: } 230: return result; 231: } 232: 233: /** 234: * Returns a string describing the object. This is used for debugging only. 235: * 236: * @return A string. 237: */ 238: public String toString() { 239: return this.baseY + ", " + this.key.toString(); 240: } 241: }