}
@Override
public void paint(Graphics2D graphics) {
TabButton tabButton = (TabButton)getComponent();
TabPane tabPane = (TabPane)TerraTabPaneSkin.this.getComponent();
boolean active = (selectionChangeTransition != null
&& selectionChangeTransition.getTab() == tabButton.tab);
Color backgroundColor, buttonBevelColor;
if (tabButton.isSelected()
|| active) {
backgroundColor = activeTabColor;
buttonBevelColor = activeButtonBevelColor;
} else {
backgroundColor = inactiveTabColor;
buttonBevelColor = inactiveButtonBevelColor;
}
int width = getWidth();
int height = getHeight();
// Draw the background
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
switch(tabOrientation) {
case HORIZONTAL: {
graphics.setPaint(new GradientPaint(width / 2f, 0, buttonBevelColor,
width / 2f, height / 2f, backgroundColor));
graphics.fill(new RoundRectangle2D.Double(0.5, 0.5, width - 1, height - 1 + buttonCornerRadius,
buttonCornerRadius, buttonCornerRadius));
break;
}
case VERTICAL: {
graphics.setPaint(new GradientPaint(0, height / 2f, buttonBevelColor,
width / 2f, height / 2f, backgroundColor));
graphics.fill(new RoundRectangle2D.Double(0.5, 0.5, width - 1 + buttonCornerRadius, height - 1,
buttonCornerRadius, buttonCornerRadius));
break;
}
default: {
break;
}
}
// Draw the border
graphics.setPaint((tabButton.isSelected() || active) ? borderColor : inactiveBorderColor);
graphics.setStroke(new BasicStroke(1));
switch(tabOrientation) {
case HORIZONTAL: {
graphics.draw(new RoundRectangle2D.Double(0.5, 0.5, width - 1, height + buttonCornerRadius - 1,
buttonCornerRadius, buttonCornerRadius));
break;
}
case VERTICAL: {
graphics.draw(new RoundRectangle2D.Double(0.5, 0.5, width + buttonCornerRadius - 1, height - 1,
buttonCornerRadius, buttonCornerRadius));
break;
}
default: {
break;
}
}
if (!(tabButton.isSelected()
|| active)) {
graphics.setPaint(borderColor);
// Draw divider
switch(tabOrientation) {
case HORIZONTAL: {
graphics.draw(new Line2D.Double(0.5, height - 0.5, width - 0.5, height - 0.5));
break;
}
case VERTICAL: {
graphics.draw(new Line2D.Double(width - 0.5, 0.5, width - 0.5, height - 0.5));
break;
}
default: {
break;
}
}
}
// Paint the content
Button.DataRenderer dataRenderer = tabButton.getDataRenderer();
dataRenderer.render(tabButton.getButtonData(), tabButton, false);
Graphics2D contentGraphics = (Graphics2D)graphics.create();
contentGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_OFF);
switch (tabOrientation) {
case HORIZONTAL: {
int contentWidth = getWidth() - (buttonPadding.left + buttonPadding.right + 2);
if (tabPane.isCloseable()
&& tabButton.isSelected()) {
contentWidth -= (CLOSE_TRIGGER_SIZE + buttonSpacing);
}
dataRenderer.setSize(Math.max(contentWidth, 0),
Math.max(getHeight() - (buttonPadding.top + buttonPadding.bottom + 2), 0));
contentGraphics.translate(buttonPadding.left + 1, buttonPadding.top + 1);
break;
}
case VERTICAL: {
int contentWidth = getHeight() - (buttonPadding.top + buttonPadding.bottom + 2);
if (tabPane.isCloseable()
&& tabButton.isSelected()) {
contentWidth -= (CLOSE_TRIGGER_SIZE + buttonSpacing);
}
dataRenderer.setSize(Math.max(contentWidth, 0),
Math.max(getWidth() - (buttonPadding.left + buttonPadding.right + 2), 0));
contentGraphics.translate(buttonPadding.top + 1, buttonPadding.left + 1);
contentGraphics.rotate(-Math.PI / 2d);
contentGraphics.translate(-dataRenderer.getWidth(), 0);
break;
}
default: {
break;
}
}
contentGraphics.clipRect(0, 0, dataRenderer.getWidth(), dataRenderer.getHeight());
dataRenderer.paint(contentGraphics);
contentGraphics.dispose();
// Draw the close trigger
if (tabPane.isCloseable()
&& tabButton.isSelected()) {
graphics.setStroke(new BasicStroke(2.5f));
int x = 0;
int y = 0;