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. 78
      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. 63
      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 java.awt.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.border.Border;
import com.github.weisj.darklaf.util.PropertyKey; import com.github.weisj.darklaf.util.PropertyKey;
@ -86,6 +87,11 @@ public class AbstractButtonLayoutDelegate extends AbstractButton {
return delegate.getHorizontalTextPosition(); return delegate.getHorizontalTextPosition();
} }
@Override
public Border getBorder() {
return delegate.getBorder();
}
@Override @Override
public Insets getInsets() { public Insets getInsets() {
return delegate.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 FontMetrics fm,
final int width, final int height) { final int width, final int height) {
Insets i = b.getInsets(); Insets i = b.getInsets();
if (!ButtonConstants.isBorderlessVariant(b)) {
i = new Insets(i.top, borderSize, i.bottom, borderSize);
}
AlignmentExt corner = DarkButtonBorder.getCornerFlag(b); AlignmentExt corner = DarkButtonBorder.getCornerFlag(b);
if (corner != null) { if (corner != null) {
@ -381,11 +378,6 @@ public class DarkButtonUI extends BasicButtonUI implements ButtonConstants {
Insets margins = b.getMargin(); Insets margins = b.getMargin();
if (!(margins instanceof UIResource)) DarkUIUtil.applyInsets(viewRect, margins); 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; textRect.x = textRect.y = textRect.width = textRect.height = 0;
iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0; iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;
// layout the text and icon // 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) { final Element root, final int descent) {
GraphicsContext config = GraphicsUtil.setupAntialiasing(g); GraphicsContext config = GraphicsUtil.setupAntialiasing(g);
g.setColor(numberingPane.getForeground()); 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(); int digits = String.valueOf(root.getElementCount()).length();
for (int i = startLine; i <= endLine; i++) { for (int i = startLine; i <= endLine; i++) {
int off = root.getElement(i).getStartOffset(); 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 static final int SCROLL_REWIND_DELAY = 1200;
protected final ScrollPopupMenu scrollPopupMenu; protected final ScrollPopupMenu scrollPopupMenu;
protected final JButton moreTabsButton; protected final DarkTabAreaButton moreTabsButton;
protected final JComponent newTabButton; protected final JComponent newTabButton;
protected final Timer timer; protected final Timer timer;
protected long lastClickEvent; 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; package com.github.weisj.darklaf.ui.tabbedpane;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionListener;
import javax.swing.*; import javax.swing.*;
import javax.swing.plaf.UIResource; import javax.swing.plaf.UIResource;
@ -38,11 +39,13 @@ public class DarkTabAreaButton extends JButton implements UIResource {
} }
@Override @Override
protected void paintComponent(final Graphics g) { public void paint(final Graphics g) {
super.paintComponent(g); super.paint(g);
paintButton(g); paintButton(g);
ui.paintTabAreaBorder(g, ui.tabPane.getTabPlacement(), 0, 0, getWidth(), getHeight()); ui.paintTabAreaBorder(g, ui.tabPane.getTabPlacement(), 0, 0, getWidth(), getHeight());
} }
protected void paintButton(final Graphics g) {} 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; th -= tabAreaInsets.top + tabAreaInsets.bottom;
break; break;
} }
JButton moreTabs = ui.scrollableTabSupport.moreTabsButton; JComponent moreTabs = ui.scrollableTabSupport.moreTabsButton;
JComponent newTab = ui.scrollableTabSupport.newTabButton; JComponent newTab = ui.scrollableTabSupport.newTabButton;
for (int i = 0; i < numChildren; i++) { for (int i = 0; i < numChildren; i++) {
@ -311,7 +311,7 @@ public class DarkTabbedPaneScrollLayout extends TabbedPaneScrollLayout {
calculateRect(i, tabBounds, metrics, verticalTabRuns, tabPlacement); calculateRect(i, tabBounds, metrics, verticalTabRuns, tabPlacement);
} }
JButton tabsButton = ui.scrollableTabSupport.moreTabsButton; JComponent tabsButton = ui.scrollableTabSupport.moreTabsButton;
Rectangle selectedBounds = ui.tabPane.getSelectedIndex() > 0 Rectangle selectedBounds = ui.tabPane.getSelectedIndex() > 0
? new Rectangle(ui.rects[ui.tabPane.getSelectedIndex()]) ? new Rectangle(ui.rects[ui.tabPane.getSelectedIndex()])
: new Rectangle(0, 0, 0, 0); : new Rectangle(0, 0, 0, 0);
@ -438,7 +438,7 @@ public class DarkTabbedPaneScrollLayout extends TabbedPaneScrollLayout {
Dimension size = ui.tabPane.getSize(); Dimension size = ui.tabPane.getSize();
Insets insets = ui.tabPane.getInsets(); Insets insets = ui.tabPane.getInsets();
Insets tabAreaInsets = ui.getTabAreaInsets(tabPlacement); Insets tabAreaInsets = ui.getTabAreaInsets(tabPlacement);
JButton tabsButton = ui.scrollableTabSupport.moreTabsButton; JComponent tabsButton = ui.scrollableTabSupport.moreTabsButton;
JComponent newTabsButton = ui.scrollableTabSupport.newTabButton; JComponent newTabsButton = ui.scrollableTabSupport.newTabButton;
if (ui.isHorizontalTabPlacement()) { if (ui.isHorizontalTabPlacement()) {
int leftMargin = 0; int leftMargin = 0;
@ -630,7 +630,7 @@ public class DarkTabbedPaneScrollLayout extends TabbedPaneScrollLayout {
} }
protected void layoutMoreTabsButton(final int tabCount) { 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.minVisible > 0 || ui.maxVisible < tabCount - 1) {
if (ui.scrollableTabSupport.moreTabsButton.isVisible()) { if (ui.scrollableTabSupport.moreTabsButton.isVisible()) {
if (ui.minVisible != ui.minVisibleOld || ui.maxVisible != ui.maxVisibleOld) { 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); return new NewTabButton(this);
} }
public JButton createMoreTabsButton() { public DarkTabAreaButton createMoreTabsButton() {
return new MoreTabsButton(this); return new MoreTabsButton(this);
} }
} }

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

@ -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) {
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() { protected String getLabelString() {
int invisible = Math.min(ui.minVisible - 1 + ui.tabPane.getTabCount() - ui.maxVisible, int invisible = Math.min(ui.minVisible - 1 + ui.tabPane.getTabCount() - ui.maxVisible,
ui.tabPane.getTabCount()); ui.tabPane.getTabCount());
return invisible >= 100 ? INFINITY : String.valueOf(invisible); return invisible >= 100 ? INFINITY : String.valueOf(invisible);
} }
@Override protected static class MoreTabsIcon implements Icon {
public Dimension getPreferredSize() {
Dimension size = super.getPreferredSize(); private final Icon icon;
FontMetrics metrics = getFontMetrics(getFont()); private final MoreTabsButton button;
size.width += metrics.stringWidth(getLabelString()) + 4 * pad;
return size; 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;
}
} }
} }

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.tabframe.TabbedPopup;
import com.github.weisj.darklaf.components.uiresource.JPanelUIResource; import com.github.weisj.darklaf.components.uiresource.JPanelUIResource;
import com.github.weisj.darklaf.ui.button.DarkButtonUI; 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.DarkTabbedPaneUI;
import com.github.weisj.darklaf.ui.tabbedpane.MoreTabsButton; import com.github.weisj.darklaf.ui.tabbedpane.MoreTabsButton;
import com.github.weisj.darklaf.ui.tabbedpane.NewTabButton; import com.github.weisj.darklaf.ui.tabbedpane.NewTabButton;
@ -239,7 +240,7 @@ public class DarkTabbedPopupUI extends DarkPanelPopupUI implements TabFrameTabbe
} }
@Override @Override
public JButton createMoreTabsButton() { public DarkTabAreaButton createMoreTabsButton() {
return new TabFrameMoreTabsButton(this); 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.textBackground = %textBackgroundSecondary
NumberingPane.currentLineForeground = %textForeground NumberingPane.currentLineForeground = %textForeground
NumberingPane.currentLineBackground = %textSelectionBackgroundSecondary NumberingPane.currentLineBackground = %textSelectionBackgroundSecondary
NumberingPane.font = Monospace-0-10

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

@ -24,41 +24,42 @@
# #
# suppress inspection "UnusedProperty" for whole file # suppress inspection "UnusedProperty" for whole file
# #
TabbedPaneUI = com.github.weisj.darklaf.ui.tabbedpane.DarkTabbedPaneUI TabbedPaneUI = com.github.weisj.darklaf.ui.tabbedpane.DarkTabbedPaneUI
TabbedPane.tabInsets = 5,3,5,3 TabbedPane.tabInsets = 5,3,5,3
TabbedPane.tabRunOverlay = 0 TabbedPane.tabRunOverlay = 0
TabbedPane.border = com.github.weisj.darklaf.ui.tabbedpane.DarkTabbedPaneBorder TabbedPane.border = com.github.weisj.darklaf.ui.tabbedpane.DarkTabbedPaneBorder
TabbedPane.borderColor = %border TabbedPane.borderColor = %border
TabbedPane.tabBorderColor = %border TabbedPane.tabBorderColor = %border
TabbedPane.accent = %highlightFillMono TabbedPane.accent = %highlightFillMono
TabbedPane.accentFocus = %highlightFillFocusSecondary TabbedPane.accentFocus = %highlightFillFocusSecondary
TabbedPane.selectedBackground = %backgroundSelected TabbedPane.selectedBackground = %backgroundSelected
TabbedPane.focus = %backgroundSelected TabbedPane.focus = %backgroundSelected
TabbedPane.hoverBackground = %backgroundHover TabbedPane.hoverBackground = %backgroundHover
TabbedPane.selectedHoverBackground = %hoverHighlightSecondary TabbedPane.selectedHoverBackground = %hoverHighlightSecondary
TabbedPane.tabAreaBackground = %background TabbedPane.tabAreaBackground = %background
TabbedPane.selectedForeground = %textForegroundHighlight TabbedPane.selectedForeground = %textForegroundHighlight
TabbedPane.disabledForeground = %textForegroundInactive TabbedPane.disabledForeground = %textForegroundInactive
TabbedPane.focusBarHeight = 3 TabbedPane.focusBarHeight = 3
TabbedPane.contentBorderInsets = 0,0,0,0 TabbedPane.contentBorderInsets = 0,0,0,0
TabbedPane.maxPopupHeight = 500 TabbedPane.maxPopupHeight = 500
TabbedPane.dropFill = %dropBackground TabbedPane.dropFill = %dropBackground
TabbedPane.dragBorderColor = %borderTertiary TabbedPane.dragBorderColor = %borderTertiary
TabbedPane.tabsOpaque = true TabbedPane.tabsOpaque = true
TabbedPane.tabsOverlapBorder = false TabbedPane.tabsOverlapBorder = false
TabbedPane.labelShift = 0 TabbedPane.labelShift = 0
TabbedPane.selectedLabelShift = 0 TabbedPane.selectedLabelShift = 0
TabbedPane.selectedTabPadInsets = 0,0,0,0 TabbedPane.selectedTabPadInsets = 0,0,0,0
TabbedPane.tabAreaInsets = 0,0,0,0 TabbedPane.tabAreaInsets = 0,0,0,0
TabbedPane.moreTabsButton.fontSize = 8 TabbedPane.moreTabsButton.font = Monospace-0-8
TabbedPane.moreTabsButton.pad = 2 TabbedPane.moreTabsButton.foreground = %textForegroundSecondary
TabbedPane.newTabButton.pad = 2 TabbedPane.moreTabsButton.pad = 2
TabbedPane.newTabButton.pad = 2
#Icons #Icons
TabbedPane.newTab.icon = navigation/add.svg[themed] TabbedPane.newTab.icon = navigation/add.svg[themed]
TabbedPane.moreTabs.icon = navigation/moreTabs.svg[themed] TabbedPane.moreTabs.icon = navigation/moreTabs.svg[themed]

Loading…
Cancel
Save