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 EditorPanePainter extends AbstractRegionPainter { 18 static final int BACKGROUND_DISABLED = 1; 23 static final int BACKGROUND_ENABLED = 2; 24 static final int BACKGROUND_SELECTED = 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("nimbusBlueGrey", -0.015872955f, -0.07995863f, 0.15294117f, 0); 40 private Color color2 = decodeColor("nimbusLightBackground", 0.0f, 0.0f, 0.0f, 0); 41 42 43 private Object [] componentColors; 45 46 public EditorPanePainter(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 case BACKGROUND_SELECTED: paintBackgroundSelected(g); break; 62 63 } 64 } 65 66 67 68 @Override 69 protected final PaintContext getPaintContext() { 70 return ctx; 71 } 72 73 private void paintBackgroundDisabled(Graphics2D g) { 74 rect = decodeRect1(); 75 g.setPaint(color1); 76 g.fill(rect); 77 78 } 79 80 private void paintBackgroundEnabled(Graphics2D g) { 81 rect = decodeRect1(); 82 g.setPaint(color2); 83 g.fill(rect); 84 85 } 86 87 private void paintBackgroundSelected(Graphics2D g) { 88 rect = decodeRect1(); 89 g.setPaint(color2); 90 g.fill(rect); 91 92 } 93 94 95 96 private Rectangle2D decodeRect1() { 97 rect.setRect(decodeX(0.0f), decodeY(0.0f), decodeX(3.0f) - decodeX(0.0f), decodeY(3.0f) - decodeY(0.0f)); return rect; 102 } 103 104 105 106 107 } 108 | Popular Tags |