1 22 23 24 package net.sourceforge.chart2d; 25 26 27 import java.awt.*; 28 import java.util.*; 29 30 31 37 final public class WarningRegionProperties { 38 39 40 45 public static final float HIGH = Float.POSITIVE_INFINITY; 46 47 48 53 public static final float LOW = Float.NEGATIVE_INFINITY; 54 55 56 59 public static final float HIGH_DEFAULT = HIGH; 60 61 62 65 public static final float LOW_DEFAULT = LOW; 66 67 68 71 public static final Color COMPONENT_COLOR_DEFAULT = new Color (146, 0, 10); 72 73 76 public static final boolean BACKGROUND_EXISTENCE_DEFAULT = true; 77 78 81 public static final Color BACKGROUND_COLOR_DEFAULT = new Color (222, 177, 180); 82 83 84 private float high; 85 private float low; 86 private Color componentColor; 87 private boolean backgroundExistence; 88 private Color backgroundColor; 89 90 private boolean needsUpdate = true; 91 private final Vector needsUpdateVector = new Vector (5, 5); 92 private final Vector graphChart2DVector = new Vector (5, 5); 93 94 95 98 public WarningRegionProperties() { 99 100 needsUpdate = true; 101 setToDefaults(); 102 } 103 104 105 110 public WarningRegionProperties (WarningRegionProperties warningRegionProps) { 111 112 needsUpdate = true; 113 setWarningRegionProperties (warningRegionProps); 114 } 115 116 117 120 public final void setToDefaults() { 121 122 needsUpdate = true; 123 setHigh (HIGH_DEFAULT); 124 setLow (LOW_DEFAULT); 125 setComponentColor (COMPONENT_COLOR_DEFAULT); 126 setBackgroundExistence (BACKGROUND_EXISTENCE_DEFAULT); 127 setBackgroundColor (BACKGROUND_COLOR_DEFAULT); 128 } 129 130 131 136 public final void setWarningRegionProperties (WarningRegionProperties warningRegionProps) { 137 138 needsUpdate = true; 139 setHigh (warningRegionProps.getHigh()); 140 setLow (warningRegionProps.getLow()); 141 setComponentColor (warningRegionProps.getComponentColor()); 142 setBackgroundExistence (warningRegionProps.getBackgroundExistence()); 143 setBackgroundColor (warningRegionProps.getBackgroundColor()); 144 } 145 146 147 153 public final void setHigh (float h) { 154 155 high = h; 156 needsUpdate = true; 157 } 158 159 160 166 public final void setLow (float l) { 167 168 low = l; 169 needsUpdate = true; 170 } 171 172 173 179 public final void setComponentColor (Color c) { 180 181 componentColor = c; 182 needsUpdate = true; 183 } 184 185 186 190 public final void setBackgroundExistence (boolean existence) { 191 192 backgroundExistence = existence; 193 needsUpdate = true; 194 } 195 196 197 201 public final void setBackgroundColor (Color c) { 202 203 backgroundColor = c; 204 needsUpdate = true; 205 } 206 207 208 214 public final float getHigh() { 215 return high; 216 } 217 218 219 225 public final float getLow() { 226 return low; 227 } 228 229 230 236 public final Color getComponentColor() { 237 return componentColor; 238 } 239 240 241 245 public final boolean getBackgroundExistence() { 246 return backgroundExistence; 247 } 248 249 250 254 public final Color getBackgroundColor() { 255 return backgroundColor; 256 } 257 258 259 264 final boolean getGraphChart2DNeedsUpdate (GraphChart2D graphChart2D) { 265 266 if (needsUpdate) return true; 267 int index = -1; 268 if ((index = graphChart2DVector.indexOf (graphChart2D)) != -1) { 269 return ((Boolean )needsUpdateVector.get (index)).booleanValue(); 270 } 271 return false; 272 } 273 274 275 279 final void addGraphChart2D (GraphChart2D graphChart2D) { 280 281 if (!graphChart2DVector.contains (graphChart2D)) { 282 graphChart2DVector.add (graphChart2D); 283 needsUpdateVector.add (new Boolean (true)); 284 } } 285 286 287 291 final void removeGraphChart2D (GraphChart2D graphChart2D) { 292 293 int index = -1; 294 if ((index = graphChart2DVector.indexOf (graphChart2D)) != -1) { 295 graphChart2DVector.remove (index); 296 needsUpdateVector.remove (index); 297 } } 298 299 300 307 final boolean validate (boolean debug) { 308 309 if (debug) System.out.println ("Validating WarningRegionProperties"); 310 311 boolean valid = true; 312 313 if ((high != HIGH && (low == HIGH || high < low)) || 314 (low != LOW && (high == LOW || high < low))) { 315 valid = false; 316 if (debug) System.out.println ("High was lower than low"); 317 } 318 if (componentColor == null) { 319 valid = false; 320 if (debug) System.out.println ("ComponentColor == null"); 321 } 322 if (backgroundColor == null) { 323 valid = false; 324 if (debug) System.out.println ("BackgroundColor == null"); 325 } 326 327 if (debug) { 328 if (valid) System.out.println ("WarningRegionProperties was valid"); 329 else System.out.println ("WarningRegionProperties was invalid"); 330 } 331 332 return valid; 333 } 334 335 336 340 final void updateGraphChart2D (GraphChart2D graphChart2D) { 341 342 if (getGraphChart2DNeedsUpdate (graphChart2D)) { 343 344 if (needsUpdate) { 345 for (int i = 0; i < needsUpdateVector.size(); ++i) { 346 needsUpdateVector.set (i, new Boolean (true)); 347 } 348 needsUpdate = false; 349 } 350 351 int index = -1; 352 if ((index = graphChart2DVector.indexOf (graphChart2D)) != -1) { 353 needsUpdateVector.set (index, new Boolean (false)); 354 } 355 } 356 } 357 358 359 363 final WarningRegion configureWarningRegion() { 364 365 WarningRegion warningRegion = new WarningRegion(); 366 warningRegion.setHigh (getHigh()); 367 warningRegion.setLow (getLow()); 368 warningRegion.setComponentColor (getComponentColor()); 369 warningRegion.setBackgroundExistence (getBackgroundExistence()); 370 warningRegion.setBackgroundColor (getBackgroundColor()); 371 return warningRegion; 372 } 373 } | Popular Tags |