Browse Source

Fixed tooltip flickering during fade-in.

pull/105/head
weisj 5 years ago
parent
commit
768c989cd2
  1. 8
      core/src/main/java/com/github/weisj/darklaf/ui/DarkPopupFactory.java
  2. 16
      core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipBorder.java
  3. 13
      core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipUI.java

8
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); Popup popup = super.getPopup(owner, contents, x, y);
boolean isMediumWeight = popup.getClass().getSimpleName().endsWith("MediumWeightPopup"); boolean isMediumWeight = popup.getClass().getSimpleName().endsWith("MediumWeightPopup");
boolean isLightWeight = popup.getClass().getSimpleName().endsWith("LightWeightPopup"); boolean isLightWeight = popup.getClass().getSimpleName().endsWith("LightWeightPopup");
boolean isBalloonTooltip = contents instanceof JToolTip
&& ((JToolTip) contents).getBorder() instanceof DarkTooltipBorder;
if (isMediumWeight || isLightWeight) { if (isMediumWeight || isLightWeight) {
if (contents instanceof JToolTip if (isBalloonTooltip) {
&& ((JToolTip) contents).getBorder() instanceof DarkTooltipBorder) {
// null owner forces a heavyweight popup. // null owner forces a heavyweight popup.
popup = super.getPopup(null, contents, x, y); popup = super.getPopup(null, contents, x, y);
} else if (isMediumWeight) { } else if (isMediumWeight) {
@ -67,6 +68,9 @@ public class DarkPopupFactory extends PopupFactory {
} else { } else {
Decorations.uninstallPopupWindow(window); Decorations.uninstallPopupWindow(window);
} }
if (isBalloonTooltip) {
window.setOpacity(0.0f);
}
} }
return popup; return popup;
} }

16
core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipBorder.java

@ -46,7 +46,6 @@ public class DarkTooltipBorder implements Border {
false, true, false, true,
true, true); true, true);
private final BubbleBorder bubbleBorder; private final BubbleBorder bubbleBorder;
private static final AlphaComposite COMPOSITE = AlphaComposite.getInstance(AlphaComposite.SRC_OVER);
public DarkTooltipBorder() { public DarkTooltipBorder() {
bubbleBorder = new BubbleBorder(UIManager.getColor("ToolTip.borderColor")); 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 @Override
public void paintBorder(final Component c, final Graphics g, public void paintBorder(final Component c, final Graphics g,
final int x, final int y, final int width, final int height) { 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); GraphicsContext context = new GraphicsContext(g);
if (alpha != DarkTooltipUI.MAX_ALPHA) {
((Graphics2D) g).setComposite(COMPOSITE.derive(alpha));
}
if (isPlain(c)) { if (isPlain(c)) {
g.setColor(bubbleBorder.getColor()); g.setColor(bubbleBorder.getColor());
DarkUIUtil.drawRect(g, x, y, width, height, 1); DarkUIUtil.drawRect(g, x, y, width, height, 1);

13
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_BALLOON = "balloon";
public static final String VARIANT_PLAIN_BALLOON = "plainBalloon"; public static final String VARIANT_PLAIN_BALLOON = "plainBalloon";
public static final String TIP_TEXT_PROPERTY = "tiptext"; 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"; public static final String KEY_CONTEXT = KEY_PREFIX + "toolTipContext";
static final float MAX_ALPHA = 1.0f; static final float MAX_ALPHA = 1.0f;
private static final AlphaComposite COMPOSITE = AlphaComposite.getInstance(AlphaComposite.SRC_OVER);
private Animator fadeAnimator; private Animator fadeAnimator;
private float alpha = 0; private float alpha = 0;
@ -199,12 +197,7 @@ public class DarkTooltipUI extends BasicToolTipUI implements PropertyChangeListe
fadeAnimator.reset(); fadeAnimator.reset();
fadeAnimator.resume(); fadeAnimator.resume();
} }
toolTip.putClientProperty(KEY_PAINT_ALPHA, alpha);
if (alpha == 0) return;
GraphicsContext config = new GraphicsContext(g); GraphicsContext config = new GraphicsContext(g);
if (alpha != MAX_ALPHA) {
((Graphics2D) g).setComposite(COMPOSITE.derive(alpha));
}
g.setColor(c.getBackground()); g.setColor(c.getBackground());
if (c.getBorder() instanceof DarkTooltipBorder) { if (c.getBorder() instanceof DarkTooltipBorder) {
Area area = ((DarkTooltipBorder) c.getBorder()).getBackgroundArea(c, c.getWidth(), c.getHeight()); Area area = ((DarkTooltipBorder) c.getBorder()).getBackgroundArea(c, c.getWidth(), c.getHeight());
@ -374,13 +367,15 @@ public class DarkTooltipUI extends BasicToolTipUI implements PropertyChangeListe
@Override @Override
public void paintNow(final int frame, final int totalFrames, final int cycle) { public void paintNow(final int frame, final int totalFrames, final int cycle) {
alpha = ((float) frame * MAX_ALPHA) / totalFrames; 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 @Override
protected void paintCycleEnd() { protected void paintCycleEnd() {
alpha = MAX_ALPHA; alpha = MAX_ALPHA;
toolTip.paintImmediately(0, 0, toolTip.getWidth(), toolTip.getHeight()); Window window = SwingUtilities.getWindowAncestor(toolTip);
if (window != null) window.setOpacity(alpha);
} }
} }
} }

Loading…
Cancel
Save