From 2234c0dd20e68ce49b1fefba9f85f39a4667b4c8 Mon Sep 17 00:00:00 2001 From: weisj Date: Sun, 26 Jul 2020 23:23:43 +0200 Subject: [PATCH] Make sure position provided by ToolTipUtil has the highest priority. Don't show cell hint if only part of the border is obscured. --- .../github/weisj/darklaf/ui/DarkPopupFactory.java | 5 +++-- .../ui/cell/hint/CellHintPopupListener.java | 15 ++++++++++++++- .../darklaf/ui/filechooser/DarkFilePane.java | 1 - .../weisj/darklaf/ui/tooltip/ToolTipUtil.java | 10 +++++++++- 4 files changed, 26 insertions(+), 5 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 b181ab3b..c04021cd 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 @@ -84,8 +84,9 @@ public class DarkPopupFactory extends PopupFactory { window = DarkUIUtil.getWindow(contents); } if (window != null) { - Window finalWindow = window; - SwingUtilities.invokeLater(() -> finalWindow.setLocation(x, y)); + Window w = window; + w.setLocation(x, y); + SwingUtilities.invokeLater(() -> w.setLocation(x, y)); } } return new Pair<>(popup, type); diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/cell/hint/CellHintPopupListener.java b/core/src/main/java/com/github/weisj/darklaf/ui/cell/hint/CellHintPopupListener.java index aae23113..78146f3d 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/cell/hint/CellHintPopupListener.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/cell/hint/CellHintPopupListener.java @@ -29,6 +29,7 @@ import java.awt.event.MouseEvent; import java.util.Objects; import javax.swing.*; +import javax.swing.border.Border; import javax.swing.event.MouseInputAdapter; import com.github.weisj.darklaf.graphics.PaintUtil; @@ -97,6 +98,15 @@ public class CellHintPopupListener extends MouseInputAd final Dimension prefSize = isEditing ? comp.getBounds().getSize() : comp.getPreferredSize(); + if (comp instanceof JComponent) { + // Avoid showing the popup if only the border is obscured. + Border border = ((JComponent) comp).getBorder(); + if (border != null) { + Insets borderInsets = border.getBorderInsets(comp); + prefSize.width -= borderInsets.left + borderInsets.right; + prefSize.height -= borderInsets.top + borderInsets.bottom; + } + } if (!(visibleBounds.width >= prefSize.width && visibleBounds.height >= prefSize.height)) { Point popupLocation = cellContainer.getComponent().getLocationOnScreen(); Rectangle rect = calculatePopupBounds(cellBounds, visibleBounds, !isEditing); @@ -105,6 +115,9 @@ public class CellHintPopupListener extends MouseInputAd cellBounds.y = rect.y - cellBounds.y; rect.x += popupLocation.x; rect.y += popupLocation.y; + System.out.println("Allocation " + allocation); + System.out.println("CellBounds " + cellBounds); + System.out.println("PreffeSize " + prefSize); enter(index, rect, cellBounds); return; } else { @@ -228,7 +241,7 @@ public class CellHintPopupListener extends MouseInputAd popup.show(); if (DarkPopupFactory.getPopupType(popup) == DarkPopupFactory.PopupType.HEAVY_WEIGHT) { // Ensure heavy weight popup is at desired location. - movePopup(bounds); + SwingUtilities.invokeLater(() -> movePopup(bounds)); } } } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFilePane.java b/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFilePane.java index c631d4e6..095c7e98 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFilePane.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFilePane.java @@ -43,7 +43,6 @@ import javax.swing.text.Position; import sun.swing.SwingUtilities2; import com.github.weisj.darklaf.components.OverlayScrollPane; -import com.github.weisj.darklaf.ui.list.DarkListCellRendererDelegate; import com.github.weisj.darklaf.ui.table.DarkTableUI; import com.github.weisj.darklaf.ui.table.TextTableCellEditorBorder; import com.github.weisj.darklaf.ui.text.DarkTextUI; diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/tooltip/ToolTipUtil.java b/core/src/main/java/com/github/weisj/darklaf/ui/tooltip/ToolTipUtil.java index 1550781e..3141e874 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/tooltip/ToolTipUtil.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/tooltip/ToolTipUtil.java @@ -28,9 +28,11 @@ import java.awt.*; import java.util.function.BiConsumer; import javax.swing.*; +import javax.swing.event.AncestorEvent; import com.github.weisj.darklaf.components.tooltip.ToolTipContext; import com.github.weisj.darklaf.components.tooltip.ToolTipStyle; +import com.github.weisj.darklaf.listener.AncestorAdapter; import com.github.weisj.darklaf.util.Alignment; import com.github.weisj.darklaf.util.DarkUIUtil; @@ -180,6 +182,12 @@ public class ToolTipUtil { Point p = new Point(x, y); SwingUtilities.convertPointToScreen(p, target); window.setLocation(p); - SwingUtilities.invokeLater(() -> window.setLocation(p)); + toolTip.addAncestorListener(new AncestorAdapter() { + @Override + public void ancestorAdded(final AncestorEvent event) { + window.setLocation(p.x, p.y); + toolTip.removeAncestorListener(this); + } + }); } }