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 TableHeaderPainter extends AbstractRegionPainter { 18 static final int ASCENDINGSORTICON_ENABLED = 1; 23 static final int DESCENDINGSORTICON_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("nimbusBase", 0.0057927966f, -0.21904764f, 0.15686274f, 0); 39 private Color color2 = decodeColor("nimbusBase", 0.0038565993f, 0.02012986f, 0.054901958f, 0); 40 41 42 private Object [] componentColors; 44 45 public TableHeaderPainter(PaintContext ctx, int state) { 46 super(); 47 this.state = state; 48 this.ctx = ctx; 49 } 50 51 @Override 52 protected void doPaint(Graphics2D g, JComponent c, int width, int height, Object [] extendedCacheKeys) { 53 componentColors = extendedCacheKeys; 55 switch(state) { 58 case ASCENDINGSORTICON_ENABLED: paintascendingSortIconEnabled(g); break; 59 case DESCENDINGSORTICON_ENABLED: paintdescendingSortIconEnabled(g); break; 60 61 } 62 } 63 64 65 66 @Override 67 protected final PaintContext getPaintContext() { 68 return ctx; 69 } 70 71 private void paintascendingSortIconEnabled(Graphics2D g) { 72 path = decodePath1(); 73 g.setPaint(decodeGradient1(path)); 74 g.fill(path); 75 76 } 77 78 private void paintdescendingSortIconEnabled(Graphics2D g) { 79 path = decodePath2(); 80 g.setPaint(decodeGradient1(path)); 81 g.fill(path); 82 83 } 84 85 86 87 private Path2D decodePath1() { 88 path.reset(); 89 path.moveTo(decodeX(1.0f), decodeY(2.0f)); 90 path.lineTo(decodeX(1.7070175f), decodeY(0.0f)); 91 path.lineTo(decodeX(3.0f), decodeY(2.0f)); 92 path.lineTo(decodeX(1.0f), decodeY(2.0f)); 93 path.closePath(); 94 return path; 95 } 96 97 private Path2D decodePath2() { 98 path.reset(); 99 path.moveTo(decodeX(1.0f), decodeY(1.0f)); 100 path.lineTo(decodeX(2.0f), decodeY(1.0f)); 101 path.lineTo(decodeX(1.5025063f), decodeY(2.0f)); 102 path.lineTo(decodeX(1.0f), decodeY(1.0f)); 103 path.closePath(); 104 return path; 105 } 106 107 108 109 private Paint decodeGradient1(Shape s) { 110 Rectangle2D bounds = s.getBounds2D(); 111 float x = (float)bounds.getX(); 112 float y = (float)bounds.getY(); 113 float w = (float)bounds.getWidth(); 114 float h = (float)bounds.getHeight(); 115 return decodeGradient((0.5f * w) + x, (0.0f * h) + y, (0.5f * w) + x, (1.0f * h) + y, 116 new float[] { 0.0f,0.5f,1.0f }, 117 new Color[] { color1, 118 decodeColor(color1,color2,0.5f), 119 color2}); 120 } 121 122 123 } 124 | Popular Tags |