diff --git a/platform/platform-api/src/com/intellij/ui/components/WideSelectionListUI.java b/platform/platform-api/src/com/intellij/ui/components/WideSelectionListUI.java index 60bd95266263..5e6d54703257 100644 --- a/platform/platform-api/src/com/intellij/ui/components/WideSelectionListUI.java +++ b/platform/platform-api/src/com/intellij/ui/components/WideSelectionListUI.java @@ -1,8 +1,11 @@ // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ui.components; +import com.intellij.openapi.util.ColoredItem; import com.intellij.ui.list.ListCellBackgroundSupplier; import com.intellij.util.ui.UIUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.plaf.ComponentUI; @@ -36,11 +39,7 @@ public final class WideSelectionListUI extends BasicListUI { boolean selected = selectionModel.isSelectedIndex(row); boolean focused = row == leadSelectionIndex && list.hasFocus(); Object value = model.getElementAt(row); - Color background = null; - if (list instanceof ListCellBackgroundSupplier) { - //noinspection unchecked - background = ((ListCellBackgroundSupplier)list).getCellBackground(value, row); - } + Color background = getBackground(list, value, row); if (background != null) { g.setColor(background); g.fillRect(rowBounds.x, rowBounds.y, rowBounds.width, rowBounds.height); @@ -57,6 +56,20 @@ public final class WideSelectionListUI extends BasicListUI { super.paintCell(g, row, rowBounds, renderer, model, selectionModel, leadSelectionIndex); } + @Nullable + private static Color getBackground(@NotNull JList list, @Nullable Object value, int row) { + if (value instanceof ColoredItem) { + Color background = ((ColoredItem)value).getColor(); + if (background != null) return background; + } + if (list instanceof ListCellBackgroundSupplier) { + //noinspection unchecked + Color background = ((ListCellBackgroundSupplier)list).getCellBackground(value, row); + if (background != null) return background; + } + return null; + } + private static void paintRenderer(Graphics g, int x, int y, int width, int height, Component owner, Component renderer) { g.clipRect(0, y, owner.getWidth(), height); paintBackground(g, y, height, owner, renderer); diff --git a/platform/platform-impl/src/com/intellij/ui/tree/ui/DefaultTreeUI.java b/platform/platform-impl/src/com/intellij/ui/tree/ui/DefaultTreeUI.java index f3dc108c54e0..b048ef7bd6ad 100644 --- a/platform/platform-impl/src/com/intellij/ui/tree/ui/DefaultTreeUI.java +++ b/platform/platform-impl/src/com/intellij/ui/tree/ui/DefaultTreeUI.java @@ -2,6 +2,7 @@ package com.intellij.ui.tree.ui; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.util.ColoredItem; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.SystemInfo; import com.intellij.ui.components.JBScrollPane; @@ -66,6 +67,10 @@ public final class DefaultTreeUI extends BasicTreeUI { return UIUtil.getTreeSelectionBackground(tree.hasFocus() || Boolean.TRUE.equals(property)); } Object node = TreeUtil.getLastUserObject(path); + if (node instanceof ColoredItem) { + Color background = ((ColoredItem)node).getColor(); + if (background != null) return background; + } if (node instanceof TreeNodeBackgroundSupplier) { TreeNodeBackgroundSupplier supplier = (TreeNodeBackgroundSupplier)node; Color background = supplier.getNodeBackground(row); diff --git a/platform/util/src/com/intellij/openapi/util/ColoredItem.java b/platform/util/src/com/intellij/openapi/util/ColoredItem.java new file mode 100644 index 000000000000..81e26fce1d36 --- /dev/null +++ b/platform/util/src/com/intellij/openapi/util/ColoredItem.java @@ -0,0 +1,14 @@ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.openapi.util; + +import org.jetbrains.annotations.Nullable; + +import java.awt.*; + +/** + * @author gregsh + */ +public interface ColoredItem { + @Nullable + Color getColor(); +}