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 PopupMenuPainter 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.6111111f, -0.110526316f, -0.39607844f, 0); 39 private Color color2 = decodeColor("nimbusBase", 0.0f, -0.6357143f, 0.45098037f, 0); 40 private Color color3 = decodeColor("nimbusBase", 0.021348298f, -0.6150531f, 0.39999998f, 0); 41 42 43 private Object [] componentColors; 45 46 public PopupMenuPainter(PaintContext ctx, int state) { 47 super(); 48 this.state = state; 49 this.ctx = ctx; 50 } 51 52 @Override 53 protected void doPaint(Graphics2D g, JComponent c, int width, int height, Object [] extendedCacheKeys) { 54 componentColors = extendedCacheKeys; 56 switch(state) { 59 case BACKGROUND_DISABLED: paintBackgroundDisabled(g); break; 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 paintBackgroundDisabled(Graphics2D g) { 73 rect = decodeRect1(); 74 g.setPaint(color1); 75 g.fill(rect); 76 rect = decodeRect2(); 77 g.setPaint(decodeGradient1(rect)); 78 g.fill(rect); 79 80 } 81 82 private void paintBackgroundEnabled(Graphics2D g) { 83 rect = decodeRect3(); 84 g.setPaint(color1); 85 g.fill(rect); 86 rect = decodeRect4(); 87 g.setPaint(decodeGradient1(rect)); 88 g.fill(rect); 89 90 } 91 92 93 94 private Rectangle2D decodeRect1() { 95 rect.setRect(decodeX(1.0f), decodeY(0.0f), decodeX(2.0f) - decodeX(1.0f), decodeY(3.0f) - decodeY(0.0f)); return rect; 100 } 101 102 private Rectangle2D decodeRect2() { 103 rect.setRect(decodeX(1.0045455f), decodeY(0.11111111f), decodeX(1.9954545f) - decodeX(1.0045455f), decodeY(2.909091f) - decodeY(0.11111111f)); return rect; 108 } 109 110 private Rectangle2D decodeRect3() { 111 rect.setRect(decodeX(0.0f), decodeY(0.0f), decodeX(3.0f) - decodeX(0.0f), decodeY(3.0f) - decodeY(0.0f)); return rect; 116 } 117 118 private Rectangle2D decodeRect4() { 119 rect.setRect(decodeX(0.5f), decodeY(0.09090909f), decodeX(2.5f) - decodeX(0.5f), decodeY(2.909091f) - decodeY(0.09090909f)); return rect; 124 } 125 126 127 128 private Paint decodeGradient1(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.0030f,0.02f,0.5f,0.98f,0.996f,1.0f }, 136 new Color[] { color2, 137 decodeColor(color2,color3,0.5f), 138 color3, 139 decodeColor(color3,color3,0.5f), 140 color3, 141 decodeColor(color3,color2,0.5f), 142 color2}); 143 } 144 145 146 } 147 | Popular Tags |