public void paintIcon(Component c,
Graphics g,
int x,
int y) {
JButton parentButton = (JButton)c;
ButtonModel buttonModel = parentButton.getModel();
Color backgroundColor = MetalLookAndFeel.getPrimaryControl();
Color internalBackgroundColor =
MetalLookAndFeel.getPrimaryControl();
Color mainItemColor =
MetalLookAndFeel.getPrimaryControlDarkShadow();
Color darkHighlightColor = MetalLookAndFeel.getBlack();
// ul = Upper Left and lr = Lower Right
Color ulLightHighlightColor = MetalLookAndFeel.getWhite();
Color lrLightHighlightColor = MetalLookAndFeel.getWhite();
// if the internal frame is inactive
if (parentButton.getClientProperty("paintActive") != Boolean.TRUE)
{
backgroundColor = MetalLookAndFeel.getControl();
internalBackgroundColor = backgroundColor;
mainItemColor = MetalLookAndFeel.getControlDarkShadow();
// if inactive and pressed
if (buttonModel.isPressed() && buttonModel.isArmed()) {
internalBackgroundColor =
MetalLookAndFeel.getControlShadow();
ulLightHighlightColor = internalBackgroundColor;
mainItemColor = darkHighlightColor;
}
}
// if the button is pressed and the mouse is over it
else if (buttonModel.isPressed() && buttonModel.isArmed()) {
internalBackgroundColor =
MetalLookAndFeel.getPrimaryControlShadow();
ulLightHighlightColor = internalBackgroundColor;
mainItemColor = darkHighlightColor;
// darkHighlightColor is still "getBlack()"
}
g.translate(x, y);
// fill background
g.setColor(backgroundColor);
g.fillRect(0,0, iconSize,iconSize);
// BOX
// fill inside the box
g.setColor(internalBackgroundColor);
g.fillRect(3,6, iconSize-9,iconSize-9);
// draw dark highlight color
g.setColor(darkHighlightColor);
g.drawRect(1,5, iconSize-8,iconSize-8);
g.drawLine(1,iconSize-2, 1,iconSize-2); // extra pixel on bottom
// draw lower right light highlight
g.setColor(lrLightHighlightColor);
g.drawRect(2,6, iconSize-7,iconSize-7);
// draw upper left light highlight
g.setColor(ulLightHighlightColor);
g.drawRect(3,7, iconSize-9,iconSize-9);
// draw the main box
g.setColor(mainItemColor);
g.drawRect(2,6, iconSize-8,iconSize-8);
// Six extraneous pixels to deal with
g.setColor(ulLightHighlightColor);
g.drawLine(iconSize-6,8,iconSize-6,8);
g.drawLine(iconSize-9,6, iconSize-7,8);
g.setColor(mainItemColor);
g.drawLine(3,iconSize-3,3,iconSize-3);
g.setColor(darkHighlightColor);
g.drawLine(iconSize-6,9,iconSize-6,9);
g.setColor(backgroundColor);
g.drawLine(iconSize-9,5,iconSize-9,5);
// ARROW
// do the shaft first
g.setColor(mainItemColor);
g.fillRect(iconSize-7,3, 3,5); // do a big block
g.drawLine(iconSize-6,5, iconSize-3,2); // top shaft
g.drawLine(iconSize-6,6, iconSize-2,2); // bottom shaft
g.drawLine(iconSize-6,7, iconSize-3,7); // bottom arrow head
// draw the dark highlight
g.setColor(darkHighlightColor);
g.drawLine(iconSize-8,2, iconSize-7,2); // top of arrowhead
g.drawLine(iconSize-8,3, iconSize-8,7); // left of arrowhead
g.drawLine(iconSize-6,4, iconSize-3,1); // top of shaft
g.drawLine(iconSize-4,6, iconSize-3,6); // top,right of arrowhead
// draw the light highlight
g.setColor(lrLightHighlightColor);
g.drawLine(iconSize-6,3, iconSize-6,3); // top
g.drawLine(iconSize-4,5, iconSize-2,3); // under shaft
g.drawLine(iconSize-4,8, iconSize-3,8); // under arrowhead
g.drawLine(iconSize-2,8, iconSize-2,7); // right of arrowhead
g.translate(-x, -y);
}
|