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 ScrollPanePainter extends AbstractRegionPainter { 18 static final int BACKGROUND_ENABLED = 1; 23 static final int BORDER_ENABLED_FOCUSED = 2; 24 static final int BORDER_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("nimbusBorder", 0.0f, 0.0f, 0.0f, 0); 40 private Color color2 = decodeColor("nimbusFocus", 0.0f, 0.0f, 0.0f, 0); 41 42 43 private Object [] componentColors; 45 46 public ScrollPanePainter(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 BORDER_ENABLED_FOCUSED: paintBorderEnabledAndFocused(g); break; 60 case BORDER_ENABLED: paintBorderEnabled(g); break; 61 62 } 63 } 64 65 66 67 @Override 68 protected final PaintContext getPaintContext() { 69 return ctx; 70 } 71 72 private void paintBorderEnabledAndFocused(Graphics2D g) { 73 rect = decodeRect1(); 74 g.setPaint(color1); 75 g.fill(rect); 76 rect = decodeRect2(); 77 g.setPaint(color1); 78 g.fill(rect); 79 rect = decodeRect3(); 80 g.setPaint(color1); 81 g.fill(rect); 82 rect = decodeRect4(); 83 g.setPaint(color1); 84 g.fill(rect); 85 path = decodePath1(); 86 g.setPaint(color2); 87 g.fill(path); 88 89 } 90 91 private void paintBorderEnabled(Graphics2D g) { 92 rect = decodeRect1(); 93 g.setPaint(color1); 94 g.fill(rect); 95 rect = decodeRect2(); 96 g.setPaint(color1); 97 g.fill(rect); 98 rect = decodeRect3(); 99 g.setPaint(color1); 100 g.fill(rect); 101 rect = decodeRect4(); 102 g.setPaint(color1); 103 g.fill(rect); 104 105 } 106 107 108 109 private Rectangle2D decodeRect1() { 110 rect.setRect(decodeX(0.6f), decodeY(0.4f), decodeX(2.4f) - decodeX(0.6f), decodeY(0.6f) - decodeY(0.4f)); return rect; 115 } 116 117 private Rectangle2D decodeRect2() { 118 rect.setRect(decodeX(0.4f), decodeY(0.4f), decodeX(0.6f) - decodeX(0.4f), decodeY(2.6f) - decodeY(0.4f)); return rect; 123 } 124 125 private Rectangle2D decodeRect3() { 126 rect.setRect(decodeX(2.4f), decodeY(0.4f), decodeX(2.6f) - decodeX(2.4f), decodeY(2.6f) - decodeY(0.4f)); return rect; 131 } 132 133 private Rectangle2D decodeRect4() { 134 rect.setRect(decodeX(0.6f), decodeY(2.4f), decodeX(2.4f) - decodeX(0.6f), decodeY(2.6f) - decodeY(2.4f)); return rect; 139 } 140 141 private Path2D decodePath1() { 142 path.reset(); 143 path.moveTo(decodeX(0.4f), decodeY(0.4f)); 144 path.lineTo(decodeX(0.4f), decodeY(2.6f)); 145 path.lineTo(decodeX(2.6f), decodeY(2.6f)); 146 path.lineTo(decodeX(2.6f), decodeY(0.4f)); 147 path.curveTo(decodeAnchorX(2.5999999046325684f, 0.0f), decodeAnchorY(0.4000000059604645f, 0.0f), decodeAnchorX(2.880000352859497f, 0.09999999999999432f), decodeAnchorY(0.4000000059604645f, 0.0f), decodeX(2.8800004f), decodeY(0.4f)); 148 path.curveTo(decodeAnchorX(2.880000352859497f, 0.09999999999999432f), decodeAnchorY(0.4000000059604645f, 0.0f), decodeAnchorX(2.880000352859497f, 0.0f), decodeAnchorY(2.879999876022339f, 0.0f), decodeX(2.8800004f), decodeY(2.8799999f)); 149 path.lineTo(decodeX(0.120000005f), decodeY(2.8799999f)); 150 path.lineTo(decodeX(0.120000005f), decodeY(0.120000005f)); 151 path.lineTo(decodeX(2.8800004f), decodeY(0.120000005f)); 152 path.lineTo(decodeX(2.8800004f), decodeY(0.4f)); 153 path.lineTo(decodeX(0.4f), decodeY(0.4f)); 154 path.closePath(); 155 return path; 156 } 157 158 159 160 161 } 162 | Popular Tags |