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 final class FancyLine extends FancyShape { 36 37 38 private GeneralPath line; 39 private BasicStroke stroke; 40 private BasicStroke outlineStroke; 41 private float thickness; 42 private boolean fillArea; 43 private Rectangle2D.Float clipBounds; 44 private FancyLine[] warningLines; 45 private boolean needsUpdate; 46 47 48 51 FancyLine() { 52 needsUpdate = true; 53 line = new GeneralPath (GeneralPath.WIND_EVEN_ODD); 54 } 55 56 57 61 final void setThickness (float t) { 62 thickness = t; 63 needsUpdate = true; 64 } 65 66 67 71 final void setFillArea (boolean f) { 72 fillArea = f; 73 } 74 75 76 80 final void setLine (GeneralPath l) { 81 needsUpdate = true; 82 line = l; 83 } 84 85 86 90 final void setClipBounds (Rectangle2D.Float b) { 91 needsUpdate = true; 92 clipBounds = b; 93 } 94 95 96 100 final float getThickness() { 101 return thickness; 102 } 103 104 105 109 final boolean getFillArea() { 110 return fillArea; 111 } 112 113 114 118 final GeneralPath getLine() { 119 return line; 120 } 121 122 123 127 final Rectangle2D.Float getClipBounds() { 128 return clipBounds; 129 } 130 131 132 136 final void paint (Graphics2D g2D) { 137 138 update(); 139 140 Stroke oldStroke = g2D.getStroke(); 141 Paint oldPaint = g2D.getPaint(); 142 Shape oldClip = g2D.getClip(); 143 144 java.awt.geom.Area clipArea = new java.awt.geom.Area (clipBounds); 145 clipArea.intersect (new java.awt.geom.Area (oldClip)); 146 g2D.setClip (clipArea); 147 148 if (getOutlineExistence() && thickness > 2f) { 149 g2D.setStroke (outlineStroke); 150 g2D.setPaint (getOutlinePaint()); 151 g2D.draw (line); 152 } 153 154 g2D.setPaint (getPaint()); 155 g2D.setStroke (stroke); 156 if (fillArea) g2D.fill (line); 157 else g2D.draw (line); 158 159 g2D.setPaint (oldPaint); 160 g2D.setClip (oldClip); 161 g2D.setStroke(oldStroke); 162 163 if (warningLines != null) { 164 for (int i = 0; i < warningLines.length; ++i) warningLines[i].paint (g2D); 165 } 166 } 167 168 169 172 final void update() { 173 174 super.update(); 175 176 if (needsUpdate) { 177 178 outlineStroke = new BasicStroke ((float)thickness, 179 BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 10.0f, Area.CONTINUOUS, 0.0f); 180 float tempThickness = thickness > 2f && getOutlineExistence() ? thickness - 2f : thickness; 181 stroke = new BasicStroke ((float)tempThickness, 182 BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 10.0f, Area.CONTINUOUS, 0.0f); 183 184 if (getWarningRegions() != null) { 185 186 warningLines = new FancyLine[getWarningRegions().size()]; 187 for (int i = 0; i < warningLines.length; ++i) { 188 189 FancyLine warningLine = new FancyLine(); 190 191 WarningRegion warningRegion = (WarningRegion)getWarningRegions().get(i); 192 java.awt.geom.Area clipArea = new java.awt.geom.Area (clipBounds); 193 java.awt.geom.Area wrArea = 194 new java.awt.geom.Area (warningRegion.getBackgroundBounds()); 195 clipArea.intersect (wrArea); 196 Rectangle2D.Float wrClipBounds = new Rectangle2D.Float(); 197 wrClipBounds.setRect (clipArea.getBounds2D()); 198 warningLine.setClipBounds (wrClipBounds); 199 warningLine.setFillArea (getFillArea()); 200 warningLine.setThickness (getThickness()); 201 warningLine.setColor (warningRegion.getComponentColor()); 202 warningLine.setLightBounds (getLightBounds()); 203 warningLine.setLightSource (getLightSource()); 204 warningLine.setOutlineColor (getOutlineColor()); 205 warningLine.setOutlineExistence (getOutlineExistence()); 206 warningLine.setType (getType()); 207 warningLine.setWarningRegions (null); 208 warningLine.setLine (line); 209 warningLines[i] = warningLine; 210 } 211 } 212 needsUpdate = false; 213 } 214 } 215 } | Popular Tags |