001    /* ===========================================================
002     * JFreeChart : a free chart library for the Java(tm) platform
003     * ===========================================================
004     *
005     * (C) Copyright 2000-2007, 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     * ItemLabelPosition.java
029     * ----------------------
030     * (C) Copyright 2003-2007, by Object Refinery Limited and Contributors.
031     *
032     * Original Author:  David Gilbert (for Object Refinery Limited);
033     * Contributor(s):   -;
034     *
035     * $Id: ItemLabelPosition.java,v 1.3.2.2 2007/01/10 12:25:21 mungady Exp $
036     *
037     * Changes
038     * -------
039     * 27-Oct-2003 : Version 1 (DG);
040     * 19-Feb-2004 : Moved to org.jfree.chart.labels, updated Javadocs and argument 
041     *               checking (DG);
042     * 26-Feb-2004 : Added new constructor (DG);
043     *
044     */
045    
046    package org.jfree.chart.labels;
047    
048    import java.io.Serializable;
049    
050    import org.jfree.ui.TextAnchor;
051    
052    /**
053     * The attributes that control the position of the label for each data item on 
054     * a chart.  Instances of this class are immutable.
055     */
056    public class ItemLabelPosition implements Serializable {
057    
058        /** For serialization. */
059        private static final long serialVersionUID = 5845390630157034499L;
060        
061        /** The item label anchor point. */
062        private ItemLabelAnchor itemLabelAnchor;
063        
064        /** The text anchor. */
065        private TextAnchor textAnchor;
066        
067        /** The rotation anchor. */
068        private TextAnchor rotationAnchor;
069    
070        /** The rotation angle. */    
071        private double angle;
072        
073        /**
074         * Creates a new position record with default settings.
075         */
076        public ItemLabelPosition() {
077            this(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER, 
078                    TextAnchor.CENTER, 0.0);
079        }
080        
081        /**
082         * Creates a new position record (with zero rotation).
083         * 
084         * @param itemLabelAnchor  the item label anchor (<code>null</code> not 
085         *                         permitted).
086         * @param textAnchor  the text anchor (<code>null</code> not permitted).
087         */
088        public ItemLabelPosition(ItemLabelAnchor itemLabelAnchor, 
089                                 TextAnchor textAnchor) {
090            this(itemLabelAnchor, textAnchor, TextAnchor.CENTER, 0.0);    
091        }
092        
093        /**
094         * Creates a new position record.  The item label anchor is a point 
095         * relative to the data item (dot, bar or other visual item) on a chart.  
096         * The item label is aligned by aligning the text anchor with the 
097         * item label anchor.
098         * 
099         * @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    }