From 768c989cd229e786679d0f9524e14c7a32b91a7b Mon Sep 17 00:00:00 2001 From: weisj Date: Thu, 19 Mar 2020 23:39:52 +0100 Subject: [PATCH] Fixed tooltip flickering during fade-in. --- .../weisj/darklaf/ui/DarkPopupFactory.java | 8 ++++++-- .../darklaf/ui/tooltip/DarkTooltipBorder.java | 16 ---------------- .../weisj/darklaf/ui/tooltip/DarkTooltipUI.java | 13 ++++--------- 3 files changed, 10 insertions(+), 27 deletions(-) diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/DarkPopupFactory.java b/core/src/main/java/com/github/weisj/darklaf/ui/DarkPopupFactory.java index 8dbc0085..bb518ca9 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/DarkPopupFactory.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/DarkPopupFactory.java @@ -38,9 +38,10 @@ public class DarkPopupFactory extends PopupFactory { Popup popup = super.getPopup(owner, contents, x, y); boolean isMediumWeight = popup.getClass().getSimpleName().endsWith("MediumWeightPopup"); boolean isLightWeight = popup.getClass().getSimpleName().endsWith("LightWeightPopup"); + boolean isBalloonTooltip = contents instanceof JToolTip + && ((JToolTip) contents).getBorder() instanceof DarkTooltipBorder; if (isMediumWeight || isLightWeight) { - if (contents instanceof JToolTip - && ((JToolTip) contents).getBorder() instanceof DarkTooltipBorder) { + if (isBalloonTooltip) { // null owner forces a heavyweight popup. popup = super.getPopup(null, contents, x, y); } else if (isMediumWeight) { @@ -67,6 +68,9 @@ public class DarkPopupFactory extends PopupFactory { } else { Decorations.uninstallPopupWindow(window); } + if (isBalloonTooltip) { + window.setOpacity(0.0f); + } } return popup; } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipBorder.java b/core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipBorder.java index 4fbc2723..4150b8e9 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipBorder.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipBorder.java @@ -46,7 +46,6 @@ public class DarkTooltipBorder implements Border { false, true, true, true); private final BubbleBorder bubbleBorder; - private static final AlphaComposite COMPOSITE = AlphaComposite.getInstance(AlphaComposite.SRC_OVER); public DarkTooltipBorder() { bubbleBorder = new BubbleBorder(UIManager.getColor("ToolTip.borderColor")); @@ -88,25 +87,10 @@ public class DarkTooltipBorder implements Border { } } - protected float getAlpha(final Component c) { - if (c instanceof JComponent) { - Object alpha = ((JComponent) c).getClientProperty(DarkTooltipUI.KEY_PAINT_ALPHA); - if (alpha instanceof Float) { - return (float) alpha; - } - } - return DarkTooltipUI.MAX_ALPHA; - } - @Override public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) { - float alpha = getAlpha(c); - if (alpha == 0) return; GraphicsContext context = new GraphicsContext(g); - if (alpha != DarkTooltipUI.MAX_ALPHA) { - ((Graphics2D) g).setComposite(COMPOSITE.derive(alpha)); - } if (isPlain(c)) { g.setColor(bubbleBorder.getColor()); DarkUIUtil.drawRect(g, x, y, width, height, 1); diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipUI.java index 15341fa8..7d70689c 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipUI.java @@ -54,10 +54,8 @@ public class DarkTooltipUI extends BasicToolTipUI implements PropertyChangeListe public static final String VARIANT_BALLOON = "balloon"; public static final String VARIANT_PLAIN_BALLOON = "plainBalloon"; public static final String TIP_TEXT_PROPERTY = "tiptext"; - public static final String KEY_PAINT_ALPHA = KEY_PREFIX + "paintAlpha"; public static final String KEY_CONTEXT = KEY_PREFIX + "toolTipContext"; static final float MAX_ALPHA = 1.0f; - private static final AlphaComposite COMPOSITE = AlphaComposite.getInstance(AlphaComposite.SRC_OVER); private Animator fadeAnimator; private float alpha = 0; @@ -199,12 +197,7 @@ public class DarkTooltipUI extends BasicToolTipUI implements PropertyChangeListe fadeAnimator.reset(); fadeAnimator.resume(); } - toolTip.putClientProperty(KEY_PAINT_ALPHA, alpha); - if (alpha == 0) return; GraphicsContext config = new GraphicsContext(g); - if (alpha != MAX_ALPHA) { - ((Graphics2D) g).setComposite(COMPOSITE.derive(alpha)); - } g.setColor(c.getBackground()); if (c.getBorder() instanceof DarkTooltipBorder) { Area area = ((DarkTooltipBorder) c.getBorder()).getBackgroundArea(c, c.getWidth(), c.getHeight()); @@ -374,13 +367,15 @@ public class DarkTooltipUI extends BasicToolTipUI implements PropertyChangeListe @Override public void paintNow(final int frame, final int totalFrames, final int cycle) { alpha = ((float) frame * MAX_ALPHA) / totalFrames; - toolTip.paintImmediately(0, 0, toolTip.getWidth(), toolTip.getHeight()); + Window window = SwingUtilities.getWindowAncestor(toolTip); + if (window != null) window.setOpacity(alpha); } @Override protected void paintCycleEnd() { alpha = MAX_ALPHA; - toolTip.paintImmediately(0, 0, toolTip.getWidth(), toolTip.getHeight()); + Window window = SwingUtilities.getWindowAncestor(toolTip); + if (window != null) window.setOpacity(alpha); } } }