From 6c943a44660b8e95a9801498c6abe009f409f790 Mon Sep 17 00:00:00 2001 From: weisj Date: Tue, 16 Jun 2020 14:10:01 +0200 Subject: [PATCH] Improved more tabs button for tabbedPane Made font of numberingPane and more tabs button ui properties. --- .../AbstractButtonLayoutDelegate.java | 6 ++ .../weisj/darklaf/ui/button/DarkButtonUI.java | 8 -- .../ui/numberingpane/DarkNumberingPaneUI.java | 7 ++ .../tabbedpane/DarkScrollableTabSupport.java | 2 +- .../ui/tabbedpane/DarkTabAreaButton.java | 7 +- .../DarkTabbedPaneScrollLayout.java | 8 +- .../ui/tabbedpane/DarkTabbedPaneUI.java | 2 +- .../darklaf/ui/tabbedpane/MoreTabsButton.java | 78 +++++++++---------- .../ui/tabframe/DarkTabbedPopupUI.java | 3 +- .../properties/ui/numberingPane.properties | 1 + .../properties/ui/tabbedPane.properties | 63 +++++++-------- 11 files changed, 95 insertions(+), 90 deletions(-) diff --git a/core/src/main/java/com/github/weisj/darklaf/delegate/AbstractButtonLayoutDelegate.java b/core/src/main/java/com/github/weisj/darklaf/delegate/AbstractButtonLayoutDelegate.java index bade0404..16a1a6ad 100644 --- a/core/src/main/java/com/github/weisj/darklaf/delegate/AbstractButtonLayoutDelegate.java +++ b/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(); diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java index 5b4b889f..a8bdfe0e 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java +++ b/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 diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/numberingpane/DarkNumberingPaneUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/numberingpane/DarkNumberingPaneUI.java index 98bc5a19..31c77b28 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/numberingpane/DarkNumberingPaneUI.java +++ b/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(); diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkScrollableTabSupport.java b/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkScrollableTabSupport.java index 38a2dd26..18c08b46 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkScrollableTabSupport.java +++ b/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; diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabAreaButton.java b/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabAreaButton.java index 02c6a4ed..4ccf3747 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabAreaButton.java +++ b/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) {} } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneScrollLayout.java b/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneScrollLayout.java index 4e9d9afd..ae0e55b2 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneScrollLayout.java +++ b/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) { diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUI.java index 274e0ab4..208080af 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUI.java +++ b/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); } } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/MoreTabsButton.java b/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/MoreTabsButton.java index 54d72e22..3f26a0de 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/MoreTabsButton.java +++ b/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; - - 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; - } - - 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(); - } - 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 Dimension getPreferredSize() { - Dimension size = super.getPreferredSize(); - FontMetrics metrics = getFontMetrics(getFont()); - size.width += metrics.stringWidth(getLabelString()) + 4 * pad; - return size; + 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; + } + + @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()); + } + + @Override + public int getIconWidth() { + int textWidth = button.getFontMetrics(button.getFont()).stringWidth(button.getLabelString()); + return icon.getIconWidth() + textWidth + button.pad; + } + + @Override + public int getIconHeight() { + return icon.getIconHeight() + button.pad; + } } } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabbedPopupUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabbedPopupUI.java index 16ed041c..268f99ab 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabbedPopupUI.java +++ b/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); } } diff --git a/core/src/main/resources/com/github/weisj/darklaf/properties/ui/numberingPane.properties b/core/src/main/resources/com/github/weisj/darklaf/properties/ui/numberingPane.properties index ceb3c424..619d23c5 100644 --- a/core/src/main/resources/com/github/weisj/darklaf/properties/ui/numberingPane.properties +++ b/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 diff --git a/core/src/main/resources/com/github/weisj/darklaf/properties/ui/tabbedPane.properties b/core/src/main/resources/com/github/weisj/darklaf/properties/ui/tabbedPane.properties index b3e2e696..698b81d5 100644 --- a/core/src/main/resources/com/github/weisj/darklaf/properties/ui/tabbedPane.properties +++ b/core/src/main/resources/com/github/weisj/darklaf/properties/ui/tabbedPane.properties @@ -24,41 +24,42 @@ # # suppress inspection "UnusedProperty" for whole file # -TabbedPaneUI = com.github.weisj.darklaf.ui.tabbedpane.DarkTabbedPaneUI -TabbedPane.tabInsets = 5,3,5,3 -TabbedPane.tabRunOverlay = 0 -TabbedPane.border = com.github.weisj.darklaf.ui.tabbedpane.DarkTabbedPaneBorder +TabbedPaneUI = com.github.weisj.darklaf.ui.tabbedpane.DarkTabbedPaneUI +TabbedPane.tabInsets = 5,3,5,3 +TabbedPane.tabRunOverlay = 0 +TabbedPane.border = com.github.weisj.darklaf.ui.tabbedpane.DarkTabbedPaneBorder -TabbedPane.borderColor = %border -TabbedPane.tabBorderColor = %border -TabbedPane.accent = %highlightFillMono -TabbedPane.accentFocus = %highlightFillFocusSecondary -TabbedPane.selectedBackground = %backgroundSelected -TabbedPane.focus = %backgroundSelected -TabbedPane.hoverBackground = %backgroundHover -TabbedPane.selectedHoverBackground = %hoverHighlightSecondary -TabbedPane.tabAreaBackground = %background -TabbedPane.selectedForeground = %textForegroundHighlight -TabbedPane.disabledForeground = %textForegroundInactive +TabbedPane.borderColor = %border +TabbedPane.tabBorderColor = %border +TabbedPane.accent = %highlightFillMono +TabbedPane.accentFocus = %highlightFillFocusSecondary +TabbedPane.selectedBackground = %backgroundSelected +TabbedPane.focus = %backgroundSelected +TabbedPane.hoverBackground = %backgroundHover +TabbedPane.selectedHoverBackground = %hoverHighlightSecondary +TabbedPane.tabAreaBackground = %background +TabbedPane.selectedForeground = %textForegroundHighlight +TabbedPane.disabledForeground = %textForegroundInactive -TabbedPane.focusBarHeight = 3 -TabbedPane.contentBorderInsets = 0,0,0,0 +TabbedPane.focusBarHeight = 3 +TabbedPane.contentBorderInsets = 0,0,0,0 -TabbedPane.maxPopupHeight = 500 -TabbedPane.dropFill = %dropBackground -TabbedPane.dragBorderColor = %borderTertiary +TabbedPane.maxPopupHeight = 500 +TabbedPane.dropFill = %dropBackground +TabbedPane.dragBorderColor = %borderTertiary -TabbedPane.tabsOpaque = true -TabbedPane.tabsOverlapBorder = false -TabbedPane.labelShift = 0 -TabbedPane.selectedLabelShift = 0 -TabbedPane.selectedTabPadInsets = 0,0,0,0 -TabbedPane.tabAreaInsets = 0,0,0,0 +TabbedPane.tabsOpaque = true +TabbedPane.tabsOverlapBorder = false +TabbedPane.labelShift = 0 +TabbedPane.selectedLabelShift = 0 +TabbedPane.selectedTabPadInsets = 0,0,0,0 +TabbedPane.tabAreaInsets = 0,0,0,0 -TabbedPane.moreTabsButton.fontSize = 8 -TabbedPane.moreTabsButton.pad = 2 -TabbedPane.newTabButton.pad = 2 +TabbedPane.moreTabsButton.font = Monospace-0-8 +TabbedPane.moreTabsButton.foreground = %textForegroundSecondary +TabbedPane.moreTabsButton.pad = 2 +TabbedPane.newTabButton.pad = 2 #Icons -TabbedPane.newTab.icon = navigation/add.svg[themed] -TabbedPane.moreTabs.icon = navigation/moreTabs.svg[themed] +TabbedPane.newTab.icon = navigation/add.svg[themed] +TabbedPane.moreTabs.icon = navigation/moreTabs.svg[themed]