public void paintComponent(Graphics g) {
// As state isn't bound, we need a convenience place to check
// if it has changed. Changing the state typically changes the
if (getFrame() != null) {
setState(getFrame().getExtendedState());
}
JRootPane rootPane = getRootPane();
Window window = getWindow();
boolean leftToRight = (window == null) ?
rootPane.getComponentOrientation().isLeftToRight() :
window.getComponentOrientation().isLeftToRight();
boolean isSelected = (window == null) ? true : window.isActive();
int width = getWidth();
int height = getHeight();
Color background;
Color foreground;
Color darkShadow;
MetalBumps bumps;
if (isSelected) {
background = activeBackground;
foreground = activeForeground;
darkShadow = activeShadow;
bumps = activeBumps;
} else {
background = inactiveBackground;
foreground = inactiveForeground;
darkShadow = inactiveShadow;
bumps = inactiveBumps;
}
g.setColor(background);
g.fillRect(0, 0, width, height);
g.setColor( darkShadow );
g.drawLine ( 0, height - 1, width, height -1);
g.drawLine ( 0, 0, 0 ,0);
g.drawLine ( width - 1, 0 , width -1, 0);
int xOffset = leftToRight ? 5 : width - 5;
if (getWindowDecorationStyle() == JRootPane.FRAME) {
xOffset += leftToRight ? IMAGE_WIDTH + 5 : - IMAGE_WIDTH - 5;
}
String theTitle = getTitle();
if (theTitle != null) {
FontMetrics fm = SwingUtilities2.getFontMetrics(rootPane, g);
g.setColor(foreground);
int yOffset = ( (height - fm.getHeight() ) / 2 ) + fm.getAscent();
Rectangle rect = new Rectangle(0, 0, 0, 0);
if (iconifyButton != null && iconifyButton.getParent() != null) {
rect = iconifyButton.getBounds();
}
int titleW;
if( leftToRight ) {
if (rect.x == 0) {
rect.x = window.getWidth() - window.getInsets().right-2;
}
titleW = rect.x - xOffset - 4;
theTitle = SwingUtilities2.clipStringIfNecessary(
rootPane, fm, theTitle, titleW);
} else {
titleW = xOffset - rect.x - rect.width - 4;
theTitle = SwingUtilities2.clipStringIfNecessary(
rootPane, fm, theTitle, titleW);
xOffset -= SwingUtilities2.stringWidth(rootPane, fm,
theTitle);
}
int titleLength = SwingUtilities2.stringWidth(rootPane, fm,
theTitle);
SwingUtilities2.drawString(rootPane, g, theTitle, xOffset,
yOffset );
xOffset += leftToRight ? titleLength + 5 : -5;
}
int bumpXOffset;
int bumpLength;
if( leftToRight ) {
bumpLength = width - buttonsWidth - xOffset - 5;
bumpXOffset = xOffset;
} else {
bumpLength = xOffset - buttonsWidth - 5;
bumpXOffset = buttonsWidth + 5;
}
int bumpYOffset = 3;
int bumpHeight = getHeight() - (2 * bumpYOffset);
bumps.setBumpArea( bumpLength, bumpHeight );
bumps.paintIcon(this, g, bumpXOffset, bumpYOffset);
}
|