1 22 23 24 package net.sourceforge.chart2d; 25 26 27 import java.awt.*; 28 import java.awt.geom.*; 29 30 31 36 final class WarningRegion { 37 38 41 static final float TOP = Float.POSITIVE_INFINITY; 42 43 46 static final float BOTTOM = Float.NEGATIVE_INFINITY; 47 48 51 static final int LABELS_BOTTOM = 0; 52 53 56 static final int LABELS_LEFT = 1; 57 58 59 private int graphSpaceX, graphSpaceY, graphSpaceWidth, graphSpaceHeight; 60 private float high; 61 private float highGraph; 62 private float low; 63 private float lowGraph; 64 private int graphType; 65 private Color componentColor; 66 private boolean backgroundExistence; 67 private Color backgroundColor; 68 private Rectangle2D.Float background; 69 private boolean needsUpdate; 70 71 72 75 WarningRegion() { 76 needsUpdate = true; 77 } 78 79 80 84 final void setGraphSpaceX (int x) { 85 graphSpaceX = x; 86 needsUpdate = true; 87 } 88 89 90 94 final void setGraphSpaceY (int y) { 95 graphSpaceY = y; 96 needsUpdate = true; 97 } 98 99 100 104 final void setGraphSpaceWidth (int w) { 105 graphSpaceWidth = w; 106 needsUpdate = true; 107 } 108 109 110 114 final void setGraphSpaceHeight (int h) { 115 graphSpaceHeight = h; 116 needsUpdate = true; 117 } 118 119 120 124 final void setHigh (float h) { 125 high = h; 126 needsUpdate = true; 127 } 128 129 130 134 final void setHighGraph (float h) { 135 136 highGraph = h; 137 needsUpdate = true; 138 } 139 140 141 145 final void setLow (float l) { 146 low = l; 147 needsUpdate = true; 148 } 149 150 151 155 final void setLowGraph (float l) { 156 lowGraph = l; 157 needsUpdate = true; 158 } 159 160 161 166 final void setGraphType (int t) { 167 graphType = t; 168 needsUpdate = true; 169 } 170 171 172 176 final void setComponentColor (Color c) { 177 componentColor = c; 178 needsUpdate = true; 179 } 180 181 182 186 final void setBackgroundExistence (boolean e) { 187 backgroundExistence = e; 188 needsUpdate = true; 189 } 190 191 192 196 final void setBackgroundColor (Color c) { 197 backgroundColor = c; 198 needsUpdate = true; 199 } 200 201 202 206 final int getGraphSpaceX() { 207 return graphSpaceX; 208 } 209 210 211 215 final int getGraphSpaceY() { 216 return graphSpaceY; 217 } 218 219 220 224 225 final int getGraphSpaceWidth() { 226 return graphSpaceWidth; 227 } 228 229 230 234 final int getGraphSpaceHeight() { 235 return graphSpaceHeight; 236 } 237 238 239 243 final float getHigh() { 244 return high; 245 } 246 247 248 252 final float getHighGraph() { 253 return highGraph; 254 } 255 256 257 261 final float getLow() { 262 return low; 263 } 264 265 266 270 final float getLowGraph() { 271 return lowGraph; 272 } 273 274 275 280 final int getGraphType() { 281 return graphType; 282 } 283 284 285 289 final Color getComponentColor() { 290 return componentColor; 291 } 292 293 294 298 final boolean getBackgroundExistence() { 299 return backgroundExistence; 300 } 301 302 303 307 final Color getBackgroundColor() { 308 return backgroundColor; 309 } 310 311 312 316 final Rectangle2D.Float getBackgroundBounds() { 317 updateWarningRegion(); 318 return background; 319 } 320 321 322 323 327 final boolean getWarningRegionNeedsUpdate() { 328 return needsUpdate; 329 } 330 331 332 337 final void paintComponent (Graphics2D g2D) { 338 339 updateWarningRegion(); 340 if (backgroundExistence) { 341 g2D.setColor (backgroundColor); 342 g2D.fill (background); 343 } 344 } 345 346 347 351 final void updateWarningRegion() { 352 353 if (getWarningRegionNeedsUpdate()) { 354 355 needsUpdate = false; 356 357 float x, y, width, height; 358 if (graphType == LABELS_BOTTOM) { 359 360 x = graphSpaceX; 361 width = graphSpaceWidth; 362 363 y = graphSpaceY + graphSpaceHeight - highGraph; 364 height = highGraph - lowGraph; 365 } 366 else { 367 368 y = graphSpaceY; 369 height = graphSpaceHeight; 370 371 x = graphSpaceX + lowGraph; 372 width = highGraph - lowGraph; 373 } 374 375 background = new Rectangle2D.Float (x, y, width, height); 376 } 377 } 378 } | Popular Tags |