From 8e6573be6858eb2b9144bd00bb401d361c176ca3 Mon Sep 17 00:00:00 2001 From: weisj <31143295+weisJ@users.noreply.github.com> Date: Mon, 21 Jun 2021 17:09:28 +0200 Subject: [PATCH] CellHint: Correctly handle popups on the top and bottom. Fixes #238 Depending on whether the hidden part of a cell has greater width/height calculate the popup accordingly. --- .../ui/cell/hint/CellHintPopupListener.java | 34 +++++-------------- 1 file changed, 9 insertions(+), 25 deletions(-) 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 0d3625b1..c4f983be 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 @@ -46,30 +46,11 @@ public class CellHintPopupListener extends MouseInputAd private I lastIndex; private Popup popup; - private boolean respectCellHeight = false; - private boolean respectCellWidth = true; - public CellHintPopupListener(final IndexedCellContainer cellContainer) { this.cellContainer = cellContainer; this.popupComponent = new PopupComponent(this); } - public void setRespectCellHeight(final boolean respectCellHeight) { - this.respectCellHeight = respectCellHeight; - } - - public void setRespectCellWidth(final boolean respectCellWidth) { - this.respectCellWidth = respectCellWidth; - } - - public boolean isRespectCellHeight() { - return respectCellHeight; - } - - public boolean isRespectCellWidth() { - return respectCellWidth; - } - public void install() { JComponent comp = cellContainer.getComponent(); comp.addMouseListener(this); @@ -160,11 +141,14 @@ public class CellHintPopupListener extends MouseInputAd boolean ltr = cellContainer.getComponent().getComponentOrientation().isLeftToRight(); popupComponent.setBorderInsets(1, 1, 1, 1); - if (isRespectCellWidth()) { - calculatePopupWidth(cellBounds, visibleBounds, rect, ltr); - } - if (isRespectCellHeight()) { + // Wen only support showing either a horizontal or vertical completion of the cell + // Calculate which portion would be bigger. + int hiddenVerticalSpace = Math.abs(cellBounds.width - visibleBounds.width); + int hiddenHorizontalSpace = Math.abs(cellBounds.height - visibleBounds.height); + if (hiddenHorizontalSpace > hiddenVerticalSpace) { calculatePopupHeight(cellBounds, visibleBounds, rect); + } else { + calculatePopupWidth(cellBounds, visibleBounds, rect, ltr); } if (!addBorder) { popupComponent.setBorderInsets(0, 0, 0, 0); @@ -189,11 +173,11 @@ public class CellHintPopupListener extends MouseInputAd if (upperDiff >= lowerDiff) { rect.y = visibleBounds.y + visibleBounds.height; rect.height = upperDiff; - popupComponent.setBottom(0); + popupComponent.setTop(0); } else { rect.y = cellBounds.y; rect.height = lowerDiff; - popupComponent.setTop(0); + popupComponent.setBottom(0); } } }