package javax.swing.plaf.nimbus;
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import javax.swing.*;
import javax.swing.Painter;
final class ToolBarPainter extends AbstractRegionPainter {
static final int BORDER_NORTH = 1;
static final int BORDER_SOUTH = 2;
static final int BORDER_EAST = 3;
static final int BORDER_WEST = 4;
static final int HANDLEICON_ENABLED = 5;
private int state;
private PaintContext ctx;
private Path2D path = new Path2D.Float();
private Rectangle2D rect = new Rectangle2D.Float(0, 0, 0, 0);
private RoundRectangle2D roundRect = new RoundRectangle2D.Float(0, 0, 0, 0, 0, 0);
private Ellipse2D ellipse = new Ellipse2D.Float(0, 0, 0, 0);
private Color color1 = decodeColor("nimbusBorder", 0.0f, 0.0f, 0.0f, 0);
private Color color2 = decodeColor("nimbusBlueGrey", 0.0f, -0.110526316f, 0.25490195f, 0);
private Color color3 = decodeColor("nimbusBlueGrey", -0.006944418f, -0.07399663f, 0.11372548f, 0);
private Color color4 = decodeColor("nimbusBorder", 0.0f, -0.029675633f, 0.109803915f, 0);
private Color color5 = decodeColor("nimbusBlueGrey", -0.008547008f, -0.03494492f, -0.07058823f, 0);
private Object[] componentColors;
public ToolBarPainter(PaintContext ctx, int state) {
super();
this.state = state;
this.ctx = ctx;
}
@Override
protected void doPaint(Graphics2D g, JComponent c, int width, int height, Object[] extendedCacheKeys) {
componentColors = extendedCacheKeys;
switch(state) {
case BORDER_NORTH: paintBorderNorth(g); break;
case BORDER_SOUTH: paintBorderSouth(g); break;
case BORDER_EAST: paintBorderEast(g); break;
case BORDER_WEST: paintBorderWest(g); break;
case HANDLEICON_ENABLED: painthandleIconEnabled(g); break;
}
}
@Override
protected final PaintContext getPaintContext() {
return ctx;
}
private void paintBorderNorth(Graphics2D g) {
rect = decodeRect1();
g.setPaint(color1);
g.fill(rect);
}
private void paintBorderSouth(Graphics2D g) {
rect = decodeRect2();
g.setPaint(color1);
g.fill(rect);
}
private void paintBorderEast(Graphics2D g) {
rect = decodeRect2();
g.setPaint(color1);
g.fill(rect);
}
private void paintBorderWest(Graphics2D g) {
rect = decodeRect1();
g.setPaint(color1);
g.fill(rect);
}
private void painthandleIconEnabled(Graphics2D g) {
rect = decodeRect3();
g.setPaint(decodeGradient1(rect));
g.fill(rect);
rect = decodeRect4();
g.setPaint(color4);
g.fill(rect);
path = decodePath1();
g.setPaint(color5);
g.fill(path);
path = decodePath2();
g.setPaint(color5);
g.fill(path);
}
private Rectangle2D decodeRect1() {
rect.setRect(decodeX(1.0f),
decodeY(2.0f),
decodeX(2.0f) - decodeX(1.0f),
decodeY(3.0f) - decodeY(2.0f));
return rect;
}
private Rectangle2D decodeRect2() {
rect.setRect(decodeX(1.0f),
decodeY(0.0f),
decodeX(2.0f) - decodeX(1.0f),
decodeY(1.0f) - decodeY(0.0f));
return rect;
}
private Rectangle2D decodeRect3() {
rect.setRect(decodeX(0.0f),
decodeY(0.0f),
decodeX(2.8f) - decodeX(0.0f),
decodeY(3.0f) - decodeY(0.0f));
return rect;
}
private Rectangle2D decodeRect4() {
rect.setRect(decodeX(2.8f),
decodeY(0.0f),
decodeX(3.0f) - decodeX(2.8f),
decodeY(3.0f) - decodeY(0.0f));
return rect;
}
private Path2D decodePath1() {
path.reset();
path.moveTo(decodeX(0.0f), decodeY(0.0f));
path.lineTo(decodeX(0.0f), decodeY(0.4f));
path.lineTo(decodeX(0.4f), decodeY(0.0f));
path.lineTo(decodeX(0.0f), decodeY(0.0f));
path.closePath();
return path;
}
private Path2D decodePath2() {
path.reset();
path.moveTo(decodeX(0.0f), decodeY(3.0f));
path.lineTo(decodeX(0.0f), decodeY(2.6f));
path.lineTo(decodeX(0.4f), decodeY(3.0f));
path.lineTo(decodeX(0.0f), decodeY(3.0f));
path.closePath();
return path;
}
private Paint decodeGradient1(Shape s) {
Rectangle2D bounds = s.getBounds2D();
float x = (float)bounds.getX();
float y = (float)bounds.getY();
float w = (float)bounds.getWidth();
float h = (float)bounds.getHeight();
return decodeGradient((0.0f * w) + x, (0.5f * h) + y, (1.0f * w) + x, (0.5f * h) + y,
new float[] { 0.0f,0.5f,1.0f },
new Color[] { color2,
decodeColor(color2,color3,0.5f),
color3});
}
}