/*
* Copyright 2005 MH-Software-Entwicklung. All rights reserved.
* Use is subject to license terms.
*/
package com.jtattoo.plaf.aluminium;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.plaf.*;
import com.jtattoo.plaf.*;
/**
* @author Michael Hagen
*/
public class AluminiumBorders extends BaseBorders {
private static Border buttonBorder = null;
private static Border rolloverToolButtonBorder = null;
private static Border internalFrameBorder = null;
//------------------------------------------------------------------------------------
// Lazy access methods
//------------------------------------------------------------------------------------
public static Border getButtonBorder() {
if (buttonBorder == null) {
buttonBorder = new ButtonBorder();
}
return buttonBorder;
}
public static Border getToggleButtonBorder() {
return getButtonBorder();
}
public static Border getRolloverToolButtonBorder() {
if (rolloverToolButtonBorder == null) {
rolloverToolButtonBorder = new RolloverToolButtonBorder();
}
return rolloverToolButtonBorder;
}
public static Border getInternalFrameBorder() {
if (internalFrameBorder == null) {
internalFrameBorder = new InternalFrameBorder();
}
return internalFrameBorder;
}
//------------------------------------------------------------------------------------
// Implementation of border classes
//------------------------------------------------------------------------------------
public static class ButtonBorder implements Border, UIResource {
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
}
public Insets getBorderInsets(Component c) {
if (AluminiumLookAndFeel.getTheme().doDrawSquareButtons()) {
return new Insets(3, 4, 3, 4);
} else {
return new Insets(2, 12, 2, 12);
}
}
public Insets getBorderInsets(Component c, Insets borderInsets) {
Insets insets = getBorderInsets(c);
borderInsets.left = insets.left;
borderInsets.top = insets.top;
borderInsets.right = insets.right;
borderInsets.bottom = insets.bottom;
return borderInsets;
}
public boolean isBorderOpaque() {
return false;
}
} // class ButtonBorder
public static class RolloverToolButtonBorder implements Border, UIResource {
private static final Insets insets = new Insets(1, 1, 1, 1);
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
AbstractButton button = (AbstractButton) c;
ButtonModel model = button.getModel();
Color loColor = AluminiumLookAndFeel.getFrameColor();
if (model.isEnabled()) {
if ((model.isPressed() && model.isArmed()) || model.isSelected()) {
Graphics2D g2D = (Graphics2D) g;
Composite composite = g2D.getComposite();
g.setColor(loColor);
g.drawRect(x, y, w - 1, h - 1);
AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.15f);
g2D.setComposite(alpha);
g.setColor(Color.black);
g.fillRect(x + 1, y + 1, w - 2, h - 2);
g2D.setComposite(composite);
} else if (model.isRollover()) {
Graphics2D g2D = (Graphics2D) g;
Composite composite = g2D.getComposite();
g.setColor(loColor);
g.drawRect(x, y, w - 1, h - 1);
AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f);
g2D.setComposite(alpha);
g.setColor(AbstractLookAndFeel.getTheme().getSelectionBackgroundColor());
g.fillRect(x + 1, y + 1, w - 2, h - 2);
g2D.setComposite(composite);
}
}
}
public Insets getBorderInsets(Component c) {
return new Insets(insets.top, insets.left, insets.bottom, insets.right);
}
public Insets getBorderInsets(Component c, Insets borderInsets) {
borderInsets.left = insets.left;
borderInsets.top = insets.top;
borderInsets.right = insets.right;
borderInsets.bottom = insets.bottom;
return borderInsets;
}
public boolean isBorderOpaque() {
return true;
}
} // class RolloverToolButtonBorder
public static class InternalFrameBorder extends BaseInternalFrameBorder {
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
Graphics2D g2D = (Graphics2D) g;
Color titleColor = AluminiumLookAndFeel.getWindowInactiveTitleBackgroundColor();
if (isActive(c)) {
titleColor = AluminiumLookAndFeel.getWindowTitleBackgroundColor();
}
int th = getTitleHeight(c);
g.setColor(titleColor);
g.fillRect(1, 1, w, dw);
g.fillRect(1, h - dw, w, dw - 1);
if (isActive(c)) {
JTattooUtilities.fillHorGradient(g, AluminiumLookAndFeel.getTheme().getWindowTitleColors(), 1, dw, dw, th + 1);
JTattooUtilities.fillHorGradient(g, AluminiumLookAndFeel.getTheme().getWindowTitleColors(), w - dw, dw, dw, th + 1);
Color c1 = AbstractLookAndFeel.getTheme().getWindowTitleColorDark();
Color c2 = AbstractLookAndFeel.getTheme().getWindowTitleColorLight();
g2D.setPaint(new GradientPaint(0, dw + th + 1, c1, 0, h - th - (2 * dw), c2));
g.fillRect(1, dw + th + 1, dw - 1, h - th - (2 * dw));
g.fillRect(w - dw, dw + th + 1, dw - 1, h - th - (2 * dw));
g2D.setPaint(null);
} else {
JTattooUtilities.fillHorGradient(g, AluminiumLookAndFeel.getTheme().getWindowInactiveTitleColors(), 1, dw, dw, th + 1);
JTattooUtilities.fillHorGradient(g, AluminiumLookAndFeel.getTheme().getWindowInactiveTitleColors(), w - dw, dw, dw, th + 1);
Color c1 = AbstractLookAndFeel.getTheme().getWindowInactiveTitleColorDark();
Color c2 = AbstractLookAndFeel.getTheme().getWindowInactiveTitleColorLight();
g2D.setPaint(new GradientPaint(0, dw + th + 1, c1, 0, h - th - (2 * dw), c2));
g.fillRect(1, dw + th + 1, dw - 1, h - th - (2 * dw));
g.fillRect(w - dw, dw + th + 1, dw - 1, h - th - (2 * dw));
g2D.setPaint(null);
}
Color borderColor = AluminiumLookAndFeel.getWindowInactiveBorderColor();
if (isActive(c)) {
borderColor = AluminiumLookAndFeel.getWindowBorderColor();
}
g.setColor(borderColor);
g.drawRect(0, 0, w - 1, h - 1);
g.drawLine(x + dw - 1, y + insets.top + th, x + dw - 1, y + h - dw);
g.drawLine(x + w - dw, y + insets.top + th, x + w - dw, y + h - dw);
g.drawLine(x + dw - 1, y + h - dw, x + w - dw, y + h - dw);
g.setColor(new Color(220, 220, 220));
g.drawLine(1, 1, w - 3, 1);
g.drawLine(1, 1, 1, h - 2);
}
} // class InternalFrameBorder
} // class AluminiumBorders