001/* =========================================================== 002 * JFreeChart : a free chart library for the Java(tm) platform 003 * =========================================================== 004 * 005 * (C) Copyright 2000-2013, 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 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. 025 * Other names may be trademarks of their respective owners.] 026 * 027 * ---------------------- 028 * ItemLabelPosition.java 029 * ---------------------- 030 * (C) Copyright 2003-2013, by Object Refinery Limited and Contributors. 031 * 032 * Original Author: David Gilbert (for Object Refinery Limited); 033 * Contributor(s): -; 034 * 035 * Changes 036 * ------- 037 * 27-Oct-2003 : Version 1 (DG); 038 * 19-Feb-2004 : Moved to org.jfree.chart.labels, updated Javadocs and argument 039 * checking (DG); 040 * 26-Feb-2004 : Added new constructor (DG); 041 * 03-Jul-2013 : Use ParamChecks (DG); 042 * 043 */ 044 045package org.jfree.chart.labels; 046 047import java.io.Serializable; 048import org.jfree.chart.util.ParamChecks; 049 050import 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 */ 056public 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, TextAnchor rotationAnchor, double angle) { 108 109 ParamChecks.nullNotPermitted(itemLabelAnchor, "itemLabelAnchor"); 110 ParamChecks.nullNotPermitted(textAnchor, "textAnchor"); 111 ParamChecks.nullNotPermitted(rotationAnchor, "rotationAnchor"); 112 this.itemLabelAnchor = itemLabelAnchor; 113 this.textAnchor = textAnchor; 114 this.rotationAnchor = rotationAnchor; 115 this.angle = angle; 116 } 117 118 /** 119 * Returns the item label anchor. 120 * 121 * @return The item label anchor (never <code>null</code>). 122 */ 123 public ItemLabelAnchor getItemLabelAnchor() { 124 return this.itemLabelAnchor; 125 } 126 127 /** 128 * Returns the text anchor. 129 * 130 * @return The text anchor (never <code>null</code>). 131 */ 132 public TextAnchor getTextAnchor() { 133 return this.textAnchor; 134 } 135 136 /** 137 * Returns the rotation anchor point. 138 * 139 * @return The rotation anchor point (never <code>null</code>). 140 */ 141 public TextAnchor getRotationAnchor() { 142 return this.rotationAnchor; 143 } 144 145 /** 146 * Returns the angle of rotation for the label. 147 * 148 * @return The angle (in radians). 149 */ 150 public double getAngle() { 151 return this.angle; 152 } 153 154 /** 155 * Tests this object for equality with an arbitrary object. 156 * 157 * @param obj the object (<code>null</code> permitted). 158 * 159 * @return A boolean. 160 */ 161 @Override 162 public boolean equals(Object obj) { 163 if (obj == this) { 164 return true; 165 } 166 if (!(obj instanceof ItemLabelPosition)) { 167 return false; 168 } 169 ItemLabelPosition that = (ItemLabelPosition) obj; 170 if (!this.itemLabelAnchor.equals(that.itemLabelAnchor)) { 171 return false; 172 } 173 if (!this.textAnchor.equals(that.textAnchor)) { 174 return false; 175 } 176 if (!this.rotationAnchor.equals(that.rotationAnchor)) { 177 return false; 178 } 179 if (this.angle != that.angle) { 180 return false; 181 } 182 return true; 183 } 184 185}