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 SliderSliderTrackPainter extends AbstractRegionPainter { 18 static final int BACKGROUND_DISABLED = 1; 23 static final int BACKGROUND_ENABLED = 2; 24 25 26 private int state; private PaintContext ctx; 28 29 private Path2D path = new Path2D.Float(); 31 private Rectangle2D rect = new Rectangle2D.Float(0, 0, 0, 0); 32 private RoundRectangle2D roundRect = new RoundRectangle2D.Float(0, 0, 0, 0, 0, 0); 33 private Ellipse2D ellipse = new Ellipse2D.Float(0, 0, 0, 0); 34 35 private Color color1 = decodeColor("nimbusBlueGrey", 0.0f, -0.110526316f, 0.25490195f, -245); 39 private Color color2 = decodeColor("nimbusBlueGrey", 0.0055555105f, -0.061265234f, 0.05098039f, 0); 40 private Color color3 = decodeColor("nimbusBlueGrey", 0.01010108f, -0.059835073f, 0.10588235f, 0); 41 private Color color4 = decodeColor("nimbusBlueGrey", -0.01111114f, -0.061982628f, 0.062745094f, 0); 42 private Color color5 = decodeColor("nimbusBlueGrey", -0.00505054f, -0.058639523f, 0.086274505f, 0); 43 private Color color6 = decodeColor("nimbusBlueGrey", 0.0f, -0.110526316f, 0.25490195f, -111); 44 private Color color7 = decodeColor("nimbusBlueGrey", 0.0f, -0.034093194f, -0.12941176f, 0); 45 private Color color8 = decodeColor("nimbusBlueGrey", 0.01111114f, -0.023821115f, -0.06666666f, 0); 46 private Color color9 = decodeColor("nimbusBlueGrey", -0.008547008f, -0.03314536f, -0.086274505f, 0); 47 private Color color10 = decodeColor("nimbusBlueGrey", 0.004273474f, -0.040256046f, -0.019607842f, 0); 48 private Color color11 = decodeColor("nimbusBlueGrey", 0.0f, -0.03626889f, 0.04705882f, 0); 49 50 51 private Object [] componentColors; 53 54 public SliderSliderTrackPainter(PaintContext ctx, int state) { 55 super(); 56 this.state = state; 57 this.ctx = ctx; 58 } 59 60 @Override 61 protected void doPaint(Graphics2D g, JComponent c, int width, int height, Object [] extendedCacheKeys) { 62 componentColors = extendedCacheKeys; 64 switch(state) { 67 case BACKGROUND_DISABLED: paintBackgroundDisabled(g); break; 68 case BACKGROUND_ENABLED: paintBackgroundEnabled(g); break; 69 70 } 71 } 72 73 74 75 @Override 76 protected final PaintContext getPaintContext() { 77 return ctx; 78 } 79 80 private void paintBackgroundDisabled(Graphics2D g) { 81 roundRect = decodeRoundRect1(); 82 g.setPaint(color1); 83 g.fill(roundRect); 84 roundRect = decodeRoundRect2(); 85 g.setPaint(decodeGradient1(roundRect)); 86 g.fill(roundRect); 87 roundRect = decodeRoundRect3(); 88 g.setPaint(decodeGradient2(roundRect)); 89 g.fill(roundRect); 90 91 } 92 93 private void paintBackgroundEnabled(Graphics2D g) { 94 roundRect = decodeRoundRect4(); 95 g.setPaint(color6); 96 g.fill(roundRect); 97 roundRect = decodeRoundRect2(); 98 g.setPaint(decodeGradient3(roundRect)); 99 g.fill(roundRect); 100 roundRect = decodeRoundRect5(); 101 g.setPaint(decodeGradient4(roundRect)); 102 g.fill(roundRect); 103 104 } 105 106 107 108 private RoundRectangle2D decodeRoundRect1() { 109 roundRect.setRoundRect(decodeX(0.2f), decodeY(1.6f), decodeX(2.8f) - decodeX(0.2f), decodeY(2.8333333f) - decodeY(1.6f), 8.705882f, 8.705882f); return roundRect; 115 } 116 117 private RoundRectangle2D decodeRoundRect2() { 118 roundRect.setRoundRect(decodeX(0.0f), decodeY(1.0f), decodeX(3.0f) - decodeX(0.0f), decodeY(2.0f) - decodeY(1.0f), 4.9411764f, 4.9411764f); return roundRect; 124 } 125 126 private RoundRectangle2D decodeRoundRect3() { 127 roundRect.setRoundRect(decodeX(0.29411763f), decodeY(1.2f), decodeX(2.7058823f) - decodeX(0.29411763f), decodeY(2.0f) - decodeY(1.2f), 4.0f, 4.0f); return roundRect; 133 } 134 135 private RoundRectangle2D decodeRoundRect4() { 136 roundRect.setRoundRect(decodeX(0.2f), decodeY(1.6f), decodeX(2.8f) - decodeX(0.2f), decodeY(2.1666667f) - decodeY(1.6f), 8.705882f, 8.705882f); return roundRect; 142 } 143 144 private RoundRectangle2D decodeRoundRect5() { 145 roundRect.setRoundRect(decodeX(0.28823528f), decodeY(1.2f), decodeX(2.7f) - decodeX(0.28823528f), decodeY(2.0f) - decodeY(1.2f), 4.0f, 4.0f); return roundRect; 151 } 152 153 154 155 private Paint decodeGradient1(Shape s) { 156 Rectangle2D bounds = s.getBounds2D(); 157 float x = (float)bounds.getX(); 158 float y = (float)bounds.getY(); 159 float w = (float)bounds.getWidth(); 160 float h = (float)bounds.getHeight(); 161 return decodeGradient((0.25f * w) + x, (0.07647059f * h) + y, (0.25f * w) + x, (0.9117647f * h) + y, 162 new float[] { 0.0f,0.5f,1.0f }, 163 new Color[] { color2, 164 decodeColor(color2,color3,0.5f), 165 color3}); 166 } 167 168 private Paint decodeGradient2(Shape s) { 169 Rectangle2D bounds = s.getBounds2D(); 170 float x = (float)bounds.getX(); 171 float y = (float)bounds.getY(); 172 float w = (float)bounds.getWidth(); 173 float h = (float)bounds.getHeight(); 174 return decodeGradient((0.25f * w) + x, (0.0f * h) + y, (0.25f * w) + x, (1.0f * h) + y, 175 new float[] { 0.0f,0.13770053f,0.27540106f,0.63770056f,1.0f }, 176 new Color[] { color4, 177 decodeColor(color4,color5,0.5f), 178 color5, 179 decodeColor(color5,color3,0.5f), 180 color3}); 181 } 182 183 private Paint decodeGradient3(Shape s) { 184 Rectangle2D bounds = s.getBounds2D(); 185 float x = (float)bounds.getX(); 186 float y = (float)bounds.getY(); 187 float w = (float)bounds.getWidth(); 188 float h = (float)bounds.getHeight(); 189 return decodeGradient((0.25f * w) + x, (0.07647059f * h) + y, (0.25f * w) + x, (0.9117647f * h) + y, 190 new float[] { 0.0f,0.5f,1.0f }, 191 new Color[] { color7, 192 decodeColor(color7,color8,0.5f), 193 color8}); 194 } 195 196 private Paint decodeGradient4(Shape s) { 197 Rectangle2D bounds = s.getBounds2D(); 198 float x = (float)bounds.getX(); 199 float y = (float)bounds.getY(); 200 float w = (float)bounds.getWidth(); 201 float h = (float)bounds.getHeight(); 202 return decodeGradient((0.25f * w) + x, (0.0f * h) + y, (0.25f * w) + x, (1.0f * h) + y, 203 new float[] { 0.0f,0.13770053f,0.27540106f,0.4906417f,0.7058824f }, 204 new Color[] { color9, 205 decodeColor(color9,color10,0.5f), 206 color10, 207 decodeColor(color10,color11,0.5f), 208 color11}); 209 } 210 211 212 } 213 | Popular Tags |