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 ArrowButtonPainter extends AbstractRegionPainter { 18 static final int BACKGROUND_ENABLED = 1; 23 static final int FOREGROUND_DISABLED = 2; 24 static final int FOREGROUND_ENABLED = 3; 25 26 27 private int state; private PaintContext ctx; 29 30 private Path2D path = new Path2D.Float(); 32 private Rectangle2D rect = new Rectangle2D.Float(0, 0, 0, 0); 33 private RoundRectangle2D roundRect = new RoundRectangle2D.Float(0, 0, 0, 0, 0, 0); 34 private Ellipse2D ellipse = new Ellipse2D.Float(0, 0, 0, 0); 35 36 private Color color1 = decodeColor("nimbusBase", 0.027408898f, -0.57391655f, 0.1490196f, 0); 40 private Color color2 = decodeColor("nimbusBase", -0.57865167f, -0.6357143f, -0.37254906f, 0); 41 42 43 private Object [] componentColors; 45 46 public ArrowButtonPainter(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 FOREGROUND_DISABLED: paintForegroundDisabled(g); break; 60 case FOREGROUND_ENABLED: paintForegroundEnabled(g); break; 61 62 } 63 } 64 65 66 67 @Override 68 protected final PaintContext getPaintContext() { 69 return ctx; 70 } 71 72 private void paintForegroundDisabled(Graphics2D g) { 73 path = decodePath1(); 74 g.setPaint(color1); 75 g.fill(path); 76 77 } 78 79 private void paintForegroundEnabled(Graphics2D g) { 80 path = decodePath1(); 81 g.setPaint(color2); 82 g.fill(path); 83 84 } 85 86 87 88 private Path2D decodePath1() { 89 path.reset(); 90 path.moveTo(decodeX(1.8f), decodeY(1.2f)); 91 path.lineTo(decodeX(1.2f), decodeY(1.5f)); 92 path.lineTo(decodeX(1.8f), decodeY(1.8f)); 93 path.lineTo(decodeX(1.8f), decodeY(1.2f)); 94 path.closePath(); 95 return path; 96 } 97 98 99 100 101 } 102 | Popular Tags |