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: * CategoryLabelPosition.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: CategoryLabelPosition.java,v 1.7.2.2 2007/04/13 09:49:23 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 31-Oct-2003 : Version 1 (DG);
040: * 17-Feb-2004 : Added new constructor (DG);
041: * 23-Mar-2004 : Added width calculation parameters (DG);
042: * 07-Jan-2005 : Fixed bug in equals() method (DG);
043: * 11-Jan-2005 : Removed deprecated constructor in preparation for the 1.0.0
044: * release (DG);
045: *
046: */
047:
048: package org.jfree.chart.axis;
049:
050: import java.io.Serializable;
051:
052: import org.jfree.text.TextBlockAnchor;
053: import org.jfree.ui.RectangleAnchor;
054: import org.jfree.ui.TextAnchor;
055:
056: /**
057: * The attributes that control the position of the labels for the categories on
058: * a {@link CategoryAxis}. Instances of this class are immutable and other
059: * JFreeChart classes rely upon this.
060: */
061: public class CategoryLabelPosition implements Serializable {
062:
063: /** For serialization. */
064: private static final long serialVersionUID = 5168681143844183864L;
065:
066: /** The category anchor point. */
067: private RectangleAnchor categoryAnchor;
068:
069: /** The text block anchor. */
070: private TextBlockAnchor labelAnchor;
071:
072: /** The rotation anchor. */
073: private TextAnchor rotationAnchor;
074:
075: /** The rotation angle (in radians). */
076: private double angle;
077:
078: /** The width calculation type. */
079: private CategoryLabelWidthType widthType;
080:
081: /**
082: * The maximum label width as a percentage of the category space or the
083: * range space.
084: */
085: private float widthRatio;
086:
087: /**
088: * Creates a new position record with default settings.
089: */
090: public CategoryLabelPosition() {
091: this (RectangleAnchor.CENTER, TextBlockAnchor.BOTTOM_CENTER,
092: TextAnchor.CENTER, 0.0,
093: CategoryLabelWidthType.CATEGORY, 0.95f);
094: }
095:
096: /**
097: * Creates a new category label position record.
098: *
099: * @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 (categoryAnchor, labelAnchor, TextAnchor.CENTER, 0.0,
107: CategoryLabelWidthType.CATEGORY, 0.95f);
108: }
109:
110: /**
111: * Creates a new category label position record.
112: *
113: * @param categoryAnchor the category anchor (<code>null</code> not
114: * permitted).
115: * @param labelAnchor the label anchor (<code>null</code> not permitted).
116: * @param widthType the width type (<code>null</code> not permitted).
117: * @param widthRatio the maximum label width as a percentage (of the
118: * category space or the range space).
119: */
120: public CategoryLabelPosition(RectangleAnchor categoryAnchor,
121: TextBlockAnchor labelAnchor,
122: CategoryLabelWidthType widthType, float widthRatio) {
123: // argument checking delegated...
124: this (categoryAnchor, labelAnchor, TextAnchor.CENTER, 0.0,
125: widthType, widthRatio);
126: }
127:
128: /**
129: * Creates a new position record. The item label anchor is a point
130: * relative to the data item (dot, bar or other visual item) on a chart.
131: * The item label is aligned by aligning the text anchor with the item
132: * label anchor.
133: *
134: * @param categoryAnchor the category anchor (<code>null</code> not
135: * permitted).
136: * @param labelAnchor the label anchor (<code>null</code> not permitted).
137: * @param rotationAnchor the rotation anchor (<code>null</code> not
138: * permitted).
139: * @param angle the rotation angle (<code>null</code> not permitted).
140: * @param widthType the width type (<code>null</code> not permitted).
141: * @param widthRatio the maximum label width as a percentage (of the
142: * category space or the range space).
143: */
144: public CategoryLabelPosition(RectangleAnchor categoryAnchor,
145: TextBlockAnchor labelAnchor, TextAnchor rotationAnchor,
146: double angle, CategoryLabelWidthType widthType,
147: float widthRatio) {
148:
149: if (categoryAnchor == null) {
150: throw new IllegalArgumentException(
151: "Null 'categoryAnchor' argument.");
152: }
153: if (labelAnchor == null) {
154: throw new IllegalArgumentException(
155: "Null 'labelAnchor' argument.");
156: }
157: if (rotationAnchor == null) {
158: throw new IllegalArgumentException(
159: "Null 'rotationAnchor' argument.");
160: }
161: if (widthType == null) {
162: throw new IllegalArgumentException(
163: "Null 'widthType' argument.");
164: }
165:
166: this .categoryAnchor = categoryAnchor;
167: this .labelAnchor = labelAnchor;
168: this .rotationAnchor = rotationAnchor;
169: this .angle = angle;
170: this .widthType = widthType;
171: this .widthRatio = widthRatio;
172:
173: }
174:
175: /**
176: * Returns the item label anchor.
177: *
178: * @return The item label anchor (never <code>null</code>).
179: */
180: public RectangleAnchor getCategoryAnchor() {
181: return this .categoryAnchor;
182: }
183:
184: /**
185: * Returns the text block anchor.
186: *
187: * @return The text block anchor (never <code>null</code>).
188: */
189: public TextBlockAnchor getLabelAnchor() {
190: return this .labelAnchor;
191: }
192:
193: /**
194: * Returns the rotation anchor point.
195: *
196: * @return The rotation anchor point (never <code>null</code>).
197: */
198: public TextAnchor getRotationAnchor() {
199: return this .rotationAnchor;
200: }
201:
202: /**
203: * Returns the angle of rotation for the label.
204: *
205: * @return The angle (in radians).
206: */
207: public double getAngle() {
208: return this .angle;
209: }
210:
211: /**
212: * Returns the width calculation type.
213: *
214: * @return The width calculation type (never <code>null</code>).
215: */
216: public CategoryLabelWidthType getWidthType() {
217: return this .widthType;
218: }
219:
220: /**
221: * Returns the ratio used to calculate the maximum category label width.
222: *
223: * @return The ratio.
224: */
225: public float getWidthRatio() {
226: return this .widthRatio;
227: }
228:
229: /**
230: * Tests this instance for equality with an arbitrary object.
231: *
232: * @param obj the object (<code>null</code> permitted).
233: *
234: * @return A boolean.
235: */
236: public boolean equals(Object obj) {
237: if (obj == this ) {
238: return true;
239: }
240: if (!(obj instanceof CategoryLabelPosition)) {
241: return false;
242: }
243: CategoryLabelPosition that = (CategoryLabelPosition) obj;
244: if (!this .categoryAnchor.equals(that.categoryAnchor)) {
245: return false;
246: }
247: if (!this .labelAnchor.equals(that.labelAnchor)) {
248: return false;
249: }
250: if (!this .rotationAnchor.equals(that.rotationAnchor)) {
251: return false;
252: }
253: if (this .angle != that.angle) {
254: return false;
255: }
256: if (this .widthType != that.widthType) {
257: return false;
258: }
259: if (this .widthRatio != that.widthRatio) {
260: return false;
261: }
262: return true;
263: }
264:
265: /**
266: * Returns a hash code for this object.
267: *
268: * @return A hash code.
269: */
270: public int hashCode() {
271: int result = 19;
272: result = 37 * result + this .categoryAnchor.hashCode();
273: result = 37 * result + this .labelAnchor.hashCode();
274: result = 37 * result + this.rotationAnchor.hashCode();
275: return result;
276: }
277:
278: }
|