Browse Source

Improved more tabs button for tabbedPane

Made font of numberingPane and more tabs button ui properties.
pull/188/head
weisj 5 years ago
parent
commit
6c943a4466
  1. 6
      core/src/main/java/com/github/weisj/darklaf/delegate/AbstractButtonLayoutDelegate.java
  2. 8
      core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java
  3. 7
      core/src/main/java/com/github/weisj/darklaf/ui/numberingpane/DarkNumberingPaneUI.java
  4. 2
      core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkScrollableTabSupport.java
  5. 7
      core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabAreaButton.java
  6. 8
      core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneScrollLayout.java
  7. 2
      core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUI.java
  8. 74
      core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/MoreTabsButton.java
  9. 3
      core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabbedPopupUI.java
  10. 1
      core/src/main/resources/com/github/weisj/darklaf/properties/ui/numberingPane.properties
  11. 3
      core/src/main/resources/com/github/weisj/darklaf/properties/ui/tabbedPane.properties

6
core/src/main/java/com/github/weisj/darklaf/delegate/AbstractButtonLayoutDelegate.java

@ -29,6 +29,7 @@ import static java.awt.RenderingHints.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.Border;
import com.github.weisj.darklaf.util.PropertyKey;
@ -86,6 +87,11 @@ public class AbstractButtonLayoutDelegate extends AbstractButton {
return delegate.getHorizontalTextPosition();
}
@Override
public Border getBorder() {
return delegate.getBorder();
}
@Override
public Insets getInsets() {
return delegate.getInsets();

8
core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java

@ -361,9 +361,6 @@ public class DarkButtonUI extends BasicButtonUI implements ButtonConstants {
final FontMetrics fm,
final int width, final int height) {
Insets i = b.getInsets();
if (!ButtonConstants.isBorderlessVariant(b)) {
i = new Insets(i.top, borderSize, i.bottom, borderSize);
}
AlignmentExt corner = DarkButtonBorder.getCornerFlag(b);
if (corner != null) {
@ -381,11 +378,6 @@ public class DarkButtonUI extends BasicButtonUI implements ButtonConstants {
Insets margins = b.getMargin();
if (!(margins instanceof UIResource)) DarkUIUtil.applyInsets(viewRect, margins);
viewRect.x = i.left;
viewRect.y = i.top;
viewRect.width = width - (i.right + i.left);
viewRect.height = height - (i.bottom + i.top);
textRect.x = textRect.y = textRect.width = textRect.height = 0;
iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;
// layout the text and icon

7
core/src/main/java/com/github/weisj/darklaf/ui/numberingpane/DarkNumberingPaneUI.java

@ -192,6 +192,13 @@ public class DarkNumberingPaneUI extends ComponentUI {
final Element root, final int descent) {
GraphicsContext config = GraphicsUtil.setupAntialiasing(g);
g.setColor(numberingPane.getForeground());
Font font = numberingPane.getTextComponent().getFont();
if (font != null) {
float newSize = (float) font.getSize() - 1;
if (newSize > 0) {
g.setFont(numberingPane.getFont().deriveFont(newSize));
}
}
int digits = String.valueOf(root.getElementCount()).length();
for (int i = startLine; i <= endLine; i++) {
int off = root.getElement(i).getStartOffset();

2
core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkScrollableTabSupport.java

@ -42,7 +42,7 @@ public class DarkScrollableTabSupport extends ScrollableTabSupport implements Mo
protected static final int SCROLL_REWIND_DELAY = 1200;
protected final ScrollPopupMenu scrollPopupMenu;
protected final JButton moreTabsButton;
protected final DarkTabAreaButton moreTabsButton;
protected final JComponent newTabButton;
protected final Timer timer;
protected long lastClickEvent;

7
core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabAreaButton.java

@ -25,6 +25,7 @@
package com.github.weisj.darklaf.ui.tabbedpane;
import java.awt.*;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.plaf.UIResource;
@ -38,11 +39,13 @@ public class DarkTabAreaButton extends JButton implements UIResource {
}
@Override
protected void paintComponent(final Graphics g) {
super.paintComponent(g);
public void paint(final Graphics g) {
super.paint(g);
paintButton(g);
ui.paintTabAreaBorder(g, ui.tabPane.getTabPlacement(), 0, 0, getWidth(), getHeight());
}
protected void paintButton(final Graphics g) {}
public void addActionListener(final ActionListener actionListener) {}
}

8
core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneScrollLayout.java

@ -138,7 +138,7 @@ public class DarkTabbedPaneScrollLayout extends TabbedPaneScrollLayout {
th -= tabAreaInsets.top + tabAreaInsets.bottom;
break;
}
JButton moreTabs = ui.scrollableTabSupport.moreTabsButton;
JComponent moreTabs = ui.scrollableTabSupport.moreTabsButton;
JComponent newTab = ui.scrollableTabSupport.newTabButton;
for (int i = 0; i < numChildren; i++) {
@ -311,7 +311,7 @@ public class DarkTabbedPaneScrollLayout extends TabbedPaneScrollLayout {
calculateRect(i, tabBounds, metrics, verticalTabRuns, tabPlacement);
}
JButton tabsButton = ui.scrollableTabSupport.moreTabsButton;
JComponent tabsButton = ui.scrollableTabSupport.moreTabsButton;
Rectangle selectedBounds = ui.tabPane.getSelectedIndex() > 0
? new Rectangle(ui.rects[ui.tabPane.getSelectedIndex()])
: new Rectangle(0, 0, 0, 0);
@ -438,7 +438,7 @@ public class DarkTabbedPaneScrollLayout extends TabbedPaneScrollLayout {
Dimension size = ui.tabPane.getSize();
Insets insets = ui.tabPane.getInsets();
Insets tabAreaInsets = ui.getTabAreaInsets(tabPlacement);
JButton tabsButton = ui.scrollableTabSupport.moreTabsButton;
JComponent tabsButton = ui.scrollableTabSupport.moreTabsButton;
JComponent newTabsButton = ui.scrollableTabSupport.newTabButton;
if (ui.isHorizontalTabPlacement()) {
int leftMargin = 0;
@ -630,7 +630,7 @@ public class DarkTabbedPaneScrollLayout extends TabbedPaneScrollLayout {
}
protected void layoutMoreTabsButton(final int tabCount) {
final JButton button = ui.scrollableTabSupport.moreTabsButton;
final JComponent button = ui.scrollableTabSupport.moreTabsButton;
if (ui.minVisible > 0 || ui.maxVisible < tabCount - 1) {
if (ui.scrollableTabSupport.moreTabsButton.isVisible()) {
if (ui.minVisible != ui.minVisibleOld || ui.maxVisible != ui.maxVisibleOld) {

2
core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUI.java

@ -830,7 +830,7 @@ public class DarkTabbedPaneUI extends DarkTabbedPaneUIBridge {
return new NewTabButton(this);
}
public JButton createMoreTabsButton() {
public DarkTabAreaButton createMoreTabsButton() {
return new MoreTabsButton(this);
}
}

74
core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/MoreTabsButton.java

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

3
core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabbedPopupUI.java

@ -37,6 +37,7 @@ import com.github.weisj.darklaf.components.tabframe.TabFrameTabbedPopupUI;
import com.github.weisj.darklaf.components.tabframe.TabbedPopup;
import com.github.weisj.darklaf.components.uiresource.JPanelUIResource;
import com.github.weisj.darklaf.ui.button.DarkButtonUI;
import com.github.weisj.darklaf.ui.tabbedpane.DarkTabAreaButton;
import com.github.weisj.darklaf.ui.tabbedpane.DarkTabbedPaneUI;
import com.github.weisj.darklaf.ui.tabbedpane.MoreTabsButton;
import com.github.weisj.darklaf.ui.tabbedpane.NewTabButton;
@ -239,7 +240,7 @@ public class DarkTabbedPopupUI extends DarkPanelPopupUI implements TabFrameTabbe
}
@Override
public JButton createMoreTabsButton() {
public DarkTabAreaButton createMoreTabsButton() {
return new TabFrameMoreTabsButton(this);
}
}

1
core/src/main/resources/com/github/weisj/darklaf/properties/ui/numberingPane.properties

@ -32,3 +32,4 @@ NumberingPane.background = %textBackgroundSecondaryInactive
NumberingPane.textBackground = %textBackgroundSecondary
NumberingPane.currentLineForeground = %textForeground
NumberingPane.currentLineBackground = %textSelectionBackgroundSecondary
NumberingPane.font = Monospace-0-10

3
core/src/main/resources/com/github/weisj/darklaf/properties/ui/tabbedPane.properties

@ -55,7 +55,8 @@ TabbedPane.selectedLabelShift = 0
TabbedPane.selectedTabPadInsets = 0,0,0,0
TabbedPane.tabAreaInsets = 0,0,0,0
TabbedPane.moreTabsButton.fontSize = 8
TabbedPane.moreTabsButton.font = Monospace-0-8
TabbedPane.moreTabsButton.foreground = %textForegroundSecondary
TabbedPane.moreTabsButton.pad = 2
TabbedPane.newTabButton.pad = 2

Loading…
Cancel
Save