Browse Source

Tree: Use background color of the tree as the non selected background if it has been specifically set by the user. Selection colors will still overwrite this behaviour.

pull/245/head
weisj 4 years ago
parent
commit
2a1983d0fc
No known key found for this signature in database
GPG Key ID: 31124CB75461DA2A
  1. 36
      core/src/main/java/com/github/weisj/darklaf/ui/cell/CellUtil.java

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

@ -311,22 +311,34 @@ public final class CellUtil {
setupBackground(comp, getTableBackground(comp, parent, selected, hasFocus(parent, comp), row));
}
public static Color getTreeBackground(final JTree tree, final boolean selected, final int row) {
return getTreeBackground(tree, tree, selected, hasFocus(tree, tree), row);
}
public static Color getTreeBackground(final Component comp, final JTree parent, final boolean selected,
final boolean focus, final int row) {
boolean alt = row % 2 == 1 && PropertyUtil.getBooleanProperty(parent, DarkTreeUI.KEY_ALTERNATE_ROW_COLOR);
return getColor(comp, focus, selected, alt ? treeCellBackgroundAlternative : treeCellBackground,
treeCellBackgroundSelected, alt ? treeCellBackgroundNoFocusAlternative : treeCellBackgroundNoFocus,
Color treeBg = parent.getBackground();
boolean canOverwrite = ColorUtil.canOverwriteColor(treeBg);
boolean alt = canOverwrite && row % 2 == 1
&& PropertyUtil.getBooleanProperty(parent, DarkTreeUI.KEY_ALTERNATE_ROW_COLOR);
Color defaultBg = canOverwrite ? treeCellBackground : treeBg;
Color defaultBgNoFocus = canOverwrite ? treeCellBackgroundNoFocus : treeBg;
Color defaultBgInactive = canOverwrite ? treeCellInactiveBackground : treeBg;
Color defaultBgInactiveNoFocus = canOverwrite ? treeCellInactiveBackgroundNoFocus : treeBg;
return getColor(comp.isEnabled(), focus, selected,
alt ? treeCellBackgroundAlternative : defaultBg, treeCellBackgroundSelected,
alt ? treeCellBackgroundNoFocusAlternative : defaultBgNoFocus,
treeCellBackgroundSelectedNoFocus,
alt ? treeCellInactiveBackgroundAlternative : treeCellInactiveBackground,
alt ? treeCellInactiveBackgroundAlternative : defaultBgInactive,
treeCellInactiveBackgroundSelected,
alt ? treeCellInactiveBackgroundNoFocusAlternative : treeCellInactiveBackgroundNoFocus,
alt ? treeCellInactiveBackgroundNoFocusAlternative : defaultBgInactiveNoFocus,
treeCellInactiveBackgroundSelectedNoFocus);
}
public static void setupTreeBackground(final Component comp, final JTree parent, final boolean selected,
final int row) {
Color bg = getTreeBackground(comp, parent, selected, hasFocus(parent, comp), row);
setupBackground(comp, bg);
comp.setBackground(bg);
if (comp instanceof DefaultTreeCellRenderer) {
Color c = comp.getBackground();
if (ColorUtil.canOverwriteColor(c)) {
@ -335,18 +347,6 @@ public final class CellUtil {
}
}
public static Color getTreeBackground(final JTree tree, final boolean selected, final int row) {
boolean alt = row % 2 == 1 && PropertyUtil.getBooleanProperty(tree, DarkTreeUI.KEY_ALTERNATE_ROW_COLOR);
return getColor(tree.isEnabled(), hasFocus(tree, tree), selected,
alt ? treeCellBackgroundAlternative : treeCellBackground, treeCellBackgroundSelected,
alt ? treeCellBackgroundNoFocusAlternative : treeCellBackgroundNoFocus,
treeCellBackgroundSelectedNoFocus,
alt ? treeCellInactiveBackgroundAlternative : treeCellInactiveBackground,
treeCellInactiveBackgroundSelected,
alt ? treeCellInactiveBackgroundNoFocusAlternative : treeCellInactiveBackgroundNoFocus,
treeCellInactiveBackgroundSelectedNoFocus);
}
public static Color getListBackground(final Component comp, final JList<?> parent, final boolean selected,
final int index) {
int layout = parent.getLayoutOrientation();

Loading…
Cancel
Save