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 ToolBarPainter extends AbstractRegionPainter { 18 static final int BORDER_ENABLED = 1; 23 static final int HANDLEICON_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("nimbusBorder", 0.0f, 0.0f, 0.0f, 0); 39 private Color color2 = decodeColor("nimbusBlueGrey", 0.0f, -0.110526316f, 0.25490195f, 0); 40 private Color color3 = decodeColor("nimbusBlueGrey", -0.006944418f, -0.07399663f, 0.11372548f, 0); 41 private Color color4 = decodeColor("nimbusBorder", 0.0f, -0.029675633f, 0.109803915f, 0); 42 private Color color5 = decodeColor("nimbusBlueGrey", -0.008547008f, -0.03494492f, -0.07058823f, 0); 43 44 45 private Object [] componentColors; 47 48 public ToolBarPainter(PaintContext ctx, int state) { 49 super(); 50 this.state = state; 51 this.ctx = ctx; 52 } 53 54 @Override 55 protected void doPaint(Graphics2D g, JComponent c, int width, int height, Object [] extendedCacheKeys) { 56 componentColors = extendedCacheKeys; 58 switch(state) { 61 case BORDER_ENABLED: paintBorderEnabled(g); break; 62 case HANDLEICON_ENABLED: painthandleIconEnabled(g); break; 63 64 } 65 } 66 67 68 69 @Override 70 protected final PaintContext getPaintContext() { 71 return ctx; 72 } 73 74 private void paintBorderEnabled(Graphics2D g) { 75 rect = decodeRect1(); 76 g.setPaint(color1); 77 g.fill(rect); 78 79 } 80 81 private void painthandleIconEnabled(Graphics2D g) { 82 rect = decodeRect2(); 83 g.setPaint(decodeGradient1(rect)); 84 g.fill(rect); 85 rect = decodeRect3(); 86 g.setPaint(color4); 87 g.fill(rect); 88 path = decodePath1(); 89 g.setPaint(color5); 90 g.fill(path); 91 path = decodePath2(); 92 g.setPaint(color5); 93 g.fill(path); 94 95 } 96 97 98 99 private Rectangle2D decodeRect1() { 100 rect.setRect(decodeX(1.0f), decodeY(2.0f), decodeX(2.0f) - decodeX(1.0f), decodeY(3.0f) - decodeY(2.0f)); return rect; 105 } 106 107 private Rectangle2D decodeRect2() { 108 rect.setRect(decodeX(0.0f), decodeY(0.0f), decodeX(2.8f) - decodeX(0.0f), decodeY(3.0f) - decodeY(0.0f)); return rect; 113 } 114 115 private Rectangle2D decodeRect3() { 116 rect.setRect(decodeX(2.8f), decodeY(0.0f), decodeX(3.0f) - decodeX(2.8f), decodeY(3.0f) - decodeY(0.0f)); return rect; 121 } 122 123 private Path2D decodePath1() { 124 path.reset(); 125 path.moveTo(decodeX(0.0f), decodeY(0.0f)); 126 path.lineTo(decodeX(0.0f), decodeY(0.4f)); 127 path.lineTo(decodeX(0.4f), decodeY(0.0f)); 128 path.lineTo(decodeX(0.0f), decodeY(0.0f)); 129 path.closePath(); 130 return path; 131 } 132 133 private Path2D decodePath2() { 134 path.reset(); 135 path.moveTo(decodeX(0.0f), decodeY(3.0f)); 136 path.lineTo(decodeX(0.0f), decodeY(2.6f)); 137 path.lineTo(decodeX(0.4f), decodeY(3.0f)); 138 path.lineTo(decodeX(0.0f), decodeY(3.0f)); 139 path.closePath(); 140 return path; 141 } 142 143 144 145 private Paint decodeGradient1(Shape s) { 146 Rectangle2D bounds = s.getBounds2D(); 147 float x = (float)bounds.getX(); 148 float y = (float)bounds.getY(); 149 float w = (float)bounds.getWidth(); 150 float h = (float)bounds.getHeight(); 151 return decodeGradient((0.0f * w) + x, (0.5f * h) + y, (1.0f * w) + x, (0.5f * h) + y, 152 new float[] { 0.0f,0.5f,1.0f }, 153 new Color[] { color2, 154 decodeColor(color2,color3,0.5f), 155 color3}); 156 } 157 158 159 } 160 | Popular Tags |