1 22 23 24 package net.sourceforge.chart2d; 25 26 27 import java.awt.*; 28 import java.util.*; 29 30 31 35 class GraphChartArea extends ChartArea { 36 37 38 private Vector datasetVector; 39 private Vector graphVector; 40 41 private XAxisArea xAxis; 42 private YAxisArea yAxis; 43 private Rectangle maxBounds; 44 private Rectangle minBounds; 45 46 private int numPlotAxisLabels; 47 48 private float yAxisToWidthRatio; 49 private float yAxisToHeightRatio; 50 51 private float xAxisToWidthRatio; 52 private float xAxisToHeightRatio; 53 54 private float graphToWidthRatio; 55 private float graphToHeightRatio; 56 private float graphableToAvailableRatio; 57 58 private boolean graphLinesThicknessAssociation; 59 private boolean graphHorizontalLinesExistence; 60 private int graphHorizontalLinesThicknessModel; 61 private float[] graphHorizontalLinesStyle; 62 private Color graphHorizontalLinesColor; 63 64 private boolean graphVerticalLinesExistence; 65 private int graphVerticalLinesThicknessModel; 66 private float[] graphVerticalLinesStyle; 67 private Color graphVerticalLinesColor; 68 69 private boolean customizeGreatestValue; 70 private float customGreatestValue; 71 private boolean customizeLeastValue; 72 private float customLeastValue; 73 74 private float numbersAxisRangeHigh; 75 private float numbersAxisRangeLow; 76 77 private int numbersAxisLabelsType; 78 private Vector warningRegions; 79 80 private boolean graphComponentsColoringByCat; 81 private Color[] graphComponentsColorsByCat; 82 83 private boolean needsUpdate; 84 85 86 90 GraphChartArea() { 91 92 xAxis = new XAxisArea(); 93 yAxis = new YAxisArea(); 94 maxBounds = new Rectangle(); 95 minBounds = new Rectangle(); 96 needsUpdate = true; 97 98 setNumPlotAxisLabels (5); 99 setCustomGreatestValue (false, 0f); 100 setCustomLeastValue (false, 0f); 101 setGraphableToAvailableRatio (.95f); 102 103 setYAxisToWidthRatio (.25f); 104 setXAxisToWidthRatio (.50f); 105 setGraphToWidthRatio (.50f); 106 107 setYAxisToHeightRatio (.75f); 108 setGraphToHeightRatio (.75f); 109 setXAxisToHeightRatio (.25f); 110 111 setWarningRegions (new Vector (0, 0)); 112 113 setGraphComponentsColoringByCat(false); 114 setGraphComponentsColorsByCat (new Color[0]); 115 116 resetGraphChartAreaModel (true); 117 } 118 119 120 124 final void setGraphComponentsColoringByCat (boolean b) { 125 126 needsUpdate = true; 127 graphComponentsColoringByCat = b; 128 } 129 130 131 135 final void setGraphComponentsColorsByCat (Color[] colors) { 136 137 needsUpdate = true; 138 graphComponentsColorsByCat = colors; 139 } 140 141 142 146 final void setWarningRegions (Vector v) { 147 148 warningRegions = v; 149 needsUpdate = true; 150 } 151 152 153 154 158 final void setDatasetVector (Vector vector) { 159 160 needsUpdate = true; 161 datasetVector = vector; 162 } 163 164 165 172 final void setNumPlotAxisLabels (int num) { 173 174 needsUpdate = true; 175 numPlotAxisLabels = num; 176 } 177 178 179 184 final void setYAxisToWidthRatio (float ratio) { 185 186 needsUpdate = true; 187 yAxisToWidthRatio = ratio; 188 } 189 190 191 196 final void setYAxisToHeightRatio (float ratio) { 197 198 needsUpdate = true; 199 yAxisToHeightRatio = ratio; 200 } 201 202 203 208 final void setXAxisToWidthRatio (float ratio) { 209 210 needsUpdate = true; 211 xAxisToWidthRatio = ratio; 212 } 213 214 215 220 final void setXAxisToHeightRatio (float ratio) { 221 222 needsUpdate = true; 223 xAxisToHeightRatio = ratio; 224 } 225 226 227 232 final void setGraphToWidthRatio (float ratio) { 233 234 needsUpdate = true; 235 graphToWidthRatio = ratio; 236 } 237 238 239 244 final void setGraphToHeightRatio (float ratio) { 245 246 needsUpdate = true; 247 graphToHeightRatio = ratio; 248 } 249 250 251 266 final void setCustomGreatestValue (boolean customize, float value) { 267 268 needsUpdate = true; 269 customizeGreatestValue = customize; 270 customGreatestValue = value; 271 } 272 273 274 289 final void setCustomLeastValue (boolean customize, float value) { 290 291 needsUpdate = true; 292 customizeLeastValue = customize; 293 customLeastValue = value; 294 } 295 296 297 304 final void setGraphableToAvailableRatio (float ratio) { 305 306 needsUpdate = true; 307 graphableToAvailableRatio = ratio; 308 } 309 310 311 315 final boolean getGraphComponentsColoringByCat() { 316 return graphComponentsColoringByCat; 317 } 318 319 320 324 final Color[] getGraphComponentsColorsByCat() { 325 return graphComponentsColorsByCat; 326 } 327 328 329 333 final Vector getWarningRegions() { 334 return warningRegions; 335 } 336 337 338 342 final Vector getDatasetVector() { 343 return datasetVector; 344 } 345 346 347 351 final XAxisArea getXAxis() { 352 353 return xAxis; 354 } 355 356 357 361 final YAxisArea getYAxis() { 362 363 return yAxis; 364 } 365 366 367 371 final void setGraphVector (Vector vector) { 372 373 needsUpdate = true; 374 graphVector = vector; 375 } 376 377 378 382 final Vector getGraphVector() { 383 384 return graphVector; 385 } 386 387 388 395 final int getNumPlotAxisLabels() { 396 397 return numPlotAxisLabels; 398 } 399 400 401 405 final float getYAxisToWidthRatio() { 406 407 return yAxisToWidthRatio; 408 } 409 410 411 415 final float getYAxisToHeightRatio() { 416 417 return yAxisToHeightRatio; 418 } 419 420 421 425 final float getXAxisToWidthRatio() { 426 427 return xAxisToWidthRatio; 428 } 429 430 431 435 final float getXAxisToHeightRatio() { 436 437 return xAxisToHeightRatio; 438 } 439 440 441 445 float getGraphToWidthRatio() { 446 447 return graphToWidthRatio; 448 } 449 450 451 455 final float getGraphToHeightRatio() { 456 457 return graphToHeightRatio; 458 } 459 460 461 465 final boolean getCustomizeGreatestValue() { 466 467 return customizeGreatestValue; 468 } 469 470 471 475 final float getCustomGreatestValue() { 476 477 return customGreatestValue; 478 } 479 480 481 485 final boolean getCustomizeLeastValue() { 486 487 return customizeLeastValue; 488 } 489 490 491 495 final float getCustomLeastValue() { 496 497 return customLeastValue; 498 } 499 500 501 505 final float getGraphableToAvailableRatio() { 506 507 return graphableToAvailableRatio; 508 } 509 510 511 515 final boolean getGraphChartAreaNeedsUpdate() { 516 517 for (int i = 0; i < warningRegions.size(); ++i) { 518 needsUpdate = needsUpdate || 519 ((WarningRegion)warningRegions.get (i)).getWarningRegionNeedsUpdate(); 520 } 521 return (needsUpdate || getChartAreaNeedsUpdate() || 522 xAxis.getXAxisAreaNeedsUpdate() || yAxis.getYAxisAreaNeedsUpdate()); 523 } 524 525 526 537 final void resetGraphChartAreaModel (boolean reset) { 538 539 needsUpdate = true; 540 resetChartAreaModel (reset); 541 xAxis.resetXAxisModel (reset); 542 yAxis.resetYAxisModel (reset); 543 } 544 545 546 550 final void updateGraphChartArea (Graphics2D g2D) { 551 552 if (getGraphChartAreaNeedsUpdate()) { 553 updateChartArea (g2D); 554 } 556 needsUpdate = false; 557 } 558 559 560 564 void paintComponent (Graphics2D g2D) { 565 566 updateGraphChartArea (g2D); 567 super.paintComponent (g2D); 568 for (int i = 0; i < warningRegions.size(); ++i) { 569 ((WarningRegion)warningRegions.get (i)).paintComponent (g2D); 570 } 571 xAxis.paintComponent (g2D); 572 yAxis.paintComponent (g2D); 573 } 574 } | Popular Tags |