1 43 44 package org.jfree.chart.annotations; 45 46 import java.awt.Graphics2D ; 47 import java.awt.geom.Rectangle2D ; 48 import java.io.Serializable ; 49 50 import org.jfree.chart.axis.ValueAxis; 51 import org.jfree.chart.plot.Plot; 52 import org.jfree.chart.plot.PlotOrientation; 53 import org.jfree.chart.plot.PlotRenderingInfo; 54 import org.jfree.chart.plot.XYPlot; 55 import org.jfree.ui.Drawable; 56 import org.jfree.ui.RectangleEdge; 57 import org.jfree.util.ObjectUtilities; 58 import org.jfree.util.PublicCloneable; 59 60 64 public class XYDrawableAnnotation extends AbstractXYAnnotation 65 implements Cloneable , PublicCloneable, 66 Serializable { 67 68 69 private static final long serialVersionUID = -6540812859722691020L; 70 71 72 private double x; 73 74 75 private double y; 76 77 78 private double width; 79 80 81 private double height; 82 83 84 private Drawable drawable; 85 86 95 public XYDrawableAnnotation(double x, double y, double width, double height, 96 Drawable drawable) { 97 98 if (drawable == null) { 99 throw new IllegalArgumentException ("Null 'drawable' argument."); 100 } 101 this.x = x; 102 this.y = y; 103 this.width = width; 104 this.height = height; 105 this.drawable = drawable; 106 107 } 108 109 121 public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, 122 ValueAxis domainAxis, ValueAxis rangeAxis, 123 int rendererIndex, 124 PlotRenderingInfo info) { 125 126 PlotOrientation orientation = plot.getOrientation(); 127 RectangleEdge domainEdge = Plot.resolveDomainAxisLocation( 128 plot.getDomainAxisLocation(), orientation 129 ); 130 RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation( 131 plot.getRangeAxisLocation(), orientation 132 ); 133 float j2DX = (float) domainAxis.valueToJava2D( 134 this.x, dataArea, domainEdge 135 ); 136 float j2DY = (float) rangeAxis.valueToJava2D( 137 this.y, dataArea, rangeEdge 138 ); 139 Rectangle2D area = new Rectangle2D.Double ( 140 j2DX - this.width / 2.0, j2DY - this.height / 2.0, 141 this.width, this.height 142 ); 143 this.drawable.draw(g2, area); 144 String toolTip = getToolTipText(); 145 String url = getURL(); 146 if (toolTip != null || url != null) { 147 addEntity(info, area, rendererIndex, toolTip, url); 148 } 149 150 } 151 152 159 public boolean equals(Object obj) { 160 161 if (obj == this) { return true; 163 } 164 if (!super.equals(obj)) { 166 return false; 167 } 168 if (!(obj instanceof XYDrawableAnnotation)) { 169 return false; 170 } 171 XYDrawableAnnotation that = (XYDrawableAnnotation) obj; 172 if (this.x != that.x) { 173 return false; 174 } 175 if (this.y != that.y) { 176 return false; 177 } 178 if (this.width != that.width) { 179 return false; 180 } 181 if (this.height != that.height) { 182 return false; 183 } 184 if (!ObjectUtilities.equal(this.drawable, that.drawable)) { 185 return false; 186 } 187 return true; 189 190 } 191 192 197 public int hashCode() { 198 int result; 199 long temp; 200 temp = Double.doubleToLongBits(this.x); 201 result = (int) (temp ^ (temp >>> 32)); 202 temp = Double.doubleToLongBits(this.y); 203 result = 29 * result + (int) (temp ^ (temp >>> 32)); 204 temp = Double.doubleToLongBits(this.width); 205 result = 29 * result + (int) (temp ^ (temp >>> 32)); 206 temp = Double.doubleToLongBits(this.height); 207 result = 29 * result + (int) (temp ^ (temp >>> 32)); 208 return result; 209 } 210 211 218 public Object clone() throws CloneNotSupportedException { 219 return super.clone(); 220 } 221 222 } 223 | Popular Tags |