public void paintBorder(Component c,
Graphics g,
int x,
int y,
int width,
int height) {
Insets insets = getBorderInsets(c);
Color oldColor = g.getColor();
g.translate(x, y);
// If the tileIcon failed loading, paint as gray.
if (this.tileIcon != null) {
this.color = (this.tileIcon.getIconWidth() == -1) ?
Color.gray : null;
}
if (this.color != null) {
g.setColor(this.color);
g.fillRect(0, 0, width - insets.right, insets.top);
g.fillRect(0, insets.top, insets.left, height - insets.top);
g.fillRect(insets.left, height - insets.bottom, width - insets.left, insets.bottom);
g.fillRect(width - insets.right, 0, insets.right, height - insets.bottom);
} else if (this.tileIcon != null) {
int tileW = tileIcon.getIconWidth();
int tileH = tileIcon.getIconHeight();
int xpos, ypos, startx, starty;
Graphics cg;
// Paint top matte edge
boolean alt = false;
cg = g.create();
cg.setClip(0, 0, width, insets.top);
for (ypos = 0; insets.top - ypos > 0; ypos += tileH) {
for (xpos = 0; width - xpos > 0; xpos += tileW) {
if (alt) { // alt image
this.tileIconAlt.paintIcon(c, cg, xpos, ypos);
alt = false;
} else { // normal
this.tileIcon.paintIcon(c, cg, xpos, ypos);
alt = true;
}
}
}
cg.dispose();
// Paint left matte edge
cg = g.create();
cg.setClip(0, insets.top, insets.left, height - insets.top);
starty = insets.top - (insets.top%tileH);
startx = 0;
for (ypos = starty; height - ypos > 0; ypos += tileH) {
for (xpos = startx; insets.left - xpos > 0; xpos += tileW) {
if (alt) { // alt image
this.tileIconAlt.paintIcon(c, cg, xpos, ypos);
alt = false;
} else { // normal
this.tileIcon.paintIcon(c, cg, xpos, ypos);
alt = true;
}
}
}
cg.dispose();
// Paint bottom matte edge
cg = g.create();
cg.setClip(insets.left, height - insets.bottom, width - insets.left, insets.bottom);
starty = (height - insets.bottom) - ((height - insets.bottom)%tileH);
startx = insets.left - (insets.left%tileW);
for (ypos = starty; height - ypos > 0; ypos += tileH) {
for (xpos = startx; width - xpos > 0; xpos += tileW) {
if (alt) { // alt image
this.tileIconAlt.paintIcon(c, cg, xpos, ypos);
alt = false;
} else { // normal
this.tileIcon.paintIcon(c, cg, xpos, ypos);
alt = true;
}
}
}
cg.dispose();
// Paint right matte edge
cg = g.create();
cg.setClip(width - insets.right, insets.top, insets.right, height - insets.top - insets.bottom);
starty = insets.top - (insets.top%tileH);
startx = width - insets.right - ((width - insets.right)%tileW);
for (ypos = starty; height - ypos > 0; ypos += tileH) {
for (xpos = startx; width - xpos > 0; xpos += tileW) {
if (alt) { // alt image
this.tileIconAlt.paintIcon(c, cg, xpos, ypos);
alt = false;
} else { // normal
this.tileIcon.paintIcon(c, cg, xpos, ypos);
alt = true;
}
}
}
cg.dispose();
}
g.translate(-x, -y);
g.setColor(oldColor);
}
|