Browse Source

Fixed missing foreground in table/list cell renderers.

pull/127/head
weisj 5 years ago
parent
commit
7d55a020c8
  1. 49
      core/src/main/java/com/github/weisj/darklaf/ui/cell/CellUtil.java
  2. 3
      core/src/main/java/com/github/weisj/darklaf/ui/cell/DarkCellRendererToggleButton.java
  3. 6
      core/src/main/java/com/github/weisj/darklaf/ui/label/DarkLabelUI.java
  4. 22
      core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListCellRenderer.java
  5. 3
      core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellEditor.java
  6. 2
      core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellEditorToggleButton.java
  7. 3
      core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellRenderer.java

49
core/src/main/java/com/github/weisj/darklaf/ui/cell/CellUtil.java

@ -23,9 +23,11 @@
*/ */
package com.github.weisj.darklaf.ui.cell; package com.github.weisj.darklaf.ui.cell;
import com.github.weisj.darklaf.ui.list.DarkListUI;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
import javax.swing.*; import javax.swing.*;
import javax.swing.plaf.ListUI;
import java.awt.*; import java.awt.*;
public class CellUtil { public class CellUtil {
@ -62,30 +64,55 @@ public class CellUtil {
} }
} }
public static void setupBackground(final JComponent comp, final JTable parent, public static void setupBackground(final Component comp, final JTable parent,
final boolean selected, final int row, final boolean selected, final int row,
final String altBgKey, final String altColorKey) { final String altBgKey, final String altColorKey,
setupBackground(comp, parent, selected, row, altBgKey, final String noFocusSelectionBgKey) {
parent.getBackground(), altColorKey, parent.getSelectionBackground()); setupBackground(comp, parent, selected, row, altBgKey, parent.getBackground(), altColorKey,
parent.getSelectionBackground(), noFocusSelectionBgKey);
} }
public static void setupBackground(final JComponent comp, final JTable parent, public static void setupBackground(final Component comp, final JTable parent,
final boolean selected, final int row, final boolean selected, final int row,
final String altBgKey, final String colorKey, final String altColorKey) { final String altBgKey, final String colorKey, final String altColorKey,
final String noFocusSelectionBgKey) {
setupBackground(comp, parent, selected, row, altBgKey, UIManager.getColor(colorKey), setupBackground(comp, parent, selected, row, altBgKey, UIManager.getColor(colorKey),
altColorKey, parent.getSelectionBackground()); altColorKey, parent.getSelectionBackground(), noFocusSelectionBgKey);
} }
protected static void setupBackground(final JComponent comp, final JComponent parent, public static void setupBackground(final Component comp, final JList<?> parent, final boolean selected,
final int index, final String altBgKey, final String altColorKey,
final String noFocusSelectionBgKey) {
int layout = parent.getLayoutOrientation();
boolean altRow = false;
if (layout == JList.VERTICAL) {
altRow = index % 2 == 1;
} else if (layout == JList.VERTICAL_WRAP || layout == JList.HORIZONTAL_WRAP) {
ListUI ui = parent.getUI();
if (ui instanceof DarkListUI) {
int row = ((DarkListUI) ui).convertModelToRow(index);
altRow = row % 2 == 1;
} else {
altRow = false;
}
}
setupBackground(comp, parent, selected, altRow ? 1 : 0, altBgKey, parent.getBackground(),
altColorKey, parent.getSelectionBackground(), noFocusSelectionBgKey);
}
protected static void setupBackground(final Component comp, final JComponent parent,
final boolean selected, final int row, final boolean selected, final int row,
final String altBgKey, final Color bgColor, final String altColorKey, final String altBgKey, final Color bgColor, final String altColorKey,
final Color selectionBackground) { final Color selectionBackground, final String noFocusSelectionBgKey) {
boolean alternativeRow = Boolean.TRUE.equals(parent.getClientProperty(altBgKey)); boolean alternativeRow = Boolean.TRUE.equals(parent.getClientProperty(altBgKey));
Color alternativeRowColor = UIManager.getColor(altColorKey); Color alternativeRowColor = UIManager.getColor(altColorKey);
Color background = alternativeRow && row % 2 == 1 ? alternativeRowColor : bgColor; Color background = alternativeRow && row % 2 == 1 ? alternativeRowColor : bgColor;
if (selected) { if (selected) {
comp.setBackground(selectionBackground); if (DarkUIUtil.hasFocus(parent)) {
comp.setBackground(selectionBackground);
} else {
comp.setBackground(UIManager.getColor(noFocusSelectionBgKey));
}
} else { } else {
comp.setBackground(background); comp.setBackground(background);
} }

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

@ -68,7 +68,8 @@ public class DarkCellRendererToggleButton<T extends JToggleButton & CellEditorTo
CellUtil.setupForeground(toggleButton, table, paintSelected, CellUtil.setupForeground(toggleButton, table, paintSelected,
"Table.selectionForeground", "Table.selectionForegroundInactive"); "Table.selectionForeground", "Table.selectionForegroundInactive");
CellUtil.setupBackground(toggleButton, table, paintSelected, row, DarkTableUI.KEY_ALTERNATE_ROW_COLOR, CellUtil.setupBackground(toggleButton, table, paintSelected, row, DarkTableUI.KEY_ALTERNATE_ROW_COLOR,
"Table.background", "Table.alternateRowBackground"); "Table.background", "Table.alternateRowBackground",
"Table.selectionNoFocusBackground");
return toggleButton; return toggleButton;
} }

6
core/src/main/java/com/github/weisj/darklaf/ui/label/DarkLabelUI.java

@ -114,10 +114,8 @@ public class DarkLabelUI extends BasicLabelUI implements PropertyChangeListener
protected void paintEnabledText(final JLabel l, final Graphics g, final String s, protected void paintEnabledText(final JLabel l, final Graphics g, final String s,
final int textX, final int textY) { final int textX, final int textY) {
int mnemIndex = l.getDisplayedMnemonicIndex(); int mnemIndex = l.getDisplayedMnemonicIndex();
if (DarkUIUtil.isInCell(l)) { if (DarkUIUtil.isInCell(l) && !hasFocusInCell(l)) {
if (!hasFocusInCell(l)) { g.setColor(cellForegroundNoFocus);
g.setColor(cellForegroundNoFocus);
}
} else { } else {
g.setColor(l.getForeground()); g.setColor(l.getForeground());
} }

22
core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListCellRenderer.java

@ -23,10 +23,10 @@
*/ */
package com.github.weisj.darklaf.ui.list; package com.github.weisj.darklaf.ui.list;
import com.github.weisj.darklaf.ui.cell.CellUtil;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
import javax.swing.*; import javax.swing.*;
import javax.swing.plaf.ListUI;
import java.awt.*; import java.awt.*;
public class DarkListCellRenderer extends DefaultListCellRenderer { public class DarkListCellRenderer extends DefaultListCellRenderer {
@ -52,24 +52,10 @@ public class DarkListCellRenderer extends DefaultListCellRenderer {
if (comp == null) { if (comp == null) {
comp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); comp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
} }
boolean alternativeRow = Boolean.TRUE.equals(list.getClientProperty(DarkListUI.KEY_ALTERNATE_ROW_COLOR)); CellUtil.setupBackground(comp, list, isSelected, index, DarkListUI.KEY_ALTERNATE_ROW_COLOR,
int layout = list.getLayoutOrientation(); "List.alternateRowBackground",
if (layout == JList.VERTICAL) { "List.selectionNoFocusBackground");
alternativeRow = alternativeRow && index % 2 == 1;
} else if (layout == JList.VERTICAL_WRAP || layout == JList.HORIZONTAL_WRAP) {
ListUI ui = list.getUI();
if (ui instanceof DarkListUI) {
int row = ((DarkListUI) ui).convertModelToRow(index);
alternativeRow = alternativeRow && row % 2 == 1;
} else {
alternativeRow = false;
}
}
Color alternativeRowColor = UIManager.getColor("List.alternateRowBackground");
Color normalColor = list.getBackground();
Color background = alternativeRow ? alternativeRowColor : normalColor;
if (!(isSelected)) { if (!(isSelected)) {
comp.setBackground(background);
comp.setForeground(list.getForeground()); comp.setForeground(list.getForeground());
} else { } else {
if (DarkUIUtil.hasFocus(list) || DarkUIUtil.getParentOfType(JPopupMenu.class, list) != null) { if (DarkUIUtil.hasFocus(list) || DarkUIUtil.getParentOfType(JPopupMenu.class, list) != null) {

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

@ -235,7 +235,8 @@ public class DarkTableCellEditor extends DefaultCellEditor {
comp = applyRendererIcon(comp, rendererComp); comp = applyRendererIcon(comp, rendererComp);
CellUtil.setupBackground(comp, table, false, row, DarkTableUI.KEY_ALTERNATE_ROW_COLOR, CellUtil.setupBackground(comp, table, false, row, DarkTableUI.KEY_ALTERNATE_ROW_COLOR,
"Table.alternateRowBackground"); "Table.alternateRowBackground",
"Table.selectionNoFocusBackground");
return comp; return comp;
} }

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

@ -62,7 +62,7 @@ public class DarkTableCellEditorToggleButton extends AbstractCellEditor implemen
boolean paintSelected = isSelected && !isLeadSelectionCell && !table.isEditing(); boolean paintSelected = isSelected && !isLeadSelectionCell && !table.isEditing();
CellUtil.setupForeground(toggleButton, table, paintSelected, "Table.selectionForegroundInactive"); CellUtil.setupForeground(toggleButton, table, paintSelected, "Table.selectionForegroundInactive");
CellUtil.setupBackground(toggleButton, table, paintSelected, row, DarkTableUI.KEY_ALTERNATE_ROW_COLOR, CellUtil.setupBackground(toggleButton, table, paintSelected, row, DarkTableUI.KEY_ALTERNATE_ROW_COLOR,
"Table.alternateRowBackground"); "Table.alternateRowBackground", "Table.selectionNoFocusBackground");
return toggleButton; return toggleButton;
} }

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

@ -71,7 +71,8 @@ public class DarkTableCellRenderer extends DefaultTableCellRenderer {
setupBorderStyle(table, row, column, component, isRowFocus); setupBorderStyle(table, row, column, component, isRowFocus);
CellUtil.setupForeground(component, table, paintSelected, "Table.selectionForegroundInactive"); CellUtil.setupForeground(component, table, paintSelected, "Table.selectionForegroundInactive");
CellUtil.setupBackground(component, table, paintSelected, row, CellUtil.setupBackground(component, table, paintSelected, row,
DarkTableUI.KEY_ALTERNATE_ROW_COLOR, "Table.alternateRowBackground"); DarkTableUI.KEY_ALTERNATE_ROW_COLOR, "Table.alternateRowBackground",
"Table.selectionNoFocusBackground");
return component; return component;
} }

Loading…
Cancel
Save