Browse Source

Dont paint selection background on lead selection cell.

pull/97/head
weisj 5 years ago
parent
commit
599fca7bd5
  1. 8
      core/src/main/java/com/github/weisj/darklaf/ui/cell/DarkCellRendererToggleButton.java
  2. 7
      core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellEditorToggleButton.java
  3. 4
      core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellFocusBorder.java
  4. 17
      core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellRenderer.java
  5. 2
      core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableUI.java

8
core/src/main/java/com/github/weisj/darklaf/ui/cell/DarkCellRendererToggleButton.java

@ -26,6 +26,7 @@ package com.github.weisj.darklaf.ui.cell;
import com.github.weisj.darklaf.components.SelectableTreeNode;
import com.github.weisj.darklaf.decorators.CellRenderer;
import com.github.weisj.darklaf.ui.button.DarkToggleButtonUI;
import com.github.weisj.darklaf.ui.table.DarkTableCellFocusBorder;
import com.github.weisj.darklaf.ui.table.DarkTableUI;
import com.github.weisj.darklaf.ui.tree.DarkTreeCellRenderer;
import com.github.weisj.darklaf.util.DarkUIUtil;
@ -60,11 +61,16 @@ public class DarkCellRendererToggleButton<T extends JToggleButton & CellEditorTo
toggleButton.setHorizontalAlignment(table.getComponentOrientation().isLeftToRight() ? LEFT : RIGHT);
toggleButton.setHasFocus(focus);
boolean isLeadSelectionCell = DarkUIUtil.hasFocus(table)
&& table.getSelectionModel().getLeadSelectionIndex() == row
&& (table.getColumnModel().getSelectionModel().getLeadSelectionIndex() == column
|| DarkTableCellFocusBorder.isRowFocusBorder(table));
boolean alternativeRow = Boolean.TRUE.equals(table.getClientProperty(DarkTableUI.KEY_ALTERNATE_ROW_COLOR));
Color alternativeRowColor = UIManager.getColor("Table.alternateRowBackground");
Color normalColor = UIManager.getColor("Table.background");
Color background = alternativeRow && row % 2 == 1 ? alternativeRowColor : normalColor;
if (!(isSelected) || table.isEditing()) {
if (!isSelected || isLeadSelectionCell || table.isEditing()) {
toggleButton.setBackground(background);
toggleButton.setForeground(table.getForeground());
} else {

7
core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellEditorToggleButton.java

@ -55,11 +55,16 @@ public class DarkTableCellEditorToggleButton extends AbstractCellEditor implemen
}
toggleButton.setHorizontalAlignment(table.getComponentOrientation().isLeftToRight() ? LEFT : RIGHT);
boolean isLeadSelectionCell = DarkUIUtil.hasFocus(table)
&& table.getSelectionModel().getLeadSelectionIndex() == row
&& (table.getColumnModel().getSelectionModel().getLeadSelectionIndex() == column
|| DarkTableCellFocusBorder.isRowFocusBorder(table));
boolean alternativeRow = Boolean.TRUE.equals(table.getClientProperty(DarkTableUI.KEY_ALTERNATE_ROW_COLOR));
Color alternativeRowColor = UIManager.getColor("Table.alternateRowBackground");
Color normalColor = table.getBackground();
Color background = alternativeRow && row % 2 == 1 ? alternativeRowColor : normalColor;
if (!(isSelected) || table.isEditing()) {
if (!isSelected || isLeadSelectionCell || table.isEditing()) {
toggleButton.setBackground(background);
toggleButton.setForeground(table.getForeground());
} else {

4
core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellFocusBorder.java

@ -62,9 +62,9 @@ public class DarkTableCellFocusBorder extends DarkCellBorder {
}
}
protected static boolean isRowFocusBorder(final Component c) {
public static boolean isRowFocusBorder(final Component c) {
return c instanceof JComponent
&& Boolean.TRUE.equals(((JComponent) c).getClientProperty(DarkTableUI.KEY_SHOW_ROW_FOCUS_BORDER));
&& Boolean.TRUE.equals(((JComponent) c).getClientProperty(DarkTableUI.KEY_FULL_ROW_FOCUS_BORDER));
}
protected static boolean forcePaintLeft(final Component c) {

17
core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellRenderer.java

@ -63,12 +63,17 @@ public class DarkTableCellRenderer extends DefaultTableCellRenderer {
this.setVerticalAlignment(SwingConstants.CENTER);
setHorizontalAlignment(table.getComponentOrientation().isLeftToRight() ? LEFT : RIGHT);
boolean isLeadSelectionCell = DarkUIUtil.hasFocus(table)
&& table.getSelectionModel().getLeadSelectionIndex() == row
&& (table.getColumnModel().getSelectionModel().getLeadSelectionIndex() == column
|| DarkTableCellFocusBorder.isRowFocusBorder(table));
if (DarkTableCellFocusBorder.isRowFocusBorder(table)
&& table.getSelectionModel().getLeadSelectionIndex() == row
&& !table.isEditing()
&& DarkUIUtil.hasFocus(table)) {
&& table.getSelectionModel().getLeadSelectionIndex() == row
&& !table.isEditing()
&& DarkUIUtil.hasFocus(table)) {
component.setBorder(UIManager.getBorder("Table.focusSelectedCellHighlightBorder"));
component.putClientProperty(DarkTableUI.KEY_SHOW_ROW_FOCUS_BORDER, true);
component.putClientProperty(DarkTableUI.KEY_FULL_ROW_FOCUS_BORDER, true);
JTableHeader header = table.getTableHeader();
TableColumn draggedColumn = (header == null) ? null : header.getDraggedColumn();
boolean forceLeft = false;
@ -81,14 +86,14 @@ public class DarkTableCellRenderer extends DefaultTableCellRenderer {
component.putClientProperty(DarkTableUI.KEY_FORCE_RIGHT_BORDER, forceRight);
component.putClientProperty(DarkTableUI.KEY_FORCE_LEFT_BORDER, forceLeft);
} else {
component.putClientProperty(DarkTableUI.KEY_SHOW_ROW_FOCUS_BORDER, false);
component.putClientProperty(DarkTableUI.KEY_FULL_ROW_FOCUS_BORDER, false);
}
boolean alternativeRow = Boolean.TRUE.equals(table.getClientProperty(DarkTableUI.KEY_ALTERNATE_ROW_COLOR));
Color alternativeRowColor = UIManager.getColor("Table.alternateRowBackground");
Color normalColor = table.getBackground();
Color background = alternativeRow && row % 2 == 1 ? alternativeRowColor : normalColor;
if (!(isSelected) || table.isEditing()) {
if (!isSelected || isLeadSelectionCell || table.isEditing()) {
component.setBackground(background);
component.setForeground(table.getForeground());
} else {

2
core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableUI.java

@ -52,7 +52,7 @@ public class DarkTableUI extends DarkTableUIBridge {
public static final String KEY_ALTERNATE_ROW_COLOR = KEY_PREFIX + "alternateRowColor";
public static final String KEY_RENDER_BOOLEAN_AS_CHECKBOX = KEY_PREFIX + "renderBooleanAsCheckBox";
public static final String KEY_BOOLEAN_RENDER_TYPE = KEY_PREFIX + "booleanRenderType";
public static final String KEY_SHOW_ROW_FOCUS_BORDER = KEY_PREFIX + "rowFocusBorder";
public static final String KEY_FULL_ROW_FOCUS_BORDER = KEY_PREFIX + "rowFocusBorder";
public static final String KEY_FORCE_LEFT_BORDER = KEY_PREFIX + "forcePaintLeft";
public static final String KEY_FORCE_RIGHT_BORDER = KEY_PREFIX + "forcePaintRight";
public static final String KEY_FILE_CHOOSER_PARENT = KEY_PREFIX + "fileChooserParent";

Loading…
Cancel
Save