diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/cell/hint/CellContainer.java b/core/src/main/java/com/github/weisj/darklaf/ui/cell/hint/CellContainer.java index 8cb626b0..629e89f8 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/cell/hint/CellContainer.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/cell/hint/CellContainer.java @@ -36,4 +36,13 @@ public interface CellContainer { } void addRenderer(final Component renderer); + + default void adjustCellBoundsToPreferredSize(final Rectangle cellBounds, final Dimension prefSize) { + if (cellBounds.width < prefSize.width) { + cellBounds.width = prefSize.width; + } + if (cellBounds.height < prefSize.height) { + cellBounds.height = prefSize.height; + } + } } 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 53553a5f..0d3625b1 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 @@ -99,7 +99,14 @@ public class CellHintPopupListener extends MouseInputAd final Rectangle visibleBounds = allocation.intersection(cellBounds); LOGGER.finer(() -> "Visible bounds at index " + index + ": " + visibleBounds); if (visibleBounds.contains(p)) { - if (isPopupNeeded(index, isEditing, visibleBounds)) { + final Component comp = cellContainer.getEffectiveCellRendererComponent(index, isEditing); + final Dimension prefSize = getPreferredSize(isEditing, comp); + LOGGER.finer(() -> "Necessary cell size at index " + index + ": " + prefSize); + + if (!fitsInside(prefSize, visibleBounds)) { + // Popup is needed. + cellContainer.adjustCellBoundsToPreferredSize(cellBounds, prefSize); + Point popupLocation = cellContainer.getComponent().getLocationOnScreen(); Rectangle popupBounds = calculatePopupBounds(cellBounds, visibleBounds, !isEditing); LOGGER.finer(() -> "Popup bounds at index " + index + ": " + popupBounds); @@ -124,13 +131,6 @@ public class CellHintPopupListener extends MouseInputAd return MenuSelectionManager.defaultManager().getSelectedPath().length > 0; } - private boolean isPopupNeeded(final I index, final boolean isEditing, final Rectangle visibleBounds) { - final Component comp = cellContainer.getEffectiveCellRendererComponent(index, isEditing); - final Dimension prefSize = getPreferredSize(isEditing, comp); - LOGGER.finer(() -> "Necessary cell size at index " + index + ": " + prefSize); - return !fitsInside(prefSize, visibleBounds); - } - private boolean fitsInside(final Dimension size, final Rectangle bounds) { return bounds.width >= size.width && bounds.height >= size.height; } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableUI.java index a822eb79..ac561d4b 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableUI.java @@ -38,6 +38,7 @@ import com.github.weisj.darklaf.ui.HasRendererPane; import com.github.weisj.darklaf.ui.cell.CellUtil; import com.github.weisj.darklaf.ui.cell.DarkBooleanCellRenderer; import com.github.weisj.darklaf.ui.cell.DarkCellRendererPane; +import com.github.weisj.darklaf.ui.cell.hint.CellHintPopupListener; import com.github.weisj.darklaf.ui.table.renderer.DarkColorTableCellRendererEditor; import com.github.weisj.darklaf.ui.table.renderer.DarkTableCellEditorDelegate; import com.github.weisj.darklaf.ui.table.renderer.DarkTableCellRenderer; @@ -51,11 +52,14 @@ import com.github.weisj.darklaf.util.SwingUtil; public class DarkTableUI extends DarkTableUIBridge implements TableConstants, HasRendererPane { private static final int ROW_HEIGHT_FALLBACK = 22; + private static final boolean CELL_POPUP_ENABLED = false; protected Color selectionBackgroundNoFocus; protected Color selectionBackground; protected Color borderColor; protected Handler handler; + protected CellHintPopupListener popupListener; + protected DarkTableCellRendererDelegate rendererDelegate; private TableCellRenderer booleanCellRenderer; @@ -118,9 +122,27 @@ public class DarkTableUI extends DarkTableUIBridge implements TableConstants, Ha table.setSurrendersFocusOnKeystroke(true); } + @Override + protected void installListeners() { + super.installListeners(); + if (CELL_POPUP_ENABLED && UIManager.getBoolean("Table.showFullCellInPopup")) { + popupListener = createPopupMouseListener(); + popupListener.install(); + } + } + + protected CellHintPopupListener createPopupMouseListener() { + return new CellHintPopupListener<>(new TableCellContainer(table, this)); + } + @Override protected void uninstallListeners() { super.uninstallListeners(); + if (popupListener != null) { + popupListener.uninstall(); + popupListener = null; + } + // Handler is uninstalled in super.uninstallListeners() handler = null; } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/table/renderer/DarkTableCellRendererDelegate.java b/core/src/main/java/com/github/weisj/darklaf/ui/table/renderer/DarkTableCellRendererDelegate.java index 2c575e74..8d8c045c 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/table/renderer/DarkTableCellRendererDelegate.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/table/renderer/DarkTableCellRendererDelegate.java @@ -118,7 +118,8 @@ public class DarkTableCellRendererDelegate extends TableCellRendererDelegate imp } else { component.putClientProperty(KEY_FULL_ROW_FOCUS_BORDER, false); } - } else if (component.getBorder() == focusBorder) { + } else if (component.getBorder() == focusBorder + || focusBorder.getClass().isInstance(component.getBorder())) { component.setBorder(UIManager.getBorder("Table.cellNoFocusBorder")); } }