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 DesktopIconPainter extends AbstractRegionPainter { 18 static final int BACKGROUND_ENABLED = 1; 23 24 25 private int state; private PaintContext ctx; 27 28 private Path2D path = new Path2D.Float(); 30 private Rectangle2D rect = new Rectangle2D.Float(0, 0, 0, 0); 31 private RoundRectangle2D roundRect = new RoundRectangle2D.Float(0, 0, 0, 0, 0, 0); 32 private Ellipse2D ellipse = new Ellipse2D.Float(0, 0, 0, 0); 33 34 private Color color1 = decodeColor("nimbusBase", 0.02551502f, -0.47885156f, -0.34901965f, 0); 38 private Color color2 = decodeColor("nimbusBlueGrey", -0.027777791f, -0.102261856f, 0.20392156f, 0); 39 private Color color3 = decodeColor("nimbusBlueGrey", 0.0f, -0.0682728f, 0.09019607f, 0); 40 private Color color4 = decodeColor("nimbusBlueGrey", -0.01111114f, -0.088974595f, 0.16470587f, 0); 41 private Color color5 = decodeColor("nimbusBlueGrey", 0.0f, -0.029445238f, -0.019607842f, 0); 42 43 44 private Object [] componentColors; 46 47 public DesktopIconPainter(PaintContext ctx, int state) { 48 super(); 49 this.state = state; 50 this.ctx = ctx; 51 } 52 53 @Override 54 protected void doPaint(Graphics2D g, JComponent c, int width, int height, Object [] extendedCacheKeys) { 55 componentColors = extendedCacheKeys; 57 switch(state) { 60 case BACKGROUND_ENABLED: paintBackgroundEnabled(g); break; 61 62 } 63 } 64 65 66 67 @Override 68 protected final PaintContext getPaintContext() { 69 return ctx; 70 } 71 72 private void paintBackgroundEnabled(Graphics2D g) { 73 roundRect = decodeRoundRect1(); 74 g.setPaint(color1); 75 g.fill(roundRect); 76 roundRect = decodeRoundRect2(); 77 g.setPaint(decodeGradient1(roundRect)); 78 g.fill(roundRect); 79 rect = decodeRect1(); 80 g.setPaint(decodeGradient2(rect)); 81 g.fill(rect); 82 83 } 84 85 86 87 private RoundRectangle2D decodeRoundRect1() { 88 roundRect.setRoundRect(decodeX(0.4f), decodeY(0.0f), decodeX(2.8f) - decodeX(0.4f), decodeY(2.6f) - decodeY(0.0f), 4.8333335f, 4.8333335f); return roundRect; 94 } 95 96 private RoundRectangle2D decodeRoundRect2() { 97 roundRect.setRoundRect(decodeX(0.6f), decodeY(0.2f), decodeX(2.8f) - decodeX(0.6f), decodeY(2.4f) - decodeY(0.2f), 3.1f, 3.1f); return roundRect; 103 } 104 105 private Rectangle2D decodeRect1() { 106 rect.setRect(decodeX(0.8f), decodeY(0.4f), decodeX(2.4f) - decodeX(0.8f), decodeY(2.2f) - decodeY(0.4f)); return rect; 111 } 112 113 114 115 private Paint decodeGradient1(Shape s) { 116 Rectangle2D bounds = s.getBounds2D(); 117 float x = (float)bounds.getX(); 118 float y = (float)bounds.getY(); 119 float w = (float)bounds.getWidth(); 120 float h = (float)bounds.getHeight(); 121 return decodeGradient((0.5f * w) + x, (0.0f * h) + y, (0.5f * w) + x, (1.0f * h) + y, 122 new float[] { 0.0f,0.5f,1.0f }, 123 new Color[] { color2, 124 decodeColor(color2,color3,0.5f), 125 color3}); 126 } 127 128 private Paint decodeGradient2(Shape s) { 129 Rectangle2D bounds = s.getBounds2D(); 130 float x = (float)bounds.getX(); 131 float y = (float)bounds.getY(); 132 float w = (float)bounds.getWidth(); 133 float h = (float)bounds.getHeight(); 134 return decodeGradient((0.5f * w) + x, (0.0f * h) + y, (0.5f * w) + x, (1.0f * h) + y, 135 new float[] { 0.0f,0.24f,1.0f }, 136 new Color[] { color4, 137 decodeColor(color4,color5,0.5f), 138 color5}); 139 } 140 141 142 } 143 | Popular Tags |