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