1 40 41 package org.jfree.chart; 42 43 48 public class CrosshairInfo { 49 50 51 private boolean calculateDistanceInDataSpace = false; 52 53 54 private double anchorX; 55 56 57 private double anchorY; 58 59 60 private double anchorXView; 61 62 63 private double anchorYView; 64 65 66 private double crosshairX; 67 68 69 private double crosshairY; 70 71 72 private double distance; 73 74 77 public CrosshairInfo() { 78 } 79 80 86 public CrosshairInfo(boolean calculateDistanceInDataSpace) { 87 this.calculateDistanceInDataSpace = calculateDistanceInDataSpace; 88 } 89 90 95 public void setCrosshairDistance(double distance) { 96 this.distance = distance; 97 } 98 99 113 public void updateCrosshairPoint(double dataX, double dataY, double viewX, double viewY) { 114 115 double d = 0.0; 116 if (this.calculateDistanceInDataSpace) { 117 d = (dataX - this.anchorX) * (dataX - this.anchorX) 118 + (dataY - this.anchorY) * (dataY - this.anchorY); 119 } 120 else { 121 d = (viewX - this.anchorXView) * (viewX - this.anchorXView) 122 + (viewY - this.anchorYView) * (viewY - this.anchorYView); 123 } 124 125 if (d < distance) { 126 crosshairX = dataX; 127 crosshairY = dataY; 128 distance = d; 129 } 130 131 } 132 133 141 public void updateCrosshairX(double candidateX) { 142 143 double d = Math.abs(candidateX - anchorX); 144 if (d < distance) { 145 crosshairX = candidateX; 146 distance = d; 147 } 148 149 } 150 151 159 public void updateCrosshairY(double candidateY) { 160 161 double d = Math.abs(candidateY - anchorY); 162 if (d < distance) { 163 crosshairY = candidateY; 164 distance = d; 165 } 166 167 } 168 169 174 public void setAnchorX(double x) { 175 this.anchorX = x; 176 this.crosshairX = x; 177 } 178 179 184 public void setAnchorY(double y) { 185 this.anchorY = y; 186 this.crosshairY = y; 187 } 188 189 194 public void setAnchorXView(double x) { 195 this.anchorXView = x; 196 } 197 198 203 public void setAnchorYView(double y) { 204 this.anchorYView = y; 205 } 206 207 212 public double getCrosshairX() { 213 return this.crosshairX; 214 } 215 216 221 public double getCrosshairY() { 222 return this.crosshairY; 223 } 224 225 } 226 | Popular Tags |