1 22 23 24 package net.sourceforge.chart2d; 25 26 27 import java.awt.*; 28 import java.awt.geom.*; 29 import java.util.*; 30 31 32 35 abstract class FancyShape { 36 37 38 41 static final int LEFT = 0; 42 43 46 static final int RIGHT = 1; 47 48 51 static final int TOP = 2; 52 53 56 static final int BOTTOM = 3; 57 58 61 static final int NONE = 6; 62 63 66 static final int ALL = 7; 67 68 71 static final int LABELSBOTTOM = 0; 72 73 76 static final int LABELSLEFT = 1; 77 78 79 private Rectangle2D.Float lightBounds; 80 private int lightSource; 81 private Color color, outlineColor; 82 private Paint paint, outlinePaint; 83 private boolean outlineExistence; 84 private Vector warningRegions; 85 private Vector warningPaints; 86 private int type; 87 private Rectangle2D.Float graphBounds; 88 private boolean needsUpdate; 89 90 91 94 FancyShape() { 95 needsUpdate = true; 96 warningPaints = new Vector (24, 5); 97 } 98 99 100 105 final void setLightBounds (Rectangle2D.Float b) { 106 lightBounds = b; 107 needsUpdate = true; 108 } 109 110 111 116 final void setLightSource (int s) { 117 lightSource = s; 118 needsUpdate = true; 119 } 120 121 122 126 final void setColor (Color c) { 127 color = c; 128 needsUpdate = true; 129 } 130 131 132 136 final void setOutlineExistence (boolean e) { 137 outlineExistence = e; 138 needsUpdate = true; 139 } 140 141 142 146 final void setOutlineColor (Color c) { 147 outlineColor = c; 148 needsUpdate = true; 149 } 150 151 152 157 final void setType (int t) { 158 type = t; 159 needsUpdate = true; 160 } 161 162 163 167 final void setWarningRegions (Vector r) { 168 warningRegions = r; 169 needsUpdate = true; 170 } 171 172 173 177 final void setGraphBounds (Rectangle2D.Float b) { 178 graphBounds = b; 179 needsUpdate = true; 180 } 181 182 183 188 final Rectangle2D.Float getLightBounds() { 189 return lightBounds; 190 } 191 192 193 198 final int getLightSource() { 199 return lightSource; 200 } 201 202 203 207 final Color getColor() { 208 return color; 209 } 210 211 212 216 final Color getOutlineColor() { 217 return outlineColor; 218 } 219 220 221 225 final boolean getOutlineExistence() { 226 return outlineExistence; 227 } 228 229 230 235 final int getType() { 236 return type; 237 } 238 239 240 244 final Rectangle2D.Float getGraphBounds() { 245 return graphBounds; 246 } 247 248 252 final Vector getWarningRegions() { 253 return warningRegions; 254 } 255 256 257 261 final Paint getPaint() { 262 update(); 263 return paint; 264 } 265 266 267 272 final Paint getOutlinePaint() { 273 update(); 274 return outlinePaint; 275 } 276 277 278 282 final Vector getWarningPaints() { 283 update(); 284 return warningPaints; 285 } 286 287 288 292 final boolean getNeedsUpdate() { 293 return needsUpdate; 294 } 295 296 297 300 void update() { 302 if (getNeedsUpdate()) { 303 304 if (lightSource == TOP) { 305 paint = new GradientPaint (lightBounds.x, lightBounds.y, color.brighter(), 306 lightBounds.x, lightBounds.y + lightBounds.height, color); 307 if (outlineExistence) { 308 outlinePaint = new GradientPaint (lightBounds.x, lightBounds.y, outlineColor.brighter(), 309 lightBounds.x, lightBounds.y + lightBounds.height, outlineColor); 310 } 311 warningPaints.removeAllElements(); 312 if (warningRegions != null) { 313 for (int i = 0; i < warningRegions.size(); ++i) { 314 Color warningColor = ((WarningRegion)warningRegions.get(i)).getComponentColor(); 315 warningPaints.add ( 316 new GradientPaint (lightBounds.x, lightBounds.y, warningColor.brighter(), 317 lightBounds.x, lightBounds.y + lightBounds.height, warningColor)); 318 } 319 } 320 } 321 else if (lightSource == BOTTOM) { 322 paint = new GradientPaint (lightBounds.x, lightBounds.y, color, 323 lightBounds.x, lightBounds.y + lightBounds.height, color.brighter()); 324 if (outlineExistence) { 325 outlinePaint = new GradientPaint (lightBounds.x, lightBounds.y, outlineColor, 326 lightBounds.x, lightBounds.y + lightBounds.height, outlineColor.brighter()); 327 } 328 warningPaints.removeAllElements(); 329 for (int i = 0; i < warningRegions.size(); ++i) { 330 Color warningColor = ((WarningRegion)warningRegions.get(i)).getComponentColor(); 331 warningPaints.add ( 332 new GradientPaint (lightBounds.x, lightBounds.y, warningColor, 333 lightBounds.x, lightBounds.y + lightBounds.height, warningColor.brighter())); 334 } 335 } 336 else if (lightSource == LEFT) { 337 338 paint = new GradientPaint (lightBounds.x, lightBounds.y, color.brighter(), 339 lightBounds.x + lightBounds.width, lightBounds.y, color); 340 if (outlineExistence) { 341 outlinePaint = new GradientPaint (lightBounds.x, lightBounds.y, outlineColor.brighter(), 342 lightBounds.x + lightBounds.width, lightBounds.y, outlineColor); 343 } 344 warningPaints.removeAllElements(); 345 if (warningRegions != null) { 346 for (int i = 0; i < warningRegions.size(); ++i) { 347 Color warningColor = ((WarningRegion)warningRegions.get(i)).getComponentColor(); 348 warningPaints.add ( 349 new GradientPaint (lightBounds.x, lightBounds.y, warningColor.brighter(), 350 lightBounds.x + lightBounds.width, lightBounds.y, warningColor)); 351 } 352 } 353 } 354 else if (lightSource == RIGHT) { 355 paint = new GradientPaint (lightBounds.x, lightBounds.y, color, 356 lightBounds.x + lightBounds.width, lightBounds.y, color.brighter()); 357 if (outlineExistence) { 358 outlinePaint = new GradientPaint (lightBounds.x, lightBounds.y, outlineColor, 359 lightBounds.x + lightBounds.width, lightBounds.y, outlineColor.brighter()); 360 } 361 warningPaints.removeAllElements(); 362 if (warningRegions != null) { 363 for (int i = 0; i < warningRegions.size(); ++i) { 364 Color warningColor = ((WarningRegion)warningRegions.get(i)).getComponentColor(); 365 warningPaints.add ( 366 new GradientPaint (lightBounds.x, lightBounds.y, warningColor, 367 lightBounds.x + lightBounds.width, lightBounds.y, warningColor.brighter())); 368 } 369 } 370 } 371 else { 372 paint = color; 373 outlinePaint = outlineColor; 374 warningPaints.removeAllElements(); 375 if (warningRegions != null) { 376 for (int i = 0; i < warningRegions.size(); ++i) { 377 Color warningColor = ((WarningRegion)warningRegions.get(i)).getComponentColor(); 378 warningPaints.add (warningColor); 379 } 380 } 381 } 382 needsUpdate = false; 383 } 384 } 385 } | Popular Tags |