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