Frames | No Frames |
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: * ItemLabelPosition.java 29: * ---------------------- 30: * (C) Copyright 2003-2005, by Object Refinery Limited and Contributors. 31: * 32: * Original Author: David Gilbert (for Object Refinery Limited); 33: * Contributor(s): -; 34: * 35: * $Id: ItemLabelPosition.java,v 1.3.2.1 2005/10/25 20:49:02 mungady Exp $ 36: * 37: * Changes 38: * ------- 39: * 27-Oct-2003 : Version 1 (DG); 40: * 19-Feb-2004 : Moved to org.jfree.chart.labels, updated Javadocs and argument 41: * checking (DG); 42: * 26-Feb-2004 : Added new constructor (DG); 43: * 44: */ 45: 46: package org.jfree.chart.labels; 47: 48: import java.io.Serializable; 49: 50: import org.jfree.ui.TextAnchor; 51: 52: /** 53: * The attributes that control the position of the label for each data item on 54: * a chart. Instances of this class are immutable. 55: */ 56: public class ItemLabelPosition implements Serializable { 57: 58: /** For serialization. */ 59: private static final long serialVersionUID = 5845390630157034499L; 60: 61: /** The item label anchor point. */ 62: private ItemLabelAnchor itemLabelAnchor; 63: 64: /** The text anchor. */ 65: private TextAnchor textAnchor; 66: 67: /** The rotation anchor. */ 68: private TextAnchor rotationAnchor; 69: 70: /** The rotation angle. */ 71: private double angle; 72: 73: /** 74: * Creates a new position record with default settings. 75: */ 76: public ItemLabelPosition() { 77: this( 78: ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER, 79: TextAnchor.CENTER, 0.0 80: ); 81: } 82: 83: /** 84: * Creates a new position record (with zero rotation). 85: * 86: * @param itemLabelAnchor the item label anchor (<code>null</code> not 87: * permitted). 88: * @param textAnchor the text anchor (<code>null</code> not permitted). 89: */ 90: public ItemLabelPosition(ItemLabelAnchor itemLabelAnchor, 91: TextAnchor textAnchor) { 92: this(itemLabelAnchor, textAnchor, TextAnchor.CENTER, 0.0); 93: } 94: 95: /** 96: * Creates a new position record. The item label anchor is a point 97: * relative to the data item (dot, bar or other visual item) on a chart. 98: * The item label is aligned by aligning the text anchor with the 99: * item label anchor. 100: * 101: * @param itemLabelAnchor the item label anchor (<code>null</code> not 102: * permitted). 103: * @param textAnchor the text anchor (<code>null</code> not permitted). 104: * @param rotationAnchor the rotation anchor (<code>null</code> not 105: * permitted). 106: * @param angle the rotation angle (in radians). 107: */ 108: public ItemLabelPosition(ItemLabelAnchor itemLabelAnchor, 109: TextAnchor textAnchor, 110: TextAnchor rotationAnchor, 111: double angle) { 112: 113: if (itemLabelAnchor == null) { 114: throw new IllegalArgumentException( 115: "Null 'itemLabelAnchor' argument." 116: ); 117: } 118: if (textAnchor == null) { 119: throw new IllegalArgumentException("Null 'textAnchor' argument."); 120: } 121: if (rotationAnchor == null) { 122: throw new IllegalArgumentException( 123: "Null 'rotationAnchor' argument." 124: ); 125: } 126: 127: this.itemLabelAnchor = itemLabelAnchor; 128: this.textAnchor = textAnchor; 129: this.rotationAnchor = rotationAnchor; 130: this.angle = angle; 131: 132: } 133: 134: /** 135: * Returns the item label anchor. 136: * 137: * @return The item label anchor (never <code>null</code>). 138: */ 139: public ItemLabelAnchor getItemLabelAnchor() { 140: return this.itemLabelAnchor; 141: } 142: 143: /** 144: * Returns the text anchor. 145: * 146: * @return The text anchor (never <code>null</code>). 147: */ 148: public TextAnchor getTextAnchor() { 149: return this.textAnchor; 150: } 151: 152: /** 153: * Returns the rotation anchor point. 154: * 155: * @return The rotation anchor point (never <code>null</code>). 156: */ 157: public TextAnchor getRotationAnchor() { 158: return this.rotationAnchor; 159: } 160: 161: /** 162: * Returns the angle of rotation for the label. 163: * 164: * @return The angle (in radians). 165: */ 166: public double getAngle() { 167: return this.angle; 168: } 169: 170: /** 171: * Tests this object for equality with an arbitrary object. 172: * 173: * @param obj the object (<code>null</code> permitted). 174: * 175: * @return A boolean. 176: */ 177: public boolean equals(Object obj) { 178: if (obj == this) { 179: return true; 180: } 181: if (!(obj instanceof ItemLabelPosition)) { 182: return false; 183: } 184: ItemLabelPosition that = (ItemLabelPosition) obj; 185: if (!this.itemLabelAnchor.equals(that.itemLabelAnchor)) { 186: return false; 187: } 188: if (!this.textAnchor.equals(that.textAnchor)) { 189: return false; 190: } 191: if (!this.rotationAnchor.equals(that.rotationAnchor)) { 192: return false; 193: } 194: if (this.angle != that.angle) { 195: return false; 196: } 197: return true; 198: } 199: 200: }