1 7 package com.sun.java.swing.plaf.nimbus; 8 9 import java.awt.*; 10 import java.awt.geom.*; 11 import java.awt.image.*; 12 import javax.swing.*; 13 import com.sun.java.swing.Painter; 14 15 17 public final class ScrollBarScrollBarThumbPainter extends AbstractRegionPainter { 18 static final int BACKGROUND_DISABLED = 1; 23 static final int BACKGROUND_ENABLED = 2; 24 static final int BACKGROUND_FOCUSED = 3; 25 static final int BACKGROUND_MOUSEOVER = 4; 26 static final int BACKGROUND_PRESSED = 5; 27 28 29 private int state; private PaintContext ctx; 31 32 private Path2D path = new Path2D.Float(); 34 private Rectangle2D rect = new Rectangle2D.Float(0, 0, 0, 0); 35 private RoundRectangle2D roundRect = new RoundRectangle2D.Float(0, 0, 0, 0, 0, 0); 36 private Ellipse2D ellipse = new Ellipse2D.Float(0, 0, 0, 0); 37 38 private Color color1 = decodeColor("nimbusBase", 5.1498413E-4f, 0.18061227f, -0.35686278f, 0); 42 private Color color2 = decodeColor("nimbusBase", 5.1498413E-4f, -0.21018237f, -0.18039218f, 0); 43 private Color color3 = decodeColor("nimbusBase", 7.13408E-4f, -0.53277314f, 0.25098038f, 0); 44 private Color color4 = decodeColor("nimbusBase", -0.07865167f, -0.6317617f, 0.44313723f, 0); 45 private Color color5 = decodeColor("nimbusBase", 5.1498413E-4f, -0.44340658f, 0.26666665f, 0); 46 private Color color6 = decodeColor("nimbusBase", 5.1498413E-4f, -0.4669379f, 0.38039213f, 0); 47 private Color color7 = decodeColor("nimbusBase", -0.07865167f, -0.56512606f, 0.45098037f, 0); 48 private Color color8 = decodeColor("nimbusBase", -0.0017285943f, -0.362987f, 0.011764705f, 0); 49 private Color color9 = decodeColor("nimbusBase", 5.2034855E-5f, -0.41753247f, 0.09803921f, -222); 50 private Color color10 = new Color(255, 200, 0, 255); 51 private Color color11 = decodeColor("nimbusBase", -0.0017285943f, -0.362987f, 0.011764705f, -255); 52 private Color color12 = decodeColor("nimbusBase", 0.010237217f, -0.5621849f, 0.25098038f, 0); 53 private Color color13 = decodeColor("nimbusBase", 0.08801502f, -0.6317773f, 0.4470588f, 0); 54 private Color color14 = decodeColor("nimbusBase", 5.1498413E-4f, -0.45950285f, 0.34117645f, 0); 55 private Color color15 = decodeColor("nimbusBase", -0.0017285943f, -0.48277313f, 0.45098037f, 0); 56 private Color color16 = decodeColor("nimbusBase", 0.0f, -0.6357143f, 0.45098037f, 0); 57 private Color color17 = decodeColor("nimbusBase", -0.57865167f, -0.6357143f, -0.54901963f, 0); 58 private Color color18 = decodeColor("nimbusBase", 0.0013483167f, 0.29021162f, -0.33725494f, 0); 59 private Color color19 = decodeColor("nimbusBase", 0.002908647f, -0.29012606f, -0.015686274f, 0); 60 private Color color20 = decodeColor("nimbusBase", -8.738637E-4f, -0.40612245f, 0.21960783f, 0); 61 private Color color21 = decodeColor("nimbusBase", 0.0f, -0.01765871f, 0.015686274f, 0); 62 private Color color22 = decodeColor("nimbusBase", 0.0f, -0.12714285f, 0.1372549f, 0); 63 private Color color23 = decodeColor("nimbusBase", 0.0018727183f, -0.23116884f, 0.31372547f, 0); 64 private Color color24 = decodeColor("nimbusBase", -8.738637E-4f, -0.3579365f, -0.33725494f, 0); 65 private Color color25 = decodeColor("nimbusBase", 0.004681647f, -0.3857143f, -0.36078435f, 0); 66 67 68 private Object [] componentColors; 70 71 public ScrollBarScrollBarThumbPainter(PaintContext ctx, int state) { 72 super(); 73 this.state = state; 74 this.ctx = ctx; 75 } 76 77 @Override 78 protected void doPaint(Graphics2D g, JComponent c, int width, int height, Object [] extendedCacheKeys) { 79 componentColors = extendedCacheKeys; 81 switch(state) { 84 case BACKGROUND_ENABLED: paintBackgroundEnabled(g); break; 85 case BACKGROUND_MOUSEOVER: paintBackgroundMouseOver(g); break; 86 case BACKGROUND_PRESSED: paintBackgroundPressed(g); break; 87 88 } 89 } 90 91 92 93 @Override 94 protected final PaintContext getPaintContext() { 95 return ctx; 96 } 97 98 private void paintBackgroundEnabled(Graphics2D g) { 99 path = decodePath1(); 100 g.setPaint(decodeGradient1(path)); 101 g.fill(path); 102 path = decodePath2(); 103 g.setPaint(decodeGradient2(path)); 104 g.fill(path); 105 path = decodePath3(); 106 g.setPaint(decodeGradient3(path)); 107 g.fill(path); 108 path = decodePath4(); 109 g.setPaint(color10); 110 g.fill(path); 111 path = decodePath5(); 112 g.setPaint(decodeGradient4(path)); 113 g.fill(path); 114 115 } 116 117 private void paintBackgroundMouseOver(Graphics2D g) { 118 path = decodePath1(); 119 g.setPaint(decodeGradient1(path)); 120 g.fill(path); 121 path = decodePath2(); 122 g.setPaint(decodeGradient5(path)); 123 g.fill(path); 124 path = decodePath3(); 125 g.setPaint(decodeGradient3(path)); 126 g.fill(path); 127 path = decodePath4(); 128 g.setPaint(color10); 129 g.fill(path); 130 path = decodePath5(); 131 g.setPaint(decodeGradient4(path)); 132 g.fill(path); 133 134 } 135 136 private void paintBackgroundPressed(Graphics2D g) { 137 path = decodePath1(); 138 g.setPaint(decodeGradient6(path)); 139 g.fill(path); 140 path = decodePath2(); 141 g.setPaint(decodeGradient7(path)); 142 g.fill(path); 143 path = decodePath3(); 144 g.setPaint(decodeGradient8(path)); 145 g.fill(path); 146 path = decodePath4(); 147 g.setPaint(color10); 148 g.fill(path); 149 path = decodePath6(); 150 g.setPaint(decodeGradient9(path)); 151 g.fill(path); 152 153 } 154 155 156 157 private Path2D decodePath1() { 158 path.reset(); 159 path.moveTo(decodeX(0.0f), decodeY(1.0f)); 160 path.lineTo(decodeX(0.0f), decodeY(1.0666667f)); 161 path.curveTo(decodeAnchorX(0.0f, 0.0f), decodeAnchorY(1.0666667222976685f, 6.0f), decodeAnchorX(1.0f, -10.0f), decodeAnchorY(2.0f, 0.0f), decodeX(1.0f), decodeY(2.0f)); 162 path.lineTo(decodeX(2.0f), decodeY(2.0f)); 163 path.curveTo(decodeAnchorX(2.0f, 10.0f), decodeAnchorY(2.0f, 0.0f), decodeAnchorX(3.0f, 0.0f), decodeAnchorY(1.0666667222976685f, 6.0f), decodeX(3.0f), decodeY(1.0666667f)); 164 path.lineTo(decodeX(3.0f), decodeY(1.0f)); 165 path.lineTo(decodeX(0.0f), decodeY(1.0f)); 166 path.closePath(); 167 return path; 168 } 169 170 private Path2D decodePath2() { 171 path.reset(); 172 path.moveTo(decodeX(0.06666667f), decodeY(1.0f)); 173 path.lineTo(decodeX(0.06666667f), decodeY(1.0666667f)); 174 path.curveTo(decodeAnchorX(0.06666667014360428f, -0.045454545454545414f), decodeAnchorY(1.0666667222976685f, 8.45454545454545f), decodeAnchorX(1.0f, -5.863636363636354f), decodeAnchorY(1.933333396911621f, 0.0f), decodeX(1.0f), decodeY(1.9333334f)); 175 path.lineTo(decodeX(2.0f), decodeY(1.9333334f)); 176 path.curveTo(decodeAnchorX(2.0f, 5.909090909090935f), decodeAnchorY(1.933333396911621f, -3.552713678800501E-15f), decodeAnchorX(2.933333396911621f, -0.045454545454546746f), decodeAnchorY(1.0666667222976685f, 8.36363636363636f), decodeX(2.9333334f), decodeY(1.0666667f)); 177 path.lineTo(decodeX(2.9333334f), decodeY(1.0f)); 178 path.lineTo(decodeX(0.06666667f), decodeY(1.0f)); 179 path.closePath(); 180 return path; 181 } 182 183 private Path2D decodePath3() { 184 path.reset(); 185 path.moveTo(decodeX(0.4f), decodeY(1.0f)); 186 path.lineTo(decodeX(0.06666667f), decodeY(1.0f)); 187 path.lineTo(decodeX(0.16060607f), decodeY(1.5090909f)); 188 path.curveTo(decodeAnchorX(0.16060607135295868f, 0.0f), decodeAnchorY(1.5090909004211426f, 0.0f), decodeAnchorX(0.20000000298023224f, -0.9545454545454564f), decodeAnchorY(1.1363636255264282f, 1.5454545454545472f), decodeX(0.2f), decodeY(1.1363636f)); 189 path.curveTo(decodeAnchorX(0.20000000298023224f, 0.9545454545454564f), decodeAnchorY(1.1363636255264282f, -1.5454545454545472f), decodeAnchorX(0.4000000059604645f, 0.0f), decodeAnchorY(1.0f, 0.0f), decodeX(0.4f), decodeY(1.0f)); 190 path.closePath(); 191 return path; 192 } 193 194 private Path2D decodePath4() { 195 path.reset(); 196 path.moveTo(decodeX(2.4242425f), decodeY(1.5121212f)); 197 path.lineTo(decodeX(2.4242425f), decodeY(1.5121212f)); 198 path.closePath(); 199 return path; 200 } 201 202 private Path2D decodePath5() { 203 path.reset(); 204 path.moveTo(decodeX(2.9363637f), decodeY(1.0f)); 205 path.lineTo(decodeX(2.6030304f), decodeY(1.0f)); 206 path.curveTo(decodeAnchorX(2.6030304431915283f, 0.0f), decodeAnchorY(1.0f, 0.0f), decodeAnchorX(2.7787880897521973f, -0.6818181818181728f), decodeAnchorY(1.1333333253860474f, -1.227272727272727f), decodeX(2.778788f), decodeY(1.1333333f)); 207 path.curveTo(decodeAnchorX(2.7787880897521973f, 0.6818181818181728f), decodeAnchorY(1.1333333253860474f, 1.227272727272727f), decodeAnchorX(2.8393938541412354f, 0.0f), decodeAnchorY(1.5060606002807617f, 0.0f), decodeX(2.8393939f), decodeY(1.5060606f)); 208 path.lineTo(decodeX(2.9363637f), decodeY(1.0f)); 209 path.closePath(); 210 return path; 211 } 212 213 private Path2D decodePath6() { 214 path.reset(); 215 path.moveTo(decodeX(2.9363637f), decodeY(1.0f)); 216 path.lineTo(decodeX(2.5563636f), decodeY(1.0f)); 217 path.curveTo(decodeAnchorX(2.556363582611084f, 0.0f), decodeAnchorY(1.0f, 0.0f), decodeAnchorX(2.7587878704071045f, -0.6818181818181728f), decodeAnchorY(1.1399999856948853f, -1.2272727272727266f), decodeX(2.7587879f), decodeY(1.14f)); 218 path.curveTo(decodeAnchorX(2.7587878704071045f, 0.6818181818181728f), decodeAnchorY(1.1399999856948853f, 1.227272727272727f), decodeAnchorX(2.8393938541412354f, 0.0f), decodeAnchorY(1.5060606002807617f, 0.0f), decodeX(2.8393939f), decodeY(1.5060606f)); 219 path.lineTo(decodeX(2.9363637f), decodeY(1.0f)); 220 path.closePath(); 221 return path; 222 } 223 224 225 226 private Paint decodeGradient1(Shape s) { 227 Rectangle2D bounds = s.getBounds2D(); 228 float x = (float)bounds.getX(); 229 float y = (float)bounds.getY(); 230 float w = (float)bounds.getWidth(); 231 float h = (float)bounds.getHeight(); 232 return decodeGradient((0.5f * w) + x, (0.0f * h) + y, (0.5f * w) + x, (1.0f * h) + y, 233 new float[] { 0.0f,0.5f,1.0f }, 234 new Color[] { color1, 235 decodeColor(color1,color2,0.5f), 236 color2}); 237 } 238 239 private Paint decodeGradient2(Shape s) { 240 Rectangle2D bounds = s.getBounds2D(); 241 float x = (float)bounds.getX(); 242 float y = (float)bounds.getY(); 243 float w = (float)bounds.getWidth(); 244 float h = (float)bounds.getHeight(); 245 return decodeGradient((0.5f * w) + x, (0.0f * h) + y, (0.5f * w) + x, (1.0f * h) + y, 246 new float[] { 0.038922157f,0.0508982f,0.06287425f,0.19610777f,0.32934132f,0.48952097f,0.6497006f,0.8248503f,1.0f }, 247 new Color[] { color3, 248 decodeColor(color3,color4,0.5f), 249 color4, 250 decodeColor(color4,color5,0.5f), 251 color5, 252 decodeColor(color5,color6,0.5f), 253 color6, 254 decodeColor(color6,color7,0.5f), 255 color7}); 256 } 257 258 private Paint decodeGradient3(Shape s) { 259 Rectangle2D bounds = s.getBounds2D(); 260 float x = (float)bounds.getX(); 261 float y = (float)bounds.getY(); 262 float w = (float)bounds.getWidth(); 263 float h = (float)bounds.getHeight(); 264 return decodeGradient((0.06818182f * w) + x, (-0.005952381f * h) + y, (0.3689091f * w) + x, (0.23929171f * h) + y, 265 new float[] { 0.0f,0.5f,1.0f }, 266 new Color[] { color8, 267 decodeColor(color8,color9,0.5f), 268 color9}); 269 } 270 271 private Paint decodeGradient4(Shape s) { 272 Rectangle2D bounds = s.getBounds2D(); 273 float x = (float)bounds.getX(); 274 float y = (float)bounds.getY(); 275 float w = (float)bounds.getWidth(); 276 float h = (float)bounds.getHeight(); 277 return decodeGradient((0.9409091f * w) + x, (0.035928145f * h) + y, (0.5954546f * w) + x, (0.26347303f * h) + y, 278 new float[] { 0.0f,0.5f,1.0f }, 279 new Color[] { color8, 280 decodeColor(color8,color11,0.5f), 281 color11}); 282 } 283 284 private Paint decodeGradient5(Shape s) { 285 Rectangle2D bounds = s.getBounds2D(); 286 float x = (float)bounds.getX(); 287 float y = (float)bounds.getY(); 288 float w = (float)bounds.getWidth(); 289 float h = (float)bounds.getHeight(); 290 return decodeGradient((0.5f * w) + x, (0.0f * h) + y, (0.5f * w) + x, (1.0f * h) + y, 291 new float[] { 0.038922157f,0.0508982f,0.06287425f,0.19610777f,0.32934132f,0.48952097f,0.6497006f,0.8248503f,1.0f }, 292 new Color[] { color12, 293 decodeColor(color12,color13,0.5f), 294 color13, 295 decodeColor(color13,color14,0.5f), 296 color14, 297 decodeColor(color14,color15,0.5f), 298 color15, 299 decodeColor(color15,color16,0.5f), 300 color16}); 301 } 302 303 private Paint decodeGradient6(Shape s) { 304 Rectangle2D bounds = s.getBounds2D(); 305 float x = (float)bounds.getX(); 306 float y = (float)bounds.getY(); 307 float w = (float)bounds.getWidth(); 308 float h = (float)bounds.getHeight(); 309 return decodeGradient((0.5f * w) + x, (0.0f * h) + y, (0.5f * w) + x, (1.0f * h) + y, 310 new float[] { 0.0f,0.5f,1.0f }, 311 new Color[] { color17, 312 decodeColor(color17,color18,0.5f), 313 color18}); 314 } 315 316 private Paint decodeGradient7(Shape s) { 317 Rectangle2D bounds = s.getBounds2D(); 318 float x = (float)bounds.getX(); 319 float y = (float)bounds.getY(); 320 float w = (float)bounds.getWidth(); 321 float h = (float)bounds.getHeight(); 322 return decodeGradient((0.5f * w) + x, (0.0f * h) + y, (0.5f * w) + x, (1.0f * h) + y, 323 new float[] { 0.038922157f,0.0508982f,0.06287425f,0.19610777f,0.32934132f,0.48952097f,0.6497006f,0.8248503f,1.0f }, 324 new Color[] { color19, 325 decodeColor(color19,color20,0.5f), 326 color20, 327 decodeColor(color20,color21,0.5f), 328 color21, 329 decodeColor(color21,color22,0.5f), 330 color22, 331 decodeColor(color22,color23,0.5f), 332 color23}); 333 } 334 335 private Paint decodeGradient8(Shape s) { 336 Rectangle2D bounds = s.getBounds2D(); 337 float x = (float)bounds.getX(); 338 float y = (float)bounds.getY(); 339 float w = (float)bounds.getWidth(); 340 float h = (float)bounds.getHeight(); 341 return decodeGradient((0.06818182f * w) + x, (-0.005952381f * h) + y, (0.3689091f * w) + x, (0.23929171f * h) + y, 342 new float[] { 0.0f,0.5f,1.0f }, 343 new Color[] { color24, 344 decodeColor(color24,color9,0.5f), 345 color9}); 346 } 347 348 private Paint decodeGradient9(Shape s) { 349 Rectangle2D bounds = s.getBounds2D(); 350 float x = (float)bounds.getX(); 351 float y = (float)bounds.getY(); 352 float w = (float)bounds.getWidth(); 353 float h = (float)bounds.getHeight(); 354 return decodeGradient((0.9409091f * w) + x, (0.035928145f * h) + y, (0.37615633f * w) + x, (0.34910178f * h) + y, 355 new float[] { 0.0f,0.5f,1.0f }, 356 new Color[] { color25, 357 decodeColor(color25,color11,0.5f), 358 color11}); 359 } 360 361 362 } 363 | Popular Tags |