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 MenuBarPainter extends AbstractRegionPainter { 18 static final int BACKGROUND_ENABLED = 1; 23 static final int BORDER_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.07016757f, 0.12941176f, 0); 39 private Color color2 = decodeColor("nimbusBlueGrey", -0.027777791f, -0.10255819f, 0.23921567f, 0); 40 private Color color3 = decodeColor("nimbusBlueGrey", -0.111111104f, -0.10654225f, 0.23921567f, -29); 41 private Color color4 = decodeColor("nimbusBlueGrey", 0.0f, -0.110526316f, 0.25490195f, -255); 42 private Color color5 = decodeColor("nimbusBorder", 0.0f, 0.0f, 0.0f, 0); 43 44 45 private Object [] componentColors; 47 48 public MenuBarPainter(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 BACKGROUND_ENABLED: paintBackgroundEnabled(g); break; 62 case BORDER_ENABLED: paintBorderEnabled(g); break; 63 64 } 65 } 66 67 68 69 @Override 70 protected final PaintContext getPaintContext() { 71 return ctx; 72 } 73 74 private void paintBackgroundEnabled(Graphics2D g) { 75 rect = decodeRect1(); 76 g.setPaint(color1); 77 g.fill(rect); 78 rect = decodeRect2(); 79 g.setPaint(decodeGradient1(rect)); 80 g.fill(rect); 81 82 } 83 84 private void paintBorderEnabled(Graphics2D g) { 85 rect = decodeRect3(); 86 g.setPaint(color5); 87 g.fill(rect); 88 89 } 90 91 92 93 private Rectangle2D decodeRect1() { 94 rect.setRect(decodeX(1.0f), decodeY(0.0f), decodeX(2.0f) - decodeX(1.0f), decodeY(1.9523809f) - decodeY(0.0f)); return rect; 99 } 100 101 private Rectangle2D decodeRect2() { 102 rect.setRect(decodeX(1.0f), decodeY(0.0f), decodeX(2.0f) - decodeX(1.0f), decodeY(2.0f) - decodeY(0.0f)); return rect; 107 } 108 109 private Rectangle2D decodeRect3() { 110 rect.setRect(decodeX(1.0f), decodeY(2.0f), decodeX(2.0f) - decodeX(1.0f), decodeY(3.0f) - decodeY(2.0f)); return rect; 115 } 116 117 118 119 private Paint decodeGradient1(Shape s) { 120 Rectangle2D bounds = s.getBounds2D(); 121 float x = (float)bounds.getX(); 122 float y = (float)bounds.getY(); 123 float w = (float)bounds.getWidth(); 124 float h = (float)bounds.getHeight(); 125 return decodeGradient((1.0f * w) + x, (0.0f * h) + y, (1.0f * w) + x, (1.0f * h) + y, 126 new float[] { 0.0f,0.015f,0.03f,0.23354445f,0.7569444f }, 127 new Color[] { color2, 128 decodeColor(color2,color3,0.5f), 129 color3, 130 decodeColor(color3,color4,0.5f), 131 color4}); 132 } 133 134 135 } 136 | Popular Tags |