IDEA-198801: move renderer colors to JBUI.CurrentTheme

GitOrigin-RevId: 2d1a1f2bd4d146d3e598c6ec0c4e6e2f094645e1
This commit is contained in:
Sergey Malenkov
2020-12-13 13:45:45 +00:00
committed by intellij-monorepo-bot
parent 483e6655f1
commit cfb65ed649
3 changed files with 170 additions and 74 deletions
@@ -2,6 +2,7 @@
package com.intellij.ui.render;
import com.intellij.openapi.util.Key;
import com.intellij.util.ui.JBUI.CurrentTheme;
import com.intellij.util.ui.UIUtil;
import com.intellij.util.ui.tree.WideSelectionTreeUI;
import org.jetbrains.annotations.ApiStatus;
@@ -60,13 +61,13 @@ public final class RenderingUtil {
@NotNull
public static Color getBackground(@NotNull JList<?> list) {
Color background = list.getBackground();
return background != null ? background : UIUtil.getListBackground();
return background != null ? background : CurrentTheme.List.BACKGROUND;
}
@NotNull
public static Color getBackground(@NotNull JTable table) {
Color background = table.getBackground();
return background != null ? background : UIUtil.getTableBackground();
return background != null ? background : CurrentTheme.Table.BACKGROUND;
}
@NotNull
@@ -74,20 +75,20 @@ public final class RenderingUtil {
JTable table = getTableFor(tree);
if (table != null) return getBackground(table); // tree table
Color background = tree.getBackground();
return background != null ? background : UIUtil.getTreeBackground();
return background != null ? background : CurrentTheme.Tree.BACKGROUND;
}
@NotNull
public static Color getSelectionBackground(@NotNull JList<?> list) {
Color background = getCustomSelectionBackground(list);
return background != null ? background : UIUtil.getListSelectionBackground(isFocused(list));
return background != null ? background : CurrentTheme.List.Selection.background(isFocused(list));
}
@NotNull
public static Color getSelectionBackground(@NotNull JTable table) {
Color background = getCustomSelectionBackground(table);
return background != null ? background : UIUtil.getTableSelectionBackground(isFocused(table));
return background != null ? background : CurrentTheme.Table.Selection.background(isFocused(table));
}
@NotNull
@@ -95,7 +96,7 @@ public final class RenderingUtil {
JTable table = getTableFor(tree);
if (table != null) return getSelectionBackground(table); // tree table
Color background = getCustomSelectionBackground(tree);
return background != null ? background : UIUtil.getTreeSelectionBackground(isFocused(tree));
return background != null ? background : CurrentTheme.Tree.Selection.background(isFocused(tree));
}
@@ -118,13 +119,13 @@ public final class RenderingUtil {
@NotNull
public static Color getForeground(@NotNull JList<?> list) {
Color foreground = list.getForeground();
return foreground != null ? foreground : UIUtil.getListForeground();
return foreground != null ? foreground : CurrentTheme.List.FOREGROUND;
}
@NotNull
public static Color getForeground(@NotNull JTable table) {
Color foreground = table.getForeground();
return foreground != null ? foreground : UIUtil.getTableForeground();
return foreground != null ? foreground : CurrentTheme.Table.FOREGROUND;
}
@NotNull
@@ -132,25 +133,25 @@ public final class RenderingUtil {
JTable table = getTableFor(tree);
if (table != null) return getForeground(table); // tree table
Color foreground = tree.getForeground();
return foreground != null ? foreground : UIUtil.getTreeForeground();
return foreground != null ? foreground : CurrentTheme.Tree.FOREGROUND;
}
@NotNull
public static Color getSelectionForeground(@NotNull JList<?> list) {
return UIUtil.getListSelectionForeground(isFocused(list));
return CurrentTheme.List.Selection.foreground(isFocused(list));
}
@NotNull
public static Color getSelectionForeground(@NotNull JTable table) {
return UIUtil.getTableSelectionForeground(isFocused(table));
return CurrentTheme.Table.Selection.foreground(isFocused(table));
}
@NotNull
public static Color getSelectionForeground(@NotNull JTree tree) {
JTable table = getTableFor(tree);
if (table != null) return getSelectionForeground(table); // tree table
return UIUtil.getTreeSelectionForeground(isFocused(tree));
return CurrentTheme.Tree.Selection.foreground(isFocused(tree));
}
@@ -161,19 +162,19 @@ public final class RenderingUtil {
public static @Nullable Color getHoverBackground(@NotNull JList<?> list) {
if (isHoverPaintingDisabled(list)) return null;
return UIUtil.getListHoverBackground(isFocused(list));
return CurrentTheme.List.Hover.background(isFocused(list));
}
public static @Nullable Color getHoverBackground(@NotNull JTable table) {
if (isHoverPaintingDisabled(table)) return null;
return UIUtil.getTableHoverBackground(isFocused(table));
return CurrentTheme.Table.Hover.background(isFocused(table));
}
public static @Nullable Color getHoverBackground(@NotNull JTree tree) {
JTable table = getTableFor(tree);
if (table != null) return getHoverBackground(table); // tree table
if (isHoverPaintingDisabled(tree)) return null;
return UIUtil.getTreeHoverBackground(isFocused(tree));
return CurrentTheme.Tree.Hover.background(isFocused(tree));
}
@@ -1122,6 +1122,144 @@ public class JBUI {
}
}
private static final Color DEFAULT_RENDERER_BACKGROUND = new JBColor(0xFFFFFF, 0x3C3F41);
private static final Color DEFAULT_RENDERER_SELECTION_BACKGROUND = new JBColor(0x3875D6, 0x2F65CA);
private static final Color DEFAULT_RENDERER_SELECTION_INACTIVE_BACKGROUND = new JBColor(0xD4D4D4, 0x0D293E);
private static final Color DEFAULT_RENDERER_HOVER_BACKGROUND = new JBColor(0xEDF5FC, 0x464A4D);
private static final Color DEFAULT_RENDERER_HOVER_INACTIVE_BACKGROUND = new JBColor(0xF5F5F5, 0x464A4D);
public interface List {
Color BACKGROUND = JBColor.namedColor("List.background", DEFAULT_RENDERER_BACKGROUND);
Color FOREGROUND = JBColor.namedColor("List.foreground", Label.foreground(false));
static @NotNull Color background(boolean selected, boolean focused) {
return selected ? Selection.background(focused) : BACKGROUND;
}
static @NotNull Color foreground(boolean selected, boolean focused) {
return selected ? Selection.foreground(focused) : FOREGROUND;
}
final class Selection {
private static final Color BACKGROUND = JBColor.namedColor("List.selectionBackground", DEFAULT_RENDERER_SELECTION_BACKGROUND);
private static final Color FOREGROUND = JBColor.namedColor("List.selectionForeground", Label.foreground(true));
public static @NotNull Color background(boolean focused) {
if (focused && UIUtil.isUnderDefaultMacTheme()) {
double alpha = getInt("List.selectedItemAlpha", 75);
if (0 <= alpha && alpha < 100) return ColorUtil.mix(Color.WHITE, BACKGROUND, alpha / 100.0);
}
return focused ? BACKGROUND : Inactive.BACKGROUND;
}
public static @NotNull Color foreground(boolean focused) {
return focused ? FOREGROUND : Inactive.FOREGROUND;
}
private interface Inactive {
Color BACKGROUND = JBColor.namedColor("List.selectionInactiveBackground", DEFAULT_RENDERER_SELECTION_INACTIVE_BACKGROUND);
Color FOREGROUND = JBColor.namedColor("List.selectionInactiveForeground", List.FOREGROUND);
}
}
final class Hover {
private static final Color BACKGROUND = JBColor.namedColor("List.hoverBackground", DEFAULT_RENDERER_HOVER_BACKGROUND);
public static @NotNull Color background(boolean focused) {
return focused ? BACKGROUND : Inactive.BACKGROUND;
}
private interface Inactive {
Color BACKGROUND = JBColor.namedColor("List.hoverInactiveBackground", DEFAULT_RENDERER_HOVER_INACTIVE_BACKGROUND);
}
}
}
public interface Table {
Color BACKGROUND = JBColor.namedColor("Table.background", DEFAULT_RENDERER_BACKGROUND);
Color FOREGROUND = JBColor.namedColor("Table.foreground", Label.foreground(false));
static @NotNull Color background(boolean selected, boolean focused) {
return selected ? Selection.background(focused) : BACKGROUND;
}
static @NotNull Color foreground(boolean selected, boolean focused) {
return selected ? Selection.foreground(focused) : FOREGROUND;
}
final class Selection {
private static final Color BACKGROUND = JBColor.namedColor("Table.selectionBackground", DEFAULT_RENDERER_SELECTION_BACKGROUND);
private static final Color FOREGROUND = JBColor.namedColor("Table.selectionForeground", Label.foreground(true));
public static @NotNull Color background(boolean focused) {
return focused ? BACKGROUND : Inactive.BACKGROUND;
}
public static @NotNull Color foreground(boolean focused) {
return focused ? FOREGROUND : Inactive.FOREGROUND;
}
private interface Inactive {
Color BACKGROUND = JBColor.namedColor("Table.selectionInactiveBackground", DEFAULT_RENDERER_SELECTION_INACTIVE_BACKGROUND);
Color FOREGROUND = JBColor.namedColor("Table.selectionInactiveForeground", Table.FOREGROUND);
}
}
final class Hover {
private static final Color BACKGROUND = JBColor.namedColor("Table.hoverBackground", DEFAULT_RENDERER_HOVER_BACKGROUND);
public static @NotNull Color background(boolean focused) {
return focused ? BACKGROUND : Inactive.BACKGROUND;
}
private interface Inactive {
Color BACKGROUND = JBColor.namedColor("Table.hoverInactiveBackground", DEFAULT_RENDERER_HOVER_INACTIVE_BACKGROUND);
}
}
}
public interface Tree {
Color BACKGROUND = JBColor.namedColor("Tree.background", DEFAULT_RENDERER_BACKGROUND);
Color FOREGROUND = JBColor.namedColor("Tree.foreground", Label.foreground(false));
static @NotNull Color background(boolean selected, boolean focused) {
return selected ? Selection.background(focused) : BACKGROUND;
}
static @NotNull Color foreground(boolean selected, boolean focused) {
return selected ? Selection.foreground(focused) : FOREGROUND;
}
final class Selection {
private static final Color BACKGROUND = JBColor.namedColor("Tree.selectionBackground", DEFAULT_RENDERER_SELECTION_BACKGROUND);
private static final Color FOREGROUND = JBColor.namedColor("Tree.selectionForeground", Label.foreground(true));
public static @NotNull Color background(boolean focused) {
return focused ? BACKGROUND : Inactive.BACKGROUND;
}
public static @NotNull Color foreground(boolean focused) {
return focused ? FOREGROUND : Inactive.FOREGROUND;
}
private interface Inactive {
Color BACKGROUND = JBColor.namedColor("Tree.selectionInactiveBackground", DEFAULT_RENDERER_SELECTION_INACTIVE_BACKGROUND);
Color FOREGROUND = JBColor.namedColor("Tree.selectionInactiveForeground", Tree.FOREGROUND);
}
}
final class Hover {
private static final Color BACKGROUND = JBColor.namedColor("Tree.hoverBackground", DEFAULT_RENDERER_HOVER_BACKGROUND);
public static @NotNull Color background(boolean focused) {
return focused ? BACKGROUND : Inactive.BACKGROUND;
}
private interface Inactive {
Color BACKGROUND = JBColor.namedColor("Tree.hoverInactiveBackground", DEFAULT_RENDERER_HOVER_INACTIVE_BACKGROUND);
}
}
}
}
public static int getInt(@NonNls @NotNull String propertyName, int defaultValue) {
@@ -3128,39 +3128,6 @@ public final class UIUtil {
}
private static final Color BACKGROUND = new JBColor(0xFFFFFF, 0x3C3F41);
private static final Color LIST_BACKGROUND = JBColor.namedColor("List.background", BACKGROUND);
private static final Color TREE_BACKGROUND = JBColor.namedColor("Tree.background", BACKGROUND);
private static final Color TABLE_BACKGROUND = JBColor.namedColor("Table.background", BACKGROUND);
private static final class FocusedSelection {
private static final Color BACKGROUND = new JBColor(0x3875D6, 0x2F65CA);
private static final Color TREE_BACKGROUND = JBColor.namedColor("Tree.selectionBackground", BACKGROUND);
private static final Color TABLE_BACKGROUND = JBColor.namedColor("Table.selectionBackground", BACKGROUND);
}
private static final class UnfocusedSelection {
private static final Color BACKGROUND = new JBColor(0xD4D4D4, 0x0D293E);
private static final Color LIST_BACKGROUND = JBColor.namedColor("List.selectionInactiveBackground", BACKGROUND);
private static final Color TREE_BACKGROUND = JBColor.namedColor("Tree.selectionInactiveBackground", BACKGROUND);
private static final Color TABLE_BACKGROUND = JBColor.namedColor("Table.selectionInactiveBackground", BACKGROUND);
}
private static final class FocusedHover {
private static final Color BACKGROUND = new JBColor(0xEDF5FC, 0x464A4D);
private static final Color LIST_BACKGROUND = JBColor.namedColor("List.hoverBackground", BACKGROUND);
private static final Color TREE_BACKGROUND = JBColor.namedColor("Tree.hoverBackground", BACKGROUND);
private static final Color TABLE_BACKGROUND = JBColor.namedColor("Table.hoverBackground", BACKGROUND);
}
private static final class UnfocusedHover {
private static final Color BACKGROUND = new JBColor(0xF5F5F5, 0x464A4D);
private static final Color LIST_BACKGROUND = JBColor.namedColor("List.hoverInactiveBackground", BACKGROUND);
private static final Color TREE_BACKGROUND = JBColor.namedColor("Tree.hoverInactiveBackground", BACKGROUND);
private static final Color TABLE_BACKGROUND = JBColor.namedColor("Table.hoverInactiveBackground", BACKGROUND);
}
// List
public static @NotNull Font getListFont() {
@@ -3174,20 +3141,14 @@ public final class UIUtil {
* @see RenderingUtil#getBackground(JList)
*/
public static @NotNull Color getListBackground() {
return LIST_BACKGROUND;
return JBUI.CurrentTheme.List.BACKGROUND;
}
private static final JBValue SELECTED_ITEM_ALPHA = new JBValue.UIInteger("List.selectedItemAlpha", 75);
/**
* @see RenderingUtil#getSelectionBackground(JList)
*/
public static @NotNull Color getListSelectionBackground(boolean focused) {
if (!focused) return UnfocusedSelection.LIST_BACKGROUND;
Color color = UIManager.getColor("List.selectionBackground");
double alpha = SELECTED_ITEM_ALPHA.getFloat() / 100.0;
//noinspection UseJBColor
return isUnderDefaultMacTheme() && alpha >= 0 && alpha <= 1.0 ? ColorUtil.mix(Color.WHITE, color, alpha) : color;
return JBUI.CurrentTheme.List.Selection.background(focused);
}
public static @NotNull Dimension updateListRowHeight(@NotNull Dimension size) {
@@ -3228,7 +3189,7 @@ public final class UIUtil {
@ApiStatus.Experimental
public static @NotNull Color getListHoverBackground(boolean focused) {
return focused ? FocusedHover.LIST_BACKGROUND : UnfocusedHover.LIST_BACKGROUND;
return JBUI.CurrentTheme.List.Hover.background(focused);
}
// foreground
@@ -3237,16 +3198,14 @@ public final class UIUtil {
* @see RenderingUtil#getForeground(JList)
*/
public static @NotNull Color getListForeground() {
return UIManager.getColor("List.foreground");
return JBUI.CurrentTheme.List.FOREGROUND;
}
/**
* @see RenderingUtil#getSelectionForeground(JList)
*/
public static @NotNull Color getListSelectionForeground(boolean focused) {
Color foreground = UIManager.getColor(focused ? "List.selectionForeground" : "List.selectionInactiveForeground");
if (focused && foreground == null) foreground = UIManager.getColor("List[Selected].textForeground"); // Nimbus
return foreground != null ? foreground : getListForeground();
return JBUI.CurrentTheme.List.Selection.foreground(focused);
}
/**
@@ -3285,14 +3244,14 @@ public final class UIUtil {
* @see RenderingUtil#getBackground(JTree)
*/
public static @NotNull Color getTreeBackground() {
return TREE_BACKGROUND;
return JBUI.CurrentTheme.Tree.BACKGROUND;
}
/**
* @see RenderingUtil#getSelectionBackground(JTree)
*/
public static @NotNull Color getTreeSelectionBackground(boolean focused) {
return focused ? FocusedSelection.TREE_BACKGROUND : UnfocusedSelection.TREE_BACKGROUND;
return JBUI.CurrentTheme.Tree.Selection.background(focused);
}
/**
@@ -3320,7 +3279,7 @@ public final class UIUtil {
@ApiStatus.Experimental
public static @NotNull Color getTreeHoverBackground(boolean focused) {
return focused ? FocusedHover.TREE_BACKGROUND : UnfocusedHover.TREE_BACKGROUND;
return JBUI.CurrentTheme.Tree.Hover.background(focused);
}
// foreground
@@ -3329,15 +3288,14 @@ public final class UIUtil {
* @see RenderingUtil#getForeground(JTree)
*/
public static @NotNull Color getTreeForeground() {
return UIManager.getColor("Tree.foreground");
return JBUI.CurrentTheme.Tree.FOREGROUND;
}
/**
* @see RenderingUtil#getSelectionForeground(JTree)
*/
public static @NotNull Color getTreeSelectionForeground(boolean focused) {
Color foreground = UIManager.getColor(focused ? "Tree.selectionForeground" : "Tree.selectionInactiveForeground");
return foreground != null ? foreground : getTreeForeground();
return JBUI.CurrentTheme.Tree.Selection.foreground(focused);
}
/**
@@ -3359,14 +3317,14 @@ public final class UIUtil {
* @see RenderingUtil#getBackground(JTable)
*/
public static @NotNull Color getTableBackground() {
return TABLE_BACKGROUND;
return JBUI.CurrentTheme.Table.BACKGROUND;
}
/**
* @see RenderingUtil#getSelectionBackground(JTable)
*/
public static @NotNull Color getTableSelectionBackground(boolean focused) {
return focused ? FocusedSelection.TABLE_BACKGROUND : UnfocusedSelection.TABLE_BACKGROUND;
return JBUI.CurrentTheme.Table.Selection.background(focused);
}
/**
@@ -3402,7 +3360,7 @@ public final class UIUtil {
@ApiStatus.Experimental
public static @NotNull Color getTableHoverBackground(boolean focused) {
return focused ? FocusedHover.TABLE_BACKGROUND : UnfocusedHover.TABLE_BACKGROUND;
return JBUI.CurrentTheme.Table.Hover.background(focused);
}
// foreground
@@ -3411,15 +3369,14 @@ public final class UIUtil {
* @see RenderingUtil#getForeground(JTable)
*/
public static @NotNull Color getTableForeground() {
return UIManager.getColor("Table.foreground");
return JBUI.CurrentTheme.Table.FOREGROUND;
}
/**
* @see RenderingUtil#getSelectionForeground(JTable)
*/
public static @NotNull Color getTableSelectionForeground(boolean focused) {
Color foreground = UIManager.getColor(focused ? "Table.selectionForeground" : "Table.selectionInactiveForeground");
return foreground != null ? foreground : getTreeForeground();
return JBUI.CurrentTheme.Table.Selection.foreground(focused);
}
/**
@@ -3442,7 +3399,7 @@ public final class UIUtil {
*/
@Deprecated
public static @NotNull Color getTableSelectionForeground() {
return UIManager.getColor("Table.selectionForeground");
return getTableSelectionForeground(true);
}
/**