1 51 52 package org.jfree.chart.plot; 53 54 import java.awt.geom.Point2D ; 55 56 61 public class CrosshairState { 62 63 67 private boolean calculateDistanceInDataSpace = false; 68 69 70 private double anchorX; 71 72 73 private double anchorY; 74 75 76 private Point2D anchor; 77 78 79 private double crosshairX; 80 81 82 private double crosshairY; 83 84 87 private double distance; 88 89 93 public CrosshairState() { 94 this(false); 95 } 96 97 104 public CrosshairState(boolean calculateDistanceInDataSpace) { 105 this.calculateDistanceInDataSpace = calculateDistanceInDataSpace; 106 } 107 108 117 public double getCrosshairDistance() { 118 return this.distance; 119 } 120 121 131 public void setCrosshairDistance(double distance) { 132 this.distance = distance; 133 } 134 135 151 public void updateCrosshairPoint(double x, double y, 152 double transX, double transY, 153 PlotOrientation orientation) { 154 155 if (this.anchor != null) { 156 double d = 0.0; 157 if (this.calculateDistanceInDataSpace) { 158 d = (x - this.anchorX) * (x - this.anchorX) 159 + (y - this.anchorY) * (y - this.anchorY); 160 } 161 else { 162 double xx = this.anchor.getX(); 163 double yy = this.anchor.getY(); 164 if (orientation == PlotOrientation.HORIZONTAL) { 165 double temp = yy; 166 yy = xx; 167 xx = temp; 168 } 169 d = (transX - xx) * (transX - xx) 170 + (transY - yy) * (transY - yy); 171 } 172 173 if (d < this.distance) { 174 this.crosshairX = x; 175 this.crosshairY = y; 176 this.distance = d; 177 } 178 } 179 180 } 181 182 191 public void updateCrosshairX(double candidateX) { 192 193 double d = Math.abs(candidateX - this.anchorX); 194 if (d < this.distance) { 195 this.crosshairX = candidateX; 196 this.distance = d; 197 } 198 199 } 200 201 210 public void updateCrosshairY(double candidateY) { 211 212 double d = Math.abs(candidateY - this.anchorY); 213 if (d < this.distance) { 214 this.crosshairY = candidateY; 215 this.distance = d; 216 } 217 218 } 219 220 228 public Point2D getAnchor() { 229 return this.anchor; 230 } 231 232 245 public void setAnchor(Point2D anchor) { 246 this.anchor = anchor; 247 } 248 249 256 public double getAnchorX() { 257 return this.anchorX; 258 } 259 260 269 public void setAnchorX(double x) { 270 this.anchorX = x; 271 } 272 273 280 public double getAnchorY() { 281 return this.anchorY; 282 } 283 284 293 public void setAnchorY(double y) { 294 this.anchorY = y; 295 } 296 297 304 public double getCrosshairX() { 305 return this.crosshairX; 306 } 307 308 319 public void setCrosshairX(double x) { 320 this.crosshairX = x; 321 } 322 323 331 public double getCrosshairY() { 332 return this.crosshairY; 333 } 334 335 345 public void setCrosshairY(double y) { 346 this.crosshairY = y; 347 } 348 349 } 350 | Popular Tags |