001/* =========================================================== 002 * JFreeChart : a free chart library for the Java(tm) platform 003 * =========================================================== 004 * 005 * (C) Copyright 2000-2020, 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-2016, 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.ui.TextAnchor; 049import org.jfree.chart.util.Args; 050 051/** 052 * The attributes that control the position of the label for each data item on 053 * a chart. Instances of this class are immutable. 054 */ 055public class ItemLabelPosition implements Serializable { 056 057 /** For serialization. */ 058 private static final long serialVersionUID = 5845390630157034499L; 059 060 /** The item label anchor point. */ 061 private ItemLabelAnchor itemLabelAnchor; 062 063 /** The text anchor. */ 064 private TextAnchor textAnchor; 065 066 /** The rotation anchor. */ 067 private TextAnchor rotationAnchor; 068 069 /** The rotation angle. */ 070 private double angle; 071 072 /** 073 * Creates a new position record with default settings. 074 */ 075 public ItemLabelPosition() { 076 this(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER, 077 TextAnchor.CENTER, 0.0); 078 } 079 080 /** 081 * Creates a new position record (with zero rotation). 082 * 083 * @param itemLabelAnchor the item label anchor ({@code null} not 084 * permitted). 085 * @param textAnchor the text anchor ({@code null} not permitted). 086 */ 087 public ItemLabelPosition(ItemLabelAnchor itemLabelAnchor, 088 TextAnchor textAnchor) { 089 this(itemLabelAnchor, textAnchor, TextAnchor.CENTER, 0.0); 090 } 091 092 /** 093 * Creates a new position record. The item label anchor is a point 094 * relative to the data item (dot, bar or other visual item) on a chart. 095 * The item label is aligned by aligning the text anchor with the 096 * item label anchor. 097 * 098 * @param itemLabelAnchor the item label anchor ({@code null} not 099 * permitted). 100 * @param textAnchor the text anchor ({@code null} not permitted). 101 * @param rotationAnchor the rotation anchor ({@code null} not 102 * permitted). 103 * @param angle the rotation angle (in radians). 104 */ 105 public ItemLabelPosition(ItemLabelAnchor itemLabelAnchor, 106 TextAnchor textAnchor, TextAnchor rotationAnchor, double angle) { 107 108 Args.nullNotPermitted(itemLabelAnchor, "itemLabelAnchor"); 109 Args.nullNotPermitted(textAnchor, "textAnchor"); 110 Args.nullNotPermitted(rotationAnchor, "rotationAnchor"); 111 this.itemLabelAnchor = itemLabelAnchor; 112 this.textAnchor = textAnchor; 113 this.rotationAnchor = rotationAnchor; 114 this.angle = angle; 115 } 116 117 /** 118 * Returns the item label anchor. 119 * 120 * @return The item label anchor (never {@code null}). 121 */ 122 public ItemLabelAnchor getItemLabelAnchor() { 123 return this.itemLabelAnchor; 124 } 125 126 /** 127 * Returns the text anchor. 128 * 129 * @return The text anchor (never {@code null}). 130 */ 131 public TextAnchor getTextAnchor() { 132 return this.textAnchor; 133 } 134 135 /** 136 * Returns the rotation anchor point. 137 * 138 * @return The rotation anchor point (never {@code null}). 139 */ 140 public TextAnchor getRotationAnchor() { 141 return this.rotationAnchor; 142 } 143 144 /** 145 * Returns the angle of rotation for the label. 146 * 147 * @return The angle (in radians). 148 */ 149 public double getAngle() { 150 return this.angle; 151 } 152 153 /** 154 * Tests this object for equality with an arbitrary object. 155 * 156 * @param obj the object ({@code null} permitted). 157 * 158 * @return A boolean. 159 */ 160 @Override 161 public boolean equals(Object obj) { 162 if (obj == this) { 163 return true; 164 } 165 if (!(obj instanceof ItemLabelPosition)) { 166 return false; 167 } 168 ItemLabelPosition that = (ItemLabelPosition) obj; 169 if (!this.itemLabelAnchor.equals(that.itemLabelAnchor)) { 170 return false; 171 } 172 if (!this.textAnchor.equals(that.textAnchor)) { 173 return false; 174 } 175 if (!this.rotationAnchor.equals(that.rotationAnchor)) { 176 return false; 177 } 178 if (this.angle != that.angle) { 179 return false; 180 } 181 return true; 182 } 183 184}