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 36 final class FancyBar extends FancyShape { 37 38 39 private Rectangle2D.Float bounds, clipBounds; 40 private float arcw, arch; 41 private RoundRectangle2D.Float bar; 42 private FancyBar[] warningBars; 43 private int dataSign, baseValue; 44 private boolean needsUpdate; 45 46 47 51 FancyBar() { 52 needsUpdate = true; 53 } 54 55 56 60 final void setBaseValue (int value) { 61 baseValue = value; 62 needsUpdate = true; 63 } 64 65 66 70 final int getBaseValue() { 71 return baseValue; 72 } 73 74 75 83 final void setDataSign (int sign) { 84 85 dataSign = sign; 86 needsUpdate = true; 87 } 88 89 90 98 final int getDataSign() { 99 return dataSign; 100 } 101 102 103 107 final void setBounds (Rectangle2D.Float b) { 108 bounds = b; 109 needsUpdate = true; 110 } 111 112 113 117 final void setClipBounds (Rectangle2D.Float b) { 118 clipBounds = b; 119 needsUpdate = true; 120 } 121 122 123 127 final void setArcw (float w) { 128 arcw = w; 129 needsUpdate = true; 130 } 131 132 133 137 final void setArch (float h) { 138 arch = h; 139 needsUpdate = true; 140 } 141 142 143 147 final Rectangle2D.Float getBounds() { 148 return bounds; 149 } 150 151 152 156 final Rectangle2D.Float getClipBounds() { 157 return clipBounds; 158 } 159 160 161 165 final float getArcw() { 166 return arcw; 167 } 168 169 170 174 final float getArch() { 175 return arch; 176 } 177 178 179 183 final void paint (Graphics2D g2D) { 184 185 update(); 186 187 Paint oldPaint = g2D.getPaint(); 188 g2D.setPaint (getPaint()); 189 190 Shape oldClip = g2D.getClip(); 191 java.awt.geom.Area clipArea = new java.awt.geom.Area (clipBounds); 192 clipArea.intersect (new java.awt.geom.Area (oldClip)); 193 g2D.setClip (clipArea); 194 195 g2D.fill (bar); 196 197 if (getOutlineExistence() && bounds.width > 2f && bounds.height > 2f) { 198 199 g2D.setPaint (getOutlinePaint()); 200 g2D.draw (bar); 201 } 202 203 g2D.setPaint (oldPaint); 204 g2D.setClip (oldClip); 205 206 if (getWarningRegions() != null) { 207 for (int i = 0; i < warningBars.length; ++i) warningBars[i].paint (g2D); 208 } 209 } 210 211 212 215 final void update() { 216 217 super.update(); 218 219 if (needsUpdate) { 220 221 if (getType() == LABELSLEFT) { 222 223 if (dataSign == GraphArea.POS) { 224 bar = new RoundRectangle2D.Float ( 225 bounds.x - (arcw / 2f), bounds.y, 226 bounds.width + (arcw / 2f), bounds.height, arcw, arch); 227 } 228 else if (dataSign == GraphArea.NEG) { 229 bar = new RoundRectangle2D.Float ( 230 bounds.x, bounds.y, 231 bounds.width + (arcw / 2f), bounds.height, arcw, arch); 232 } 233 else { 234 235 if (bounds.x >= baseValue) { 236 bar = new RoundRectangle2D.Float ( 237 bounds.x - (arcw / 2f), bounds.y, 238 bounds.width + (arcw / 2f), bounds.height, arcw, arch); 239 } 240 else { 241 bar = new RoundRectangle2D.Float ( 242 bounds.x, bounds.y, 243 bounds.width + (arcw / 2f), bounds.height, arcw, arch); 244 } 245 } 246 } 247 else { 249 if (dataSign == GraphArea.POS) { 250 bar = new RoundRectangle2D.Float ( 251 bounds.x, bounds.y, 252 bounds.width, bounds.height + (arch / 2f), arcw, arch); 253 } 254 else if (dataSign == GraphArea.NEG) { 255 bar = new RoundRectangle2D.Float ( 256 bounds.x, bounds.y - (arch / 2f), 257 bounds.width, bounds.height + (arch / 2f), arcw, arch); 258 } 259 else { 260 261 if (baseValue <= bounds.y) { 262 bar = new RoundRectangle2D.Float ( 263 bounds.x, bounds.y - (arch / 2f), 264 bounds.width, bounds.height + (arch / 2f), arcw, arch); 265 } 266 else { 267 bar = new RoundRectangle2D.Float ( 268 bounds.x, bounds.y, bounds.width, bounds.height + (arch / 2f), arcw, arch); 269 } 270 } 271 } 272 273 if (getWarningRegions() != null) { 274 275 warningBars = new FancyBar[getWarningRegions().size()]; 276 for (int i = 0; i < warningBars.length; ++i) { 277 278 FancyBar warningBar = new FancyBar(); 279 warningBar.setBounds (bounds); 280 warningBar.setArcw (arcw); 281 warningBar.setArch (arch); 282 warningBar.setDataSign (dataSign); 283 warningBar.setBaseValue (baseValue); 284 warningBar.setWarningRegions (null); 285 warningBar.setLightBounds (getLightBounds()); 286 warningBar.setLightSource (getLightSource()); 287 warningBar.setOutlineExistence (getOutlineExistence()); 288 warningBar.setOutlineColor (getOutlineColor()); 289 warningBar.setType (getType()); 290 warningBar.setGraphBounds (getGraphBounds()); 291 WarningRegion warningRegion = (WarningRegion)getWarningRegions().get (i); 292 Rectangle2D tempRect2D = bounds.createIntersection (warningRegion.getBackgroundBounds()); 293 Rectangle2D.Float clipBoundsWR = new Rectangle2D.Float(); 294 clipBoundsWR.setRect (tempRect2D); 295 warningBar.setClipBounds (clipBoundsWR); 296 warningBar.setColor (warningRegion.getComponentColor()); 297 warningBars[i] = warningBar; 298 } 299 } 300 needsUpdate = false; 301 } 302 } 303 } | Popular Tags |