From 78aff654eca981f2c9df0d140e4d0be4c69f14d3 Mon Sep 17 00:00:00 2001 From: ShadelessFox Date: Thu, 14 Mar 2024 03:22:30 +0100 Subject: [PATCH] Application: Replace hand-crafted vertical tabs with FlatLaf ones --- .../platform/ui/controls/ToolTabbedPane.java | 13 --- .../platform/ui/controls/VerticalLabel.java | 26 ------ .../controls/plaf/FlatToolTabbedPaneUI.java | 23 ----- .../ui/controls/plaf/FlatVerticalLabelUI.java | 83 ------------------- .../main/resources/themes/FlatLaf.properties | 2 +- 5 files changed, 1 insertion(+), 146 deletions(-) delete mode 100644 modules/platform-ui/src/main/java/com/shade/platform/ui/controls/VerticalLabel.java delete mode 100644 modules/platform-ui/src/main/java/com/shade/platform/ui/controls/plaf/FlatVerticalLabelUI.java diff --git a/modules/platform-ui/src/main/java/com/shade/platform/ui/controls/ToolTabbedPane.java b/modules/platform-ui/src/main/java/com/shade/platform/ui/controls/ToolTabbedPane.java index 4ac4e6304..848043717 100644 --- a/modules/platform-ui/src/main/java/com/shade/platform/ui/controls/ToolTabbedPane.java +++ b/modules/platform-ui/src/main/java/com/shade/platform/ui/controls/ToolTabbedPane.java @@ -3,7 +3,6 @@ import com.shade.util.NotNull; import javax.swing.*; -import java.awt.*; import java.util.Objects; public class ToolTabbedPane extends JTabbedPane { @@ -64,18 +63,6 @@ public void minimizePane() { repaint(); } - @Override - public void insertTab(String title, Icon icon, Component component, String tip, int index) { - super.insertTab(title, icon, component, tip, index); - - if (tabPlacement == LEFT || tabPlacement == RIGHT) { - final VerticalLabel label = new VerticalLabel(title); - label.setClockwise(tabPlacement == RIGHT); - label.setIcon(icon); - setTabComponentAt(index, label); - } - } - private int computeMinimizedDividerLocation(@NotNull JSplitPane pane) { return switch (tabPlacement) { case LEFT, TOP -> TAB_HEADER_SIZE; diff --git a/modules/platform-ui/src/main/java/com/shade/platform/ui/controls/VerticalLabel.java b/modules/platform-ui/src/main/java/com/shade/platform/ui/controls/VerticalLabel.java deleted file mode 100644 index e76a52f46..000000000 --- a/modules/platform-ui/src/main/java/com/shade/platform/ui/controls/VerticalLabel.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.shade.platform.ui.controls; - -import com.shade.util.Nullable; - -import javax.swing.*; - -public class VerticalLabel extends JLabel { - private boolean clockwise; - - public VerticalLabel(@Nullable String text) { - super(text); - } - - @Override - public String getUIClassID() { - return "VerticalLabelUI"; - } - - public boolean isClockwise() { - return clockwise; - } - - public void setClockwise(boolean clockwise) { - this.clockwise = clockwise; - } -} diff --git a/modules/platform-ui/src/main/java/com/shade/platform/ui/controls/plaf/FlatToolTabbedPaneUI.java b/modules/platform-ui/src/main/java/com/shade/platform/ui/controls/plaf/FlatToolTabbedPaneUI.java index dc0723ece..a275d95fb 100644 --- a/modules/platform-ui/src/main/java/com/shade/platform/ui/controls/plaf/FlatToolTabbedPaneUI.java +++ b/modules/platform-ui/src/main/java/com/shade/platform/ui/controls/plaf/FlatToolTabbedPaneUI.java @@ -66,29 +66,6 @@ public void mouseExited(MouseEvent e) { }; } - @SuppressWarnings("SuspiciousNameCombination") - @Override - protected int calculateTabWidth(int tabPlacement, int tabIndex, FontMetrics metrics) { - if (tabPlacement == LEFT || tabPlacement == RIGHT) { - return tabHeight; - } else { - return super.calculateTabWidth(tabPlacement, tabIndex, metrics); - } - - } - - @SuppressWarnings("SuspiciousNameCombination") - @Override - protected Insets getTabInsets(int tabPlacement, int tabIndex) { - final Insets insets = super.getTabInsets(tabPlacement, tabIndex); - - if (tabPlacement == LEFT || tabPlacement == RIGHT) { - return new Insets(insets.right, insets.top, insets.left, insets.bottom); - } else { - return insets; - } - } - private class CompactTabbedPaneLayout extends FlatTabbedPaneLayout { @Override protected boolean isContentEmpty() { diff --git a/modules/platform-ui/src/main/java/com/shade/platform/ui/controls/plaf/FlatVerticalLabelUI.java b/modules/platform-ui/src/main/java/com/shade/platform/ui/controls/plaf/FlatVerticalLabelUI.java deleted file mode 100644 index 988a8083d..000000000 --- a/modules/platform-ui/src/main/java/com/shade/platform/ui/controls/plaf/FlatVerticalLabelUI.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.shade.platform.ui.controls.plaf; - -import com.formdev.flatlaf.ui.FlatLabelUI; -import com.shade.platform.ui.controls.VerticalLabel; -import com.shade.util.NotNull; - -import javax.swing.*; -import javax.swing.plaf.ComponentUI; -import java.awt.*; -import java.awt.geom.AffineTransform; - -public class FlatVerticalLabelUI extends FlatLabelUI { - private final Rectangle paintIconR = new Rectangle(); - private final Rectangle paintTextR = new Rectangle(); - private final Rectangle paintViewR = new Rectangle(); - - public FlatVerticalLabelUI() { - super(false); - } - - @NotNull - public static ComponentUI createUI(@NotNull JComponent c) { - return new FlatVerticalLabelUI(); - } - - @Override - public void paint(Graphics g, JComponent c) { - final VerticalLabel label = (VerticalLabel) c; - final String text = label.getText(); - final Icon icon = label.isEnabled() ? label.getIcon() : label.getDisabledIcon(); - - if (icon == null && text == null) { - return; - } - - final Insets insets = c.getInsets(); - final FontMetrics fm = g.getFontMetrics(); - - paintViewR.x = insets.left; - paintViewR.y = insets.top; - paintViewR.height = c.getWidth() - (insets.left + insets.right); - paintViewR.width = c.getHeight() - (insets.top + insets.bottom); - - paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0; - paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0; - - final String clippedText = layoutCL(label, fm, text, icon, paintViewR, paintIconR, paintTextR); - final Graphics2D g2 = (Graphics2D) g; - final AffineTransform tr = g2.getTransform(); - - if (icon != null) { - icon.paintIcon(c, g, paintIconR.x, paintIconR.y + c.getHeight() - icon.getIconHeight()); - } - - if (label.isClockwise()) { - g2.rotate(Math.PI / 2); - g2.translate(0, -c.getWidth()); - } else { - g2.rotate(-Math.PI / 2); - g2.translate(-c.getHeight(), 0); - } - - if (text != null) { - final int textX = paintTextR.x; - final int textY = paintTextR.y + fm.getAscent(); - - if (label.isEnabled()) { - paintEnabledText(label, g, clippedText, textX, textY); - } else { - paintDisabledText(label, g, clippedText, textX, textY); - } - } - - g2.setTransform(tr); - } - - @SuppressWarnings("SuspiciousNameCombination") - @Override - public Dimension getPreferredSize(JComponent c) { - final Dimension size = super.getPreferredSize(c); - return new Dimension(size.height, size.width); - } -} diff --git a/modules/platform-ui/src/main/resources/themes/FlatLaf.properties b/modules/platform-ui/src/main/resources/themes/FlatLaf.properties index 5125f4ec4..15740edea 100644 --- a/modules/platform-ui/src/main/resources/themes/FlatLaf.properties +++ b/modules/platform-ui/src/main/resources/themes/FlatLaf.properties @@ -15,7 +15,6 @@ RangeSliderUI = com.shade.platform.ui.controls.plaf.FlatRangeSliderUI TreeUI = com.shade.platform.ui.controls.tree.TreeUI ToolTipUI = com.shade.platform.ui.controls.plaf.FlatOutlineToolTipUI ToolTabbedPaneUI = com.shade.platform.ui.controls.plaf.FlatToolTabbedPaneUI -VerticalLabelUI = com.shade.platform.ui.controls.plaf.FlatVerticalLabelUI LabeledSeparatorUI = com.shade.platform.ui.controls.plaf.LabeledSeparatorUI ThinSplitPaneUI = com.shade.platform.ui.controls.plaf.FlatThinSplitPaneUI @@ -23,6 +22,7 @@ ThinSplitPaneUI = com.shade.platform.ui.controls.plaf.FlatThinSplitPaneUI TitlePane.unifiedBackground = false TitlePane.buttonSize = 44,28 TabbedPane.tabHeight = 24 +TabbedPane.tabRotation = auto Component.hideMnemonics = false Tree.showsRootHandles = true SplitPane.dividerSize = 7