mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Fix custom selection background in a TreeTable in Editor's tab
GitOrigin-RevId: c3a1feb787150ee8c311347405f06043d2fac6e1
This commit is contained in:
committed by
intellij-monorepo-bot
parent
8063082fa4
commit
6567cf5cfe
@@ -9,6 +9,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.Color;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public final class RenderingUtil {
|
||||
/**
|
||||
@@ -26,6 +27,12 @@ public final class RenderingUtil {
|
||||
@ApiStatus.Internal
|
||||
public static final Key<JComponent> FOCUSABLE_SIBLING = Key.create("FOCUSABLE_SIBLING");
|
||||
|
||||
/**
|
||||
* This key can be set to provide a custom selection background.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public static final Key<Supplier<Color>> CUSTOM_SELECTION_BACKGROUND = Key.create("CUSTOM_SELECTION_BACKGROUND");
|
||||
|
||||
|
||||
@NotNull
|
||||
public static Color getBackground(@NotNull JList<?> list, boolean selected) {
|
||||
@@ -66,19 +73,22 @@ public final class RenderingUtil {
|
||||
|
||||
@NotNull
|
||||
public static Color getSelectionBackground(@NotNull JList<?> list) {
|
||||
return UIUtil.getListSelectionBackground(isFocused(list));
|
||||
Color background = getCustomSelectionBackground(list);
|
||||
return background != null ? background : UIUtil.getListSelectionBackground(isFocused(list));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Color getSelectionBackground(@NotNull JTable table) {
|
||||
return UIUtil.getTableSelectionBackground(isFocused(table));
|
||||
Color background = getCustomSelectionBackground(table);
|
||||
return background != null ? background : UIUtil.getTableSelectionBackground(isFocused(table));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Color getSelectionBackground(@NotNull JTree tree) {
|
||||
JTable table = getTableFor(tree);
|
||||
if (table != null) return getSelectionBackground(table); // tree table
|
||||
return UIUtil.getTreeSelectionBackground(isFocused(tree));
|
||||
Color background = getCustomSelectionBackground(tree);
|
||||
return background != null ? background : UIUtil.getTreeSelectionBackground(isFocused(tree));
|
||||
}
|
||||
|
||||
|
||||
@@ -154,4 +164,9 @@ public final class RenderingUtil {
|
||||
JComponent sibling = UIUtil.getClientProperty(tree, FOCUSABLE_SIBLING);
|
||||
return sibling instanceof JTable ? (JTable)sibling : null;
|
||||
}
|
||||
|
||||
private static Color getCustomSelectionBackground(@NotNull JComponent component) {
|
||||
Supplier<Color> supplier = UIUtil.getClientProperty(component, CUSTOM_SELECTION_BACKGROUND);
|
||||
return supplier == null ? null : supplier.get();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user