|
|
@ -28,9 +28,6 @@ import java.awt.*; |
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.*; |
|
|
|
import javax.swing.*; |
|
|
|
|
|
|
|
|
|
|
|
import com.github.weisj.darklaf.graphics.GraphicsContext; |
|
|
|
|
|
|
|
import com.github.weisj.darklaf.graphics.GraphicsUtil; |
|
|
|
|
|
|
|
import com.github.weisj.darklaf.icons.EmptyIcon; |
|
|
|
|
|
|
|
import com.github.weisj.darklaf.ui.button.DarkButtonUI; |
|
|
|
import com.github.weisj.darklaf.ui.button.DarkButtonUI; |
|
|
|
|
|
|
|
|
|
|
|
public class MoreTabsButton extends DarkTabAreaButton { |
|
|
|
public class MoreTabsButton extends DarkTabAreaButton { |
|
|
@ -43,15 +40,18 @@ public class MoreTabsButton extends DarkTabAreaButton { |
|
|
|
public MoreTabsButton(final DarkTabbedPaneUI ui) { |
|
|
|
public MoreTabsButton(final DarkTabbedPaneUI ui) { |
|
|
|
super(ui); |
|
|
|
super(ui); |
|
|
|
this.ui = ui; |
|
|
|
this.ui = ui; |
|
|
|
|
|
|
|
setLayout(null); |
|
|
|
icon = ui.getMoreTabsIcon(); |
|
|
|
icon = ui.getMoreTabsIcon(); |
|
|
|
|
|
|
|
setForeground(UIManager.getColor("TabbedPane.moreTabsButton.foreground")); |
|
|
|
pad = UIManager.getInt("TabbedPane.moreTabsButton.pad"); |
|
|
|
pad = UIManager.getInt("TabbedPane.moreTabsButton.pad"); |
|
|
|
int fontSize = UIManager.getInt("TabbedPane.moreTabsButton.fontSize"); |
|
|
|
setFont(UIManager.getFont("TabbedPane.moreTabsButton.font")); |
|
|
|
setIcon(EmptyIcon.create(icon.getIconWidth(), icon.getIconHeight())); |
|
|
|
setIcon(new MoreTabsIcon(icon, this)); |
|
|
|
putClientProperty(DarkButtonUI.KEY_NO_BACKGROUND, true); |
|
|
|
putClientProperty(DarkButtonUI.KEY_VARIANT, DarkButtonUI.VARIANT_BORDERLESS); |
|
|
|
putClientProperty(DarkButtonUI.KEY_VARIANT, DarkButtonUI.VARIANT_BORDERLESS_RECTANGULAR); |
|
|
|
|
|
|
|
putClientProperty(DarkButtonUI.KEY_SQUARE, true); |
|
|
|
putClientProperty(DarkButtonUI.KEY_SQUARE, true); |
|
|
|
|
|
|
|
putClientProperty(DarkButtonUI.KEY_THIN, true); |
|
|
|
|
|
|
|
setMargin(new Insets(pad, pad, pad, pad)); |
|
|
|
setFocusable(false); |
|
|
|
setFocusable(false); |
|
|
|
setFont(getFont().deriveFont((float) fontSize)); |
|
|
|
setOpaque(true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -60,45 +60,39 @@ public class MoreTabsButton extends DarkTabAreaButton { |
|
|
|
return ui.getTabAreaBackground(); |
|
|
|
return ui.getTabAreaBackground(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected void paintButton(final Graphics g) { |
|
|
|
protected String getLabelString() { |
|
|
|
FontMetrics metrics = g.getFontMetrics(); |
|
|
|
int invisible = Math.min(ui.minVisible - 1 + ui.tabPane.getTabCount() - ui.maxVisible, |
|
|
|
String label = getLabelString(); |
|
|
|
ui.tabPane.getTabCount()); |
|
|
|
int labelWidth = metrics.stringWidth(label); |
|
|
|
return invisible >= 100 ? INFINITY : String.valueOf(invisible); |
|
|
|
int x = (getWidth() - (icon.getIconWidth() + labelWidth + pad)) / 2; |
|
|
|
} |
|
|
|
int y = (getHeight() - icon.getIconHeight()) / 2; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GraphicsContext config = GraphicsUtil.setupAntialiasing(g); |
|
|
|
protected static class MoreTabsIcon implements Icon { |
|
|
|
/* |
|
|
|
|
|
|
|
* These offsets are due to the nature of the used icon. They are applied to match the baseline of |
|
|
|
private final Icon icon; |
|
|
|
* the label.properties text. |
|
|
|
private final MoreTabsButton button; |
|
|
|
* A different icon might need a different offset. |
|
|
|
|
|
|
|
*/ |
|
|
|
protected MoreTabsIcon(final Icon icon, final MoreTabsButton button) { |
|
|
|
int off = 5; |
|
|
|
this.icon = icon; |
|
|
|
int tabPlacement = ui.tabPane.getTabPlacement(); |
|
|
|
this.button = button; |
|
|
|
if (tabPlacement == TOP) { |
|
|
|
|
|
|
|
y += 2; |
|
|
|
|
|
|
|
} else if (tabPlacement == BOTTOM) { |
|
|
|
|
|
|
|
y -= 1; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
icon.paintIcon(this, g, x, y); |
|
|
|
@Override |
|
|
|
config.restore(); |
|
|
|
public void paintIcon(final Component c, final Graphics g, final int x, final int y) { |
|
|
|
config = GraphicsUtil.setupAntialiasing(g); |
|
|
|
icon.paintIcon(c, g, x, y + getIconHeight() - icon.getIconHeight()); |
|
|
|
g.drawString(label, x + icon.getIconWidth() + pad, y + icon.getIconHeight() - off); |
|
|
|
String text = button.getLabelString(); |
|
|
|
config.restore(); |
|
|
|
g.setColor(button.getForeground()); |
|
|
|
|
|
|
|
g.drawString(text, x + icon.getIconWidth() + button.pad, y + icon.getIconHeight()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected String getLabelString() { |
|
|
|
@Override |
|
|
|
int invisible = Math.min(ui.minVisible - 1 + ui.tabPane.getTabCount() - ui.maxVisible, |
|
|
|
public int getIconWidth() { |
|
|
|
ui.tabPane.getTabCount()); |
|
|
|
int textWidth = button.getFontMetrics(button.getFont()).stringWidth(button.getLabelString()); |
|
|
|
return invisible >= 100 ? INFINITY : String.valueOf(invisible); |
|
|
|
return icon.getIconWidth() + textWidth + button.pad; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Dimension getPreferredSize() { |
|
|
|
public int getIconHeight() { |
|
|
|
Dimension size = super.getPreferredSize(); |
|
|
|
return icon.getIconHeight() + button.pad; |
|
|
|
FontMetrics metrics = getFontMetrics(getFont()); |
|
|
|
} |
|
|
|
size.width += metrics.stringWidth(getLabelString()) + 4 * pad; |
|
|
|
|
|
|
|
return size; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|