001/* =========================================================== 002 * JFreeChart : a free chart library for the Java(tm) platform 003 * =========================================================== 004 * 005 * (C) Copyright 2000-2021, 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 * AxisEntity.java 029 * ---------------- 030 * (C) Copyright 2009-2021, by Object Refinery Limited and Contributors. 031 * 032 * Original Author: Peter Kolb; 033 * Contributor(s): David Gilbert (for Object Refinery Limited); 034 * 035 */ 036 037package org.jfree.chart.entity; 038 039import java.awt.Shape; 040import java.io.IOException; 041import java.io.ObjectInputStream; 042import java.io.ObjectOutputStream; 043import java.util.Objects; 044 045import org.jfree.chart.HashUtils; 046import org.jfree.chart.axis.Axis; 047import org.jfree.chart.util.Args; 048import org.jfree.chart.util.SerialUtils; 049 050/** 051 * A class that captures information about an {@link Axis} belonging to a 052 * chart. 053 */ 054public class AxisEntity extends ChartEntity { 055 056 /** For serialization. */ 057 private static final long serialVersionUID = -4445994133561919083L; 058 //same as for ChartEntity! 059 060 /** The axis for the entity. */ 061 private Axis axis; 062 063 /** 064 * Creates a new axis entity. 065 * 066 * @param area the area ({@code null} not permitted). 067 * @param axis the axis ({@code null} not permitted). 068 */ 069 public AxisEntity(Shape area, Axis axis) { 070 // defer argument checks... 071 this(area, axis, null); 072 } 073 074 /** 075 * Creates a new axis entity. 076 * 077 * @param area the area ({@code null} not permitted). 078 * @param axis the axis ({@code null} not permitted). 079 * @param toolTipText the tool tip text ({@code null} permitted). 080 */ 081 public AxisEntity(Shape area, Axis axis, String toolTipText) { 082 // defer argument checks... 083 this(area, axis, toolTipText, null); 084 } 085 086 /** 087 * Creates a new axis entity. 088 * 089 * @param area the area ({@code null} not permitted). 090 * @param axis the axis ({@code null} not permitted). 091 * @param toolTipText the tool tip text ({@code null} permitted). 092 * @param urlText the URL text for HTML image maps ({@code null} 093 * permitted). 094 */ 095 public AxisEntity(Shape area, Axis axis, String toolTipText, 096 String urlText) { 097 super(area, toolTipText, urlText); 098 Args.nullNotPermitted(axis, "axis"); 099 this.axis = axis; 100 } 101 102 /** 103 * Returns the axis that occupies the entity area. 104 * 105 * @return The axis (never {@code null}). 106 */ 107 public Axis getAxis() { 108 return this.axis; 109 } 110 111 /** 112 * Returns a string representation of the chart entity, useful for 113 * debugging. 114 * 115 * @return A string. 116 */ 117 @Override 118 public String toString() { 119 StringBuilder sb = new StringBuilder("AxisEntity: "); 120 sb.append("tooltip = "); 121 sb.append(getToolTipText()); 122 return sb.toString(); 123 } 124 125 /** 126 * Tests the entity for equality with an arbitrary object. 127 * 128 * @param obj the object to test against ({@code null} permitted). 129 * 130 * @return A boolean. 131 */ 132 @Override 133 public boolean equals(Object obj) { 134 if (obj == this) { 135 return true; 136 } 137 if (!(obj instanceof AxisEntity)) { 138 return false; 139 } 140 AxisEntity that = (AxisEntity) obj; 141 if (!getArea().equals(that.getArea())) { 142 return false; 143 } 144 if (!Objects.equals(getToolTipText(), that.getToolTipText())) { 145 return false; 146 } 147 if (!Objects.equals(getURLText(), that.getURLText())) { 148 return false; 149 } 150 if (!(this.axis.equals(that.axis))) { 151 return false; 152 } 153 return true; 154 } 155 156 /** 157 * Returns a hash code for this instance. 158 * 159 * @return A hash code. 160 */ 161 @Override 162 public int hashCode() { 163 int result = 39; 164 result = HashUtils.hashCode(result, getToolTipText()); 165 result = HashUtils.hashCode(result, getURLText()); 166 return result; 167 } 168 169 /** 170 * Returns a clone of the entity. 171 * 172 * @return A clone. 173 * 174 * @throws CloneNotSupportedException if there is a problem cloning the 175 * entity. 176 */ 177 @Override 178 public Object clone() throws CloneNotSupportedException { 179 return super.clone(); 180 } 181 182 /** 183 * Provides serialization support. 184 * 185 * @param stream the output stream. 186 * 187 * @throws IOException if there is an I/O error. 188 */ 189 private void writeObject(ObjectOutputStream stream) throws IOException { 190 stream.defaultWriteObject(); 191 SerialUtils.writeShape(getArea(), stream); 192 } 193 194 /** 195 * Provides serialization support. 196 * 197 * @param stream the input stream. 198 * 199 * @throws IOException if there is an I/O error. 200 * @throws ClassNotFoundException if there is a classpath problem. 201 */ 202 private void readObject(ObjectInputStream stream) 203 throws IOException, ClassNotFoundException { 204 stream.defaultReadObject(); 205 setArea(SerialUtils.readShape(stream)); 206 } 207 208}