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 TreeCellEditorPainter extends AbstractRegionPainter { 18 static final int BACKGROUND_DISABLED = 1; 23 static final int BACKGROUND_ENABLED = 2; 24 static final int BACKGROUND_ENABLED_FOCUSED = 3; 25 static final int BACKGROUND_SELECTED = 4; 26 27 28 private int state; private PaintContext ctx; 30 31 private Path2D path = new Path2D.Float(); 33 private Rectangle2D rect = new Rectangle2D.Float(0, 0, 0, 0); 34 private RoundRectangle2D roundRect = new RoundRectangle2D.Float(0, 0, 0, 0, 0, 0); 35 private Ellipse2D ellipse = new Ellipse2D.Float(0, 0, 0, 0); 36 37 private Color color1 = decodeColor("nimbusBlueGrey", 0.0f, -0.017358616f, -0.11372548f, 0); 41 private Color color2 = decodeColor("nimbusFocus", 0.0f, 0.0f, 0.0f, 0); 42 43 44 private Object [] componentColors; 46 47 public TreeCellEditorPainter(PaintContext ctx, int state) { 48 super(); 49 this.state = state; 50 this.ctx = ctx; 51 } 52 53 @Override 54 protected void doPaint(Graphics2D g, JComponent c, int width, int height, Object [] extendedCacheKeys) { 55 componentColors = extendedCacheKeys; 57 switch(state) { 60 case BACKGROUND_ENABLED: paintBackgroundEnabled(g); break; 61 case BACKGROUND_ENABLED_FOCUSED: paintBackgroundEnabledAndFocused(g); break; 62 63 } 64 } 65 66 67 68 @Override 69 protected final PaintContext getPaintContext() { 70 return ctx; 71 } 72 73 private void paintBackgroundEnabled(Graphics2D g) { 74 path = decodePath1(); 75 g.setPaint(color1); 76 g.fill(path); 77 78 } 79 80 private void paintBackgroundEnabledAndFocused(Graphics2D g) { 81 path = decodePath2(); 82 g.setPaint(color2); 83 g.fill(path); 84 85 } 86 87 88 89 private Path2D decodePath1() { 90 path.reset(); 91 path.moveTo(decodeX(0.0f), decodeY(0.0f)); 92 path.lineTo(decodeX(0.0f), decodeY(3.0f)); 93 path.lineTo(decodeX(3.0f), decodeY(3.0f)); 94 path.lineTo(decodeX(3.0f), decodeY(0.0f)); 95 path.lineTo(decodeX(0.2f), decodeY(0.0f)); 96 path.lineTo(decodeX(0.2f), decodeY(0.2f)); 97 path.lineTo(decodeX(2.8f), decodeY(0.2f)); 98 path.lineTo(decodeX(2.8f), decodeY(2.8f)); 99 path.lineTo(decodeX(0.2f), decodeY(2.8f)); 100 path.lineTo(decodeX(0.2f), decodeY(0.0f)); 101 path.lineTo(decodeX(0.0f), decodeY(0.0f)); 102 path.closePath(); 103 return path; 104 } 105 106 private Path2D decodePath2() { 107 path.reset(); 108 path.moveTo(decodeX(0.0f), decodeY(0.0f)); 109 path.lineTo(decodeX(0.0f), decodeY(3.0f)); 110 path.lineTo(decodeX(3.0f), decodeY(3.0f)); 111 path.lineTo(decodeX(3.0f), decodeY(0.0f)); 112 path.lineTo(decodeX(0.24000001f), decodeY(0.0f)); 113 path.lineTo(decodeX(0.24000001f), decodeY(0.24000001f)); 114 path.lineTo(decodeX(2.7600007f), decodeY(0.24000001f)); 115 path.lineTo(decodeX(2.7600007f), decodeY(2.7599998f)); 116 path.lineTo(decodeX(0.24000001f), decodeY(2.7599998f)); 117 path.lineTo(decodeX(0.24000001f), decodeY(0.0f)); 118 path.lineTo(decodeX(0.0f), decodeY(0.0f)); 119 path.closePath(); 120 return path; 121 } 122 123 124 125 126 } 127 | Popular Tags |