Browse Source

Ensure complete tooltip hierarchy is non-opaque

pull/235/head
weisj 4 years ago committed by Jannis Weis
parent
commit
85b52cc6f7
  1. 41
      core/src/main/java/com/github/weisj/darklaf/ui/DarkPopupFactory.java
  2. 1
      core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkToolTipUI.java

41
core/src/main/java/com/github/weisj/darklaf/ui/DarkPopupFactory.java

@ -54,12 +54,12 @@ public class DarkPopupFactory extends PopupFactory {
return popup; return popup;
} }
protected Pair<Popup, PopupType> getEffectivePopup(final Component owner, final Component contents, final int x, protected Pair<Popup, PopupType> getEffectivePopup(final Component owner, final Component contents,
final int y) { final int x, final int y) {
Popup popup = super.getPopup(owner, contents, x, y); Popup popup = super.getPopup(owner, contents, x, y);
PopupType type = getPopupType(popup); PopupType type = getPopupType(popup);
boolean forceHeavy = boolean forceHeavy = type != PopupType.HEAVY_WEIGHT
type != PopupType.HEAVY_WEIGHT && PropertyUtil.getBooleanProperty(contents, KEY_FORCE_HEAVYWEIGHT); && PropertyUtil.getBooleanProperty(contents, KEY_FORCE_HEAVYWEIGHT);
if (forceHeavy) { if (forceHeavy) {
// Heavy weight owner forces a heavyweight popup. // Heavy weight owner forces a heavyweight popup.
Window targetWindow = DarkUIUtil.getWindow(owner); Window targetWindow = DarkUIUtil.getWindow(owner);
@ -104,43 +104,46 @@ public class DarkPopupFactory extends PopupFactory {
if (window != null) { if (window != null) {
boolean isFocusable = PropertyUtil.getBooleanProperty(contents, KEY_FOCUSABLE_POPUP); boolean isFocusable = PropertyUtil.getBooleanProperty(contents, KEY_FOCUSABLE_POPUP);
boolean startHidden = PropertyUtil.getBooleanProperty(contents, KEY_START_HIDDEN); boolean startHidden = PropertyUtil.getBooleanProperty(contents, KEY_START_HIDDEN);
setupWindow(window, contents, isFocusable, startHidden); setupHeavyWeightWindow(window, contents, isFocusable, startHidden);
window.setLocation(x, y); window.setLocation(x, y);
} }
} }
} }
protected void setupWindow(final Window window, final Component contents, final boolean isFocusable, protected void setupHeavyWeightWindow(final Window window, final Component contents,
final boolean startHidden) { final boolean isFocusable, final boolean startHidden) {
boolean noDecorations = PropertyUtil.getBooleanProperty(contents, KEY_NO_DECORATION); boolean noDecorations = PropertyUtil.getBooleanProperty(contents, KEY_NO_DECORATION);
boolean opaque = PropertyUtil.getBooleanProperty(contents, KEY_OPAQUE); boolean opaque = PropertyUtil.getBooleanProperty(contents, KEY_OPAQUE);
JRootPane rootPane = window instanceof RootPaneContainer ? ((RootPaneContainer) window).getRootPane() : null; JRootPane rootPane = window instanceof RootPaneContainer ? ((RootPaneContainer) window).getRootPane() : null;
setupWindowBackground(window, rootPane, opaque, !noDecorations); setupWindowBackground(window, rootPane, opaque, !noDecorations);
setupWindowFocusableState(isFocusable, window); setupFocusableWindowState(isFocusable, window);
setupWindowDecorations(window, rootPane, noDecorations); setupWindowDecorations(window, rootPane, noDecorations);
setupWindowOpacity(startHidden, window); setupWindowOpacity(startHidden, window);
} }
protected void setupWindowBackground(final Window window, final JRootPane rootPane, final boolean opaque, protected void setupWindowBackground(final Window window, final JRootPane rootPane,
final boolean decorations) { final boolean opaque, final boolean decorations) {
/* /*
* Sometimes the background is java.awt.SystemColor[i=7] It results in a flash of white background, * Sometimes the background is java.awt.SystemColor[i=7] It results in a flash of white background,
* that is repainted with the proper popup background later. That is why we set window background * that is repainted with the proper popup background later. That is why we set window background
* explicitly. * explicitly.
*/ */
if (rootPane == null) return; if (rootPane == null) return;
rootPane.setOpaque(opaque); Color bg = opaque
if (opaque) { ? ColorUtil.toAlpha(rootPane.getBackground(), 255)
Color bg = ColorUtil.toAlpha(rootPane.getBackground(), 255); : getTranslucentPopupBackground(decorations);
window.setBackground(bg); Container p = rootPane.getContentPane();
} else { while (p != null && p != window) {
Color bg = getTranslucentPopupBackground(decorations); p.setBackground(bg);
window.setBackground(bg); if (p instanceof JComponent) {
rootPane.setBackground(bg); ((JComponent) p).setOpaque(opaque);
}
p = p.getParent();
} }
window.setBackground(bg);
} }
protected void setupWindowFocusableState(final boolean isFocusable, final Window window) { protected void setupFocusableWindowState(final boolean isFocusable, final Window window) {
if (isFocusable && !window.getFocusableWindowState()) { if (isFocusable && !window.getFocusableWindowState()) {
window.dispose(); window.dispose();
window.setFocusableWindowState(true); window.setFocusableWindowState(true);

1
core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkToolTipUI.java

@ -115,6 +115,7 @@ public class DarkToolTipUI extends BasicToolTipUI
toolTip.putClientProperty(DarkPopupFactory.KEY_NO_DECORATION, !useDecoratedPopup()); toolTip.putClientProperty(DarkPopupFactory.KEY_NO_DECORATION, !useDecoratedPopup());
toolTip.putClientProperty(DarkPopupFactory.KEY_START_HIDDEN, true); toolTip.putClientProperty(DarkPopupFactory.KEY_START_HIDDEN, true);
toolTip.putClientProperty(DarkPopupFactory.KEY_FORCE_HEAVYWEIGHT, true); toolTip.putClientProperty(DarkPopupFactory.KEY_FORCE_HEAVYWEIGHT, true);
toolTip.setOpaque(false);
fadeAnimator = new FadeInAnimator(); fadeAnimator = new FadeInAnimator();
updateTipText(toolTip); updateTipText(toolTip);
updateStyle(); updateStyle();

Loading…
Cancel
Save