Browse Source

CellPopup: Accommodate cell containers, where the cell bounds aren't already the correct size to display the whole component. This brings us one step closer to supporting cell popups for tables.

pull/245/head
weisj 4 years ago
parent
commit
494edfaaa7
No known key found for this signature in database
GPG Key ID: 31124CB75461DA2A
  1. 9
      core/src/main/java/com/github/weisj/darklaf/ui/cell/hint/CellContainer.java
  2. 16
      core/src/main/java/com/github/weisj/darklaf/ui/cell/hint/CellHintPopupListener.java
  3. 22
      core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableUI.java
  4. 3
      core/src/main/java/com/github/weisj/darklaf/ui/table/renderer/DarkTableCellRendererDelegate.java

9
core/src/main/java/com/github/weisj/darklaf/ui/cell/hint/CellContainer.java

@ -36,4 +36,13 @@ public interface CellContainer<T extends JComponent> {
} }
void addRenderer(final Component renderer); 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;
}
}
} }

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

@ -99,7 +99,14 @@ public class CellHintPopupListener<T extends JComponent, I> extends MouseInputAd
final Rectangle visibleBounds = allocation.intersection(cellBounds); final Rectangle visibleBounds = allocation.intersection(cellBounds);
LOGGER.finer(() -> "Visible bounds at index " + index + ": " + visibleBounds); LOGGER.finer(() -> "Visible bounds at index " + index + ": " + visibleBounds);
if (visibleBounds.contains(p)) { 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(); Point popupLocation = cellContainer.getComponent().getLocationOnScreen();
Rectangle popupBounds = calculatePopupBounds(cellBounds, visibleBounds, !isEditing); Rectangle popupBounds = calculatePopupBounds(cellBounds, visibleBounds, !isEditing);
LOGGER.finer(() -> "Popup bounds at index " + index + ": " + popupBounds); LOGGER.finer(() -> "Popup bounds at index " + index + ": " + popupBounds);
@ -124,13 +131,6 @@ public class CellHintPopupListener<T extends JComponent, I> extends MouseInputAd
return MenuSelectionManager.defaultManager().getSelectedPath().length > 0; 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) { private boolean fitsInside(final Dimension size, final Rectangle bounds) {
return bounds.width >= size.width && bounds.height >= size.height; return bounds.width >= size.width && bounds.height >= size.height;
} }

22
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.CellUtil;
import com.github.weisj.darklaf.ui.cell.DarkBooleanCellRenderer; import com.github.weisj.darklaf.ui.cell.DarkBooleanCellRenderer;
import com.github.weisj.darklaf.ui.cell.DarkCellRendererPane; 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.DarkColorTableCellRendererEditor;
import com.github.weisj.darklaf.ui.table.renderer.DarkTableCellEditorDelegate; import com.github.weisj.darklaf.ui.table.renderer.DarkTableCellEditorDelegate;
import com.github.weisj.darklaf.ui.table.renderer.DarkTableCellRenderer; 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 { public class DarkTableUI extends DarkTableUIBridge implements TableConstants, HasRendererPane {
private static final int ROW_HEIGHT_FALLBACK = 22; private static final int ROW_HEIGHT_FALLBACK = 22;
private static final boolean CELL_POPUP_ENABLED = false;
protected Color selectionBackgroundNoFocus; protected Color selectionBackgroundNoFocus;
protected Color selectionBackground; protected Color selectionBackground;
protected Color borderColor; protected Color borderColor;
protected Handler handler; protected Handler handler;
protected CellHintPopupListener<JTable, ?> popupListener;
protected DarkTableCellRendererDelegate rendererDelegate; protected DarkTableCellRendererDelegate rendererDelegate;
private TableCellRenderer booleanCellRenderer; private TableCellRenderer booleanCellRenderer;
@ -118,9 +122,27 @@ public class DarkTableUI extends DarkTableUIBridge implements TableConstants, Ha
table.setSurrendersFocusOnKeystroke(true); table.setSurrendersFocusOnKeystroke(true);
} }
@Override
protected void installListeners() {
super.installListeners();
if (CELL_POPUP_ENABLED && UIManager.getBoolean("Table.showFullCellInPopup")) {
popupListener = createPopupMouseListener();
popupListener.install();
}
}
protected CellHintPopupListener<JTable, ?> createPopupMouseListener() {
return new CellHintPopupListener<>(new TableCellContainer(table, this));
}
@Override @Override
protected void uninstallListeners() { protected void uninstallListeners() {
super.uninstallListeners(); super.uninstallListeners();
if (popupListener != null) {
popupListener.uninstall();
popupListener = null;
}
// Handler is uninstalled in super.uninstallListeners()
handler = null; handler = null;
} }

3
core/src/main/java/com/github/weisj/darklaf/ui/table/renderer/DarkTableCellRendererDelegate.java

@ -118,7 +118,8 @@ public class DarkTableCellRendererDelegate extends TableCellRendererDelegate imp
} else { } else {
component.putClientProperty(KEY_FULL_ROW_FOCUS_BORDER, false); 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")); component.setBorder(UIManager.getBorder("Table.cellNoFocusBorder"));
} }
} }

Loading…
Cancel
Save