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