Source for org.jfree.chart.labels.ItemLabelPosition

   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:  * $Id: ItemLabelPosition.java,v 1.3.2.2 2007/01/10 12:25:21 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(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER, 
  78:                 TextAnchor.CENTER, 0.0);
  79:     }
  80:     
  81:     /**
  82:      * Creates a new position record (with zero rotation).
  83:      * 
  84:      * @param itemLabelAnchor  the item label anchor (<code>null</code> not 
  85:      *                         permitted).
  86:      * @param textAnchor  the text anchor (<code>null</code> not permitted).
  87:      */
  88:     public ItemLabelPosition(ItemLabelAnchor itemLabelAnchor, 
  89:                              TextAnchor textAnchor) {
  90:         this(itemLabelAnchor, textAnchor, TextAnchor.CENTER, 0.0);    
  91:     }
  92:     
  93:     /**
  94:      * Creates a new position record.  The item label anchor is a point 
  95:      * relative to the data item (dot, bar or other visual item) on a chart.  
  96:      * The item label is aligned by aligning the text anchor with the 
  97:      * item label anchor.
  98:      * 
  99:      * @param itemLabelAnchor  the item label anchor (<code>null</code> not 
 100:      *                         permitted).
 101:      * @param textAnchor  the text anchor (<code>null</code> not permitted).
 102:      * @param rotationAnchor  the rotation anchor (<code>null</code> not 
 103:      *                        permitted).
 104:      * @param angle  the rotation angle (in radians).
 105:      */
 106:     public ItemLabelPosition(ItemLabelAnchor itemLabelAnchor, 
 107:                              TextAnchor textAnchor,
 108:                              TextAnchor rotationAnchor,
 109:                              double angle) {
 110:               
 111:         if (itemLabelAnchor == null) {
 112:             throw new IllegalArgumentException(
 113:                     "Null 'itemLabelAnchor' argument.");
 114:         }
 115:         if (textAnchor == null) {
 116:             throw new IllegalArgumentException("Null 'textAnchor' argument.");
 117:         }
 118:         if (rotationAnchor == null) {
 119:             throw new IllegalArgumentException(
 120:                     "Null 'rotationAnchor' argument.");
 121:         }
 122:         
 123:         this.itemLabelAnchor = itemLabelAnchor;
 124:         this.textAnchor = textAnchor;
 125:         this.rotationAnchor = rotationAnchor;
 126:         this.angle = angle;
 127:     
 128:     }
 129:     
 130:     /**
 131:      * Returns the item label anchor.
 132:      * 
 133:      * @return The item label anchor (never <code>null</code>).
 134:      */
 135:     public ItemLabelAnchor getItemLabelAnchor() {
 136:         return this.itemLabelAnchor;
 137:     }
 138:     
 139:     /**
 140:      * Returns the text anchor.
 141:      * 
 142:      * @return The text anchor (never <code>null</code>).
 143:      */
 144:     public TextAnchor getTextAnchor() {
 145:         return this.textAnchor;
 146:     }
 147:     
 148:     /**
 149:      * Returns the rotation anchor point.
 150:      * 
 151:      * @return The rotation anchor point (never <code>null</code>).
 152:      */
 153:     public TextAnchor getRotationAnchor() {
 154:         return this.rotationAnchor;
 155:     }
 156:     
 157:     /**
 158:      * Returns the angle of rotation for the label.
 159:      * 
 160:      * @return The angle (in radians).
 161:      */
 162:     public double getAngle() {
 163:         return this.angle;
 164:     }
 165:     
 166:     /**
 167:      * Tests this object for equality with an arbitrary object.
 168:      * 
 169:      * @param obj  the object (<code>null</code> permitted).
 170:      * 
 171:      * @return A boolean.
 172:      */
 173:     public boolean equals(Object obj) {  
 174:         if (obj == this) {
 175:             return true;
 176:         }    
 177:         if (!(obj instanceof ItemLabelPosition)) {
 178:             return false;
 179:         }
 180:         ItemLabelPosition that = (ItemLabelPosition) obj;
 181:         if (!this.itemLabelAnchor.equals(that.itemLabelAnchor)) {
 182:             return false;
 183:         }
 184:         if (!this.textAnchor.equals(that.textAnchor)) {
 185:             return false;
 186:         }
 187:         if (!this.rotationAnchor.equals(that.rotationAnchor)) {
 188:             return false;
 189:         }
 190:         if (this.angle != that.angle) {
 191:             return false;
 192:         }     
 193:         return true;
 194:     }
 195: 
 196: }