mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-200179 Make *.propertyName patterns from UIThemes work with named colors
This commit is contained in:
@@ -232,6 +232,7 @@ public class UITheme {
|
||||
if (key.startsWith("*.")) {
|
||||
String tail = key.substring(1);
|
||||
Object finalValue = value;
|
||||
addPattern(key, value, defaults);
|
||||
|
||||
//please DO NOT stream on UIDefaults directly
|
||||
((UIDefaults)defaults.clone()).keySet().stream()
|
||||
@@ -243,6 +244,18 @@ public class UITheme {
|
||||
}
|
||||
}
|
||||
|
||||
private static void addPattern(String key, Object value, UIDefaults defaults) {
|
||||
Object o = defaults.get("*");
|
||||
if (! (o instanceof Map)) {
|
||||
o = new HashMap<String, Object>();
|
||||
defaults.put("*", o);
|
||||
}
|
||||
Map map = (Map)o;
|
||||
if (key != null && key.startsWith("*.")) {
|
||||
map.put(key.substring(2), value);
|
||||
}
|
||||
}
|
||||
|
||||
public static Object parseValue(String key, @NotNull String value) {
|
||||
if ("null".equals(value)) {
|
||||
return null;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
package com.intellij.ui;
|
||||
|
||||
import com.intellij.util.NotNullProducer;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.containers.hash.HashMap;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -15,6 +14,8 @@ import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.intellij.util.ObjectUtils.notNull;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
@@ -53,11 +54,48 @@ public class JBColor extends Color {
|
||||
@NotNull
|
||||
@Override
|
||||
public Color produce() {
|
||||
return ObjectUtils.notNull(UIManager.getColor(propertyName), defaultColor);
|
||||
Color color = notNull(findPatternMatch(propertyName),
|
||||
notNull(UIManager.getColor(propertyName), defaultColor));
|
||||
if (UIManager.get(propertyName) == null) {
|
||||
UIManager.put(propertyName, color);
|
||||
}
|
||||
return color;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Let's find if namedColor can be overridden by *.propertyName rule in ui theme and apply it
|
||||
// We need to cache calculated results. Cache and rules will be reset after LaF change
|
||||
private static Color findPatternMatch(String name) {
|
||||
Object value = UIManager.get("*");
|
||||
|
||||
if (value instanceof Map) {
|
||||
Color color = null;
|
||||
Map<?,?> map = (Map<?, ?>)value;
|
||||
Object o = UIManager.get("*cache");
|
||||
if (! (o instanceof Map)) {
|
||||
o = new java.util.HashMap<String, Color>();
|
||||
UIManager.put("*cache", o);
|
||||
}
|
||||
Map<String,Color> cache = (Map)o;
|
||||
if (cache.containsKey(name)) {
|
||||
return cache.get(name);
|
||||
}
|
||||
for (Map.Entry<?, ?> entry : map.entrySet()) {
|
||||
if (entry.getKey() instanceof String && name.endsWith(((String)entry.getKey()))) {
|
||||
Object result = map.get(entry.getKey());
|
||||
if (result instanceof Color) {
|
||||
color = (Color)result;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
cache.put(name, color);
|
||||
return color;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Color link() {
|
||||
return new JBColor(new NotNullProducer<Color>() {
|
||||
|
||||
Reference in New Issue
Block a user