diff --git a/core/src/main/java/com/github/weisj/darklaf/components/ComponentHelper.java b/core/src/main/java/com/github/weisj/darklaf/components/ComponentHelper.java index 763ec6ed..7d7979e7 100644 --- a/core/src/main/java/com/github/weisj/darklaf/components/ComponentHelper.java +++ b/core/src/main/java/com/github/weisj/darklaf/components/ComponentHelper.java @@ -22,8 +22,6 @@ package com.github.weisj.darklaf.components; -import java.awt.*; - import javax.swing.*; import com.github.weisj.darklaf.components.button.JSplitButton; @@ -55,6 +53,12 @@ public class ComponentHelper { return button; } + public static T createIconOnlyButton(final T button, final Icon enabled, + final Icon disabled) { + setup(button, enabled, disabled); + return button; + } + private static void setup(final AbstractButton b, final Icon enabled, final Icon disabled) { b.setIcon(enabled); b.setDisabledIcon(disabled); diff --git a/core/src/main/java/com/github/weisj/darklaf/layout/LayoutHelper.java b/core/src/main/java/com/github/weisj/darklaf/layout/LayoutHelper.java index 8c544b95..dac2dcde 100644 --- a/core/src/main/java/com/github/weisj/darklaf/layout/LayoutHelper.java +++ b/core/src/main/java/com/github/weisj/darklaf/layout/LayoutHelper.java @@ -182,12 +182,12 @@ public class LayoutHelper { }); } + public static JComponent createPanelWithOverlay(final JComponent content, final JComponent overlayContent) { return createPanelWithOverlay(content, overlayContent, Alignment.NORTH_EAST, createEmptyContainerInsets()); } - public static JComponent createPanelWithOverlay(final JComponent content, - final JComponent overlayContent, + public static JComponent createPanelWithOverlay(final JComponent content, final JComponent overlayContent, final Alignment alignment, final Insets padding) { return createPanelWithOverlay(content, overlayContent, (r, c) -> { Dimension prefSize = c.getPreferredSize(); @@ -248,6 +248,19 @@ public class LayoutHelper { }); } + public static OverlayScrollPane createScrollPaneWithHoverOverlay(final JComponent content, + final JComponent overlayContent, + final Alignment alignment, final Supplier paddingSupplier) { + HoveringPanel hoveringPanel = new HoveringPanel() { + @Override + public boolean isVisible() { + return overlayContent.isVisible(); + } + }; + hoveringPanel.add(overlayContent); + return createScrollPaneWithOverlay(content, hoveringPanel, alignment, paddingSupplier); + } + public static OverlayScrollPane createScrollPaneWithOverlay(final JComponent content, final JComponent overlayContent, final Alignment alignment, final Supplier paddingSupplier) { @@ -259,26 +272,34 @@ public class LayoutHelper { }); } + public static OverlayScrollPane createScrollPaneWithHoverOverlay(final JComponent content, + final JComponent overlayContent, + final BiFunction layoutFunction) { + HoveringPanel hoveringPanel = new HoveringPanel(); + hoveringPanel.add(overlayContent); + return createScrollPaneWithOverlay(content, hoveringPanel, (r, c) -> { + hoveringPanel.setVisible(overlayContent.isVisible()); + return layoutFunction.apply(r, hoveringPanel); + }); + } + public static OverlayScrollPane createScrollPaneWithOverlay(final JComponent content, final JComponent overlayContent, final BiFunction layoutFunction) { return new OverlayScrollPane(content) { - private final HoveringPanel hoveringPanel = new HoveringPanel(); - { - hoveringPanel.add(overlayContent); - add(hoveringPanel, Integer.valueOf(JLayeredPane.MODAL_LAYER - 1)); + add(overlayContent, Integer.valueOf(JLayeredPane.MODAL_LAYER - 1)); } @Override public void doLayout() { super.doLayout(); Component viewport = getScrollPane().getViewport(); - hoveringPanel.setBounds( - layoutFunction.apply(getLayoutRect(viewport.getWidth(), viewport.getHeight()), hoveringPanel)); - hoveringPanel.doLayout(); - hoveringPanel.setVisible(overlayContent.isVisible()); + overlayContent.setBounds( + layoutFunction.apply(getLayoutRect(viewport.getWidth(), viewport.getHeight()), overlayContent)); + overlayContent.doLayout(); + overlayContent.setVisible(overlayContent.isVisible()); } private Rectangle getLayoutRect(final int width, final int height) { @@ -299,8 +320,8 @@ public class LayoutHelper { @Override public Dimension getPreferredSize() { Dimension dim = super.getPreferredSize(); - if (hoveringPanel.isVisible()) { - Rectangle layoutRect = layoutFunction.apply(getLayoutRect(dim.width, dim.height), hoveringPanel); + if (overlayContent.isVisible()) { + Rectangle layoutRect = layoutFunction.apply(getLayoutRect(dim.width, dim.height), overlayContent); dim.width = Math.max(dim.width, layoutRect.x + layoutRect.width); dim.height = Math.max(dim.height, layoutRect.y + layoutRect.height); } diff --git a/core/src/test/java/theme/ThemeEditor.java b/core/src/test/java/theme/ThemeEditor.java index 71aca478..bf7ed786 100644 --- a/core/src/test/java/theme/ThemeEditor.java +++ b/core/src/test/java/theme/ThemeEditor.java @@ -294,11 +294,12 @@ public class ThemeEditor extends JPanel { if (!keyEditable) { sp = new OverlayScrollPane(table); } else { - sp = LayoutHelper.createScrollPaneWithOverlay(table, createButtonPanel(table), Alignment.NORTH_EAST, () -> { - Insets ins = new Insets(10, 10, 10, 10); - ins.right += table.getColumnModel().getColumn(0).getWidth(); - return ins; - }); + sp = LayoutHelper.createScrollPaneWithHoverOverlay(table, createButtonPanel(table), + Alignment.NORTH_EAST, () -> { + Insets ins = new Insets(10, 10, 10, 10); + ins.right += table.getColumnModel().getColumn(0).getWidth(); + return ins; + }); } sp.getScrollPane().setBorder(DarkBorders.createLineBorder(0, 0, 1, 0)); return sp;