Browse Source

Allow to omit the hovering panel for scrollpane overlays.

pull/222/head
weisj 4 years ago
parent
commit
200356ad69
  1. 8
      core/src/main/java/com/github/weisj/darklaf/components/ComponentHelper.java
  2. 45
      core/src/main/java/com/github/weisj/darklaf/layout/LayoutHelper.java
  3. 3
      core/src/test/java/theme/ThemeEditor.java

8
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 extends AbstractButton> 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);

45
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<Insets> 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<Insets> paddingSupplier) {
@ -259,26 +272,34 @@ public class LayoutHelper {
});
}
public static OverlayScrollPane createScrollPaneWithHoverOverlay(final JComponent content,
final JComponent overlayContent,
final BiFunction<Rectangle, JComponent, Rectangle> 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<Rectangle, JComponent, Rectangle> 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);
}

3
core/src/test/java/theme/ThemeEditor.java

@ -294,7 +294,8 @@ public class ThemeEditor extends JPanel {
if (!keyEditable) {
sp = new OverlayScrollPane(table);
} else {
sp = LayoutHelper.createScrollPaneWithOverlay(table, createButtonPanel(table), Alignment.NORTH_EAST, () -> {
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;

Loading…
Cancel
Save