Browse Source

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.
pull/245/head
weisj 3 years ago
parent
commit
8e6573be68
No known key found for this signature in database
GPG Key ID: 31124CB75461DA2A
  1. 34
      core/src/main/java/com/github/weisj/darklaf/ui/cell/hint/CellHintPopupListener.java

34
core/src/main/java/com/github/weisj/darklaf/ui/cell/hint/CellHintPopupListener.java

@ -46,30 +46,11 @@ public class CellHintPopupListener<T extends JComponent, I> extends MouseInputAd
private I lastIndex; private I lastIndex;
private Popup popup; private Popup popup;
private boolean respectCellHeight = false;
private boolean respectCellWidth = true;
public CellHintPopupListener(final IndexedCellContainer<T, I> cellContainer) { public CellHintPopupListener(final IndexedCellContainer<T, I> cellContainer) {
this.cellContainer = cellContainer; this.cellContainer = cellContainer;
this.popupComponent = new PopupComponent(this); 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() { public void install() {
JComponent comp = cellContainer.getComponent(); JComponent comp = cellContainer.getComponent();
comp.addMouseListener(this); comp.addMouseListener(this);
@ -160,11 +141,14 @@ public class CellHintPopupListener<T extends JComponent, I> extends MouseInputAd
boolean ltr = cellContainer.getComponent().getComponentOrientation().isLeftToRight(); boolean ltr = cellContainer.getComponent().getComponentOrientation().isLeftToRight();
popupComponent.setBorderInsets(1, 1, 1, 1); popupComponent.setBorderInsets(1, 1, 1, 1);
if (isRespectCellWidth()) { // Wen only support showing either a horizontal or vertical completion of the cell
calculatePopupWidth(cellBounds, visibleBounds, rect, ltr); // Calculate which portion would be bigger.
} int hiddenVerticalSpace = Math.abs(cellBounds.width - visibleBounds.width);
if (isRespectCellHeight()) { int hiddenHorizontalSpace = Math.abs(cellBounds.height - visibleBounds.height);
if (hiddenHorizontalSpace > hiddenVerticalSpace) {
calculatePopupHeight(cellBounds, visibleBounds, rect); calculatePopupHeight(cellBounds, visibleBounds, rect);
} else {
calculatePopupWidth(cellBounds, visibleBounds, rect, ltr);
} }
if (!addBorder) { if (!addBorder) {
popupComponent.setBorderInsets(0, 0, 0, 0); popupComponent.setBorderInsets(0, 0, 0, 0);
@ -189,11 +173,11 @@ public class CellHintPopupListener<T extends JComponent, I> extends MouseInputAd
if (upperDiff >= lowerDiff) { if (upperDiff >= lowerDiff) {
rect.y = visibleBounds.y + visibleBounds.height; rect.y = visibleBounds.y + visibleBounds.height;
rect.height = upperDiff; rect.height = upperDiff;
popupComponent.setBottom(0); popupComponent.setTop(0);
} else { } else {
rect.y = cellBounds.y; rect.y = cellBounds.y;
rect.height = lowerDiff; rect.height = lowerDiff;
popupComponent.setTop(0); popupComponent.setBottom(0);
} }
} }
} }

Loading…
Cancel
Save