1 39 40 package org.jfree.data; 41 42 import java.io.Serializable ; 43 44 49 public class DefaultMeterDataset extends AbstractDataset implements MeterDataset, Serializable { 50 51 52 private static final double DEFAULT_ADJ = 1.0; 53 54 55 private Number value; 56 57 58 private Number min; 59 60 61 private Number max; 62 63 64 private Number minNormal; 65 66 67 private Number maxNormal; 68 69 70 private Number minWarning; 71 72 73 private Number maxWarning; 74 75 76 private Number minCritical; 77 78 79 private Number maxCritical; 80 81 82 private int borderType; 83 84 85 private String units; 86 87 90 public DefaultMeterDataset() { 91 this(new Double (0), new Double (0), null, null); 92 } 93 94 102 public DefaultMeterDataset(Number min, Number max, Number value, String units) { 103 this(min, max, value, units, null, null, null, null, null, null, FULL_DATA); 104 } 105 106 121 public DefaultMeterDataset(Number min, Number max, Number value, 122 String units, 123 Number minCritical, Number maxCritical, 124 Number minWarning, Number maxWarning, 125 Number minNormal, Number maxNormal, 126 int borderType) { 127 128 setRange(min, max); 129 setValue(value); 130 setUnits(units); 131 setCriticalRange(minCritical, maxCritical); 132 setWarningRange(minWarning, maxWarning); 133 setNormalRange(minNormal, maxNormal); 134 setBorderType(borderType); 135 136 } 137 138 143 public boolean isValueValid() { 144 return (value != null); 145 } 146 147 152 public Number getValue() { 153 return value; 154 } 155 156 161 public void setValue(double value) { 162 setValue(new Double (value)); 163 } 164 165 170 public void setValue(Number value) { 171 172 if (value != null && min != null && max != null) { 173 if (value.doubleValue() < min.doubleValue() 174 || value.doubleValue() > max.doubleValue()) { 175 176 throw new IllegalArgumentException ("Value is out of range for min/max"); 177 178 } 179 } 180 this.value = value; 181 if (value != null && min != null && max != null) { 182 if (min.doubleValue() == max.doubleValue()) { 183 min = new Double (value.doubleValue() - DEFAULT_ADJ); 184 max = new Double (value.doubleValue() + DEFAULT_ADJ); 185 } 186 } 187 fireDatasetChanged(); 188 189 } 190 191 196 public Number getMinimumValue() { 197 return min; 198 } 199 200 205 public Number getMaximumValue() { 206 return max; 207 } 208 209 214 public Number getMinimumNormalValue() { 215 return minNormal; 216 } 217 218 223 public Number getMaximumNormalValue() { 224 return maxNormal; 225 } 226 227 232 public Number getMinimumWarningValue() { 233 return minWarning; 234 } 235 236 241 public Number getMaximumWarningValue() { 242 return maxWarning; 243 } 244 245 250 public Number getMinimumCriticalValue() { 251 return minCritical; 252 } 253 254 259 public Number getMaximumCriticalValue() { 260 return maxCritical; 261 } 262 263 269 public void setRange(Number min, Number max) { 270 271 if (min == null || max == null) { 272 throw new IllegalArgumentException ("Min/Max should not be null"); 273 } 274 275 if (min.doubleValue() > max.doubleValue()) { 277 Number temp = min; 278 min = max; 279 max = temp; 280 } 281 282 if (this.value != null) { 283 if (min.doubleValue() == max.doubleValue()) { 284 min = new Double (value.doubleValue() - DEFAULT_ADJ); 285 max = new Double (value.doubleValue() + DEFAULT_ADJ); 286 } 287 } 288 this.min = min; 289 this.max = max; 290 fireDatasetChanged(); 291 292 } 293 294 301 public void setNormalRange(Number minNormal, Number maxNormal) { 302 303 this.minNormal = minNormal; 304 this.maxNormal = maxNormal; 305 306 if (this.minNormal != null && this.minNormal.doubleValue() < this.min.doubleValue()) { 307 this.min = this.minNormal; 308 } 309 if (this.maxNormal != null && this.maxNormal.doubleValue() > this.max.doubleValue()) { 310 this.max = this.maxNormal; 311 } 312 fireDatasetChanged(); 313 } 314 315 322 public void setWarningRange(Number minWarning, Number maxWarning) { 323 324 this.minWarning = minWarning; 325 this.maxWarning = maxWarning; 326 327 if (this.minWarning != null && this.minWarning.doubleValue() < this.min.doubleValue()) { 328 this.min = this.minWarning; 329 } 330 if (this.maxWarning != null && this.maxWarning.doubleValue() > this.max.doubleValue()) { 331 this.max = this.maxWarning; 332 } 333 fireDatasetChanged(); 334 335 } 336 337 344 public void setCriticalRange(Number minCritical, Number maxCritical) { 345 346 this.minCritical = minCritical; 347 this.maxCritical = maxCritical; 348 349 if (this.minCritical != null && this.minCritical.doubleValue() < this.min.doubleValue()) { 350 this.min = this.minCritical; 351 } 352 if (this.maxCritical != null && this.maxCritical.doubleValue() > this.max.doubleValue()) { 353 this.max = this.maxCritical; 354 } 355 fireDatasetChanged(); 356 357 } 358 359 364 public String getUnits() { 365 return units; 366 } 367 368 373 public void setUnits(String units) { 374 this.units = units; 375 fireDatasetChanged(); 376 } 377 378 383 public int getBorderType() { 384 return borderType; 385 } 386 387 392 public void setBorderType(int borderType) { 393 this.borderType = borderType; 394 fireDatasetChanged(); 395 } 396 397 } 398 | Popular Tags |