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