Browse Source

Fixed NPE when showing tree cell popup and no cell is targeted. Fixes #194

pull/198/head
weisj 4 years ago
parent
commit
162a6c6b13
  1. 42
      core/src/main/java/com/github/weisj/darklaf/ui/cell/hint/CellHintPopupListener.java

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

@ -90,29 +90,31 @@ public class CellHintPopupListener<T extends JComponent, I> extends MouseInputAd
final boolean isEditing = cellContainer.isEditingCell(index); final boolean isEditing = cellContainer.isEditingCell(index);
final Rectangle allocation = cellContainer.getAllocation(); final Rectangle allocation = cellContainer.getAllocation();
final Rectangle cellBounds = cellContainer.getCellBoundsAt(index, isEditing); final Rectangle cellBounds = cellContainer.getCellBoundsAt(index, isEditing);
final Rectangle visibleBounds = allocation.intersection(cellBounds); if (cellBounds != null && allocation != null) {
if (visibleBounds.contains(p)) { final Rectangle visibleBounds = allocation.intersection(cellBounds);
final Component comp = cellContainer.getEffectiveCellRendererComponent(index, isEditing); if (visibleBounds.contains(p)) {
final Dimension prefSize = isEditing final Component comp = cellContainer.getEffectiveCellRendererComponent(index, isEditing);
? comp.getBounds().getSize() final Dimension prefSize = isEditing
: comp.getPreferredSize(); ? comp.getBounds().getSize()
if (!(visibleBounds.width >= prefSize.width && visibleBounds.height >= prefSize.height)) { : comp.getPreferredSize();
Point popupLocation = cellContainer.getComponent().getLocationOnScreen(); if (!(visibleBounds.width >= prefSize.width && visibleBounds.height >= prefSize.height)) {
Rectangle rect = calculatePopupBounds(cellBounds, visibleBounds, !isEditing); Point popupLocation = cellContainer.getComponent().getLocationOnScreen();
if (!visibleBounds.contains(rect)) { Rectangle rect = calculatePopupBounds(cellBounds, visibleBounds, !isEditing);
cellBounds.x = rect.x - cellBounds.x; if (!visibleBounds.contains(rect)) {
cellBounds.y = rect.y - cellBounds.y; cellBounds.x = rect.x - cellBounds.x;
rect.x += popupLocation.x; cellBounds.y = rect.y - cellBounds.y;
rect.y += popupLocation.y; rect.x += popupLocation.x;
enter(index, rect, cellBounds); rect.y += popupLocation.y;
return; enter(index, rect, cellBounds);
} else { return;
lastIndex = index; } else {
lastIndex = index;
}
} }
return;
} }
} else {
lastIndex = null;
} }
lastIndex = null;
leave(); leave();
} }

Loading…
Cancel
Save