KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > axis > CategoryLabelPosition


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 License
20  * along with this library; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
24  * in the United States and other countries.]
25  *
26  * --------------------------
27  * CategoryLabelPosition.java
28  * --------------------------
29  * (C) Copyright 2003-2005, by Object Refinery Limited and Contributors.
30  *
31  * Original Author: David Gilbert (for Object Refinery Limited);
32  * Contributor(s): -;
33  *
34  * $Id: CategoryLabelPosition.java,v 1.7 2005/05/19 13:58:11 mungady Exp $
35  *
36  * Changes
37  * -------
38  * 31-Oct-2003 : Version 1 (DG);
39  * 17-Feb-2004 : Added new constructor (DG);
40  * 23-Mar-2004 : Added width calculation parameters (DG);
41  * 07-Jan-2005 : Fixed bug in equals() method (DG);
42  * 11-Jan-2005 : Removed deprecated constructor in preparation for the 1.0.0
43  * release (DG);
44  *
45  */

46
47 package org.jfree.chart.axis;
48
49 import java.io.Serializable JavaDoc;
50
51 import org.jfree.text.TextBlockAnchor;
52 import org.jfree.ui.RectangleAnchor;
53 import org.jfree.ui.TextAnchor;
54
55 /**
56  * The attributes that control the position of the labels for the categories on
57  * a {@link CategoryAxis}. Instances of this class are immutable and other
58  * JFreeChart classes rely upon this.
59  */

60 public class CategoryLabelPosition implements Serializable JavaDoc {
61
62     /** For serialization. */
63     private static final long serialVersionUID = 5168681143844183864L;
64     
65     /** The category anchor point. */
66     private RectangleAnchor categoryAnchor;
67     
68     /** The text block anchor. */
69     private TextBlockAnchor labelAnchor;
70     
71     /** The rotation anchor. */
72     private TextAnchor rotationAnchor;
73
74     /** The rotation angle (in radians). */
75     private double angle;
76     
77     /** The width calculation type. */
78     private CategoryLabelWidthType widthType;
79     
80     /**
81      * The maximum label width as a percentage of the category space or the
82      * range space.
83      */

84     private float widthRatio;
85     
86     /**
87      * Creates a new position record with default settings.
88      */

89     public CategoryLabelPosition() {
90         this(
91             RectangleAnchor.CENTER, TextBlockAnchor.BOTTOM_CENTER,
92             TextAnchor.CENTER, 0.0, CategoryLabelWidthType.CATEGORY, 0.95f
93         );
94     }
95     
96     /**
97      * Creates a new category label position record.
98      *
99      * @param categoryAnchor the category anchor (<code>null</code> not
100      * permitted).
101      * @param labelAnchor the label anchor (<code>null</code> not permitted).
102      */

103     public CategoryLabelPosition(RectangleAnchor categoryAnchor,
104                                  TextBlockAnchor labelAnchor) {
105         // argument checking delegated...
106
this(
107             categoryAnchor, labelAnchor, TextAnchor.CENTER, 0.0,
108             CategoryLabelWidthType.CATEGORY, 0.95f
109         );
110     }
111     
112     /**
113      * Creates a new category label position record.
114      *
115      * @param categoryAnchor the category anchor (<code>null</code> not
116      * permitted).
117      * @param labelAnchor the label anchor (<code>null</code> not permitted).
118      * @param widthType the width type (<code>null</code> not permitted).
119      * @param widthRatio the maximum label width as a percentage (of the
120      * category space or the range space).
121      */

122     public CategoryLabelPosition(RectangleAnchor categoryAnchor,
123                                  TextBlockAnchor labelAnchor,
124                                  CategoryLabelWidthType widthType,
125                                  float widthRatio) {
126         // argument checking delegated...
127
this(
128             categoryAnchor, labelAnchor, TextAnchor.CENTER,
129             0.0, widthType, widthRatio
130         );
131     }
132     
133     /**
134      * Creates a new position record. The item label anchor is a point
135      * relative to the data item (dot, bar or other visual item) on a chart.
136      * The item label is aligned by aligning the text anchor with the item
137      * label anchor.
138      *
139      * @param categoryAnchor the category anchor (<code>null</code> not
140      * permitted).
141      * @param labelAnchor the label anchor (<code>null</code> not permitted).
142      * @param rotationAnchor the rotation anchor (<code>null</code> not
143      * permitted).
144      * @param angle the rotation angle (<code>null</code> not permitted).
145      * @param widthType the width type (<code>null</code> not permitted).
146      * @param widthRatio the maximum label width as a percentage (of the
147      * category space or the range space).
148      */

149     public CategoryLabelPosition(RectangleAnchor categoryAnchor,
150                                  TextBlockAnchor labelAnchor,
151                                  TextAnchor rotationAnchor,
152                                  double angle,
153                                  CategoryLabelWidthType widthType,
154                                  float widthRatio) {
155         
156         if (categoryAnchor == null) {
157             throw new IllegalArgumentException JavaDoc(
158                 "Null 'categoryAnchor' argument."
159             );
160         }
161         if (labelAnchor == null) {
162             throw new IllegalArgumentException JavaDoc(
163                 "Null 'labelAnchor' argument."
164             );
165         }
166         if (rotationAnchor == null) {
167             throw new IllegalArgumentException JavaDoc(
168                 "Null 'rotationAnchor' argument."
169             );
170         }
171         if (widthType == null) {
172             throw new IllegalArgumentException JavaDoc("Null 'widthType' argument.");
173         }
174         
175         this.categoryAnchor = categoryAnchor;
176         this.labelAnchor = labelAnchor;
177         this.rotationAnchor = rotationAnchor;
178         this.angle = angle;
179         this.widthType = widthType;
180         this.widthRatio = widthRatio;
181     
182     }
183     
184     /**
185      * Returns the item label anchor.
186      *
187      * @return The item label anchor (never <code>null</code>).
188      */

189     public RectangleAnchor getCategoryAnchor() {
190         return this.categoryAnchor;
191     }
192     
193     /**
194      * Returns the text block anchor.
195      *
196      * @return The text block anchor (never <code>null</code>).
197      */

198     public TextBlockAnchor getLabelAnchor() {
199         return this.labelAnchor;
200     }
201     
202     /**
203      * Returns the rotation anchor point.
204      *
205      * @return The rotation anchor point (never <code>null</code>).
206      */

207     public TextAnchor getRotationAnchor() {
208         return this.rotationAnchor;
209     }
210     
211     /**
212      * Returns the angle of rotation for the label.
213      *
214      * @return The angle (in radians).
215      */

216     public double getAngle() {
217         return this.angle;
218     }
219     
220     /**
221      * Returns the width calculation type.
222      *
223      * @return The width calculation type.
224      */

225     public CategoryLabelWidthType getWidthType() {
226         return this.widthType;
227     }
228     
229     /**
230      * Returns the ratio used to calculate the maximum category label width.
231      *
232      * @return The ratio.
233      */

234     public float getWidthRatio() {
235         return this.widthRatio;
236     }
237     
238     /**
239      * Tests this instance for equality with an arbitrary object.
240      *
241      * @param obj the object (<code>null</code> permitted).
242      *
243      * @return A boolean.
244      */

245     public boolean equals(Object JavaDoc obj) {
246         if (obj == this) {
247             return true;
248         }
249         if (!(obj instanceof CategoryLabelPosition)) {
250             return false;
251         }
252         CategoryLabelPosition that = (CategoryLabelPosition) obj;
253         if (!this.categoryAnchor.equals(that.categoryAnchor)) {
254             return false;
255         }
256         if (!this.labelAnchor.equals(that.labelAnchor)) {
257             return false;
258         }
259         if (!this.rotationAnchor.equals(that.rotationAnchor)) {
260             return false;
261         }
262         if (this.angle != that.angle) {
263             return false;
264         }
265         if (this.widthType != that.widthType) {
266             return false;
267         }
268         if (this.widthRatio != that.widthRatio) {
269             return false;
270         }
271         return true;
272     }
273     
274     /**
275      * Returns a hash code for this object.
276      *
277      * @return A hash code.
278      */

279     public int hashCode() {
280         int result = 19;
281         result = 37 * result + this.categoryAnchor.hashCode();
282         result = 37 * result + this.labelAnchor.hashCode();
283         result = 37 * result + this.rotationAnchor.hashCode();
284         return result;
285     }
286
287 }
288
Popular Tags