IDEA-239720 THEMES: Please add option to add background image to empty frame only

GitOrigin-RevId: 428ee1fc85ef359e2e15d7c8edf7d165e891dd7d
This commit is contained in:
Konstantin Bulenkov
2020-06-07 19:19:48 +00:00
committed by intellij-monorepo-bot
parent a3835e24a7
commit dcc13fefcc
4 changed files with 115 additions and 87 deletions
@@ -63,6 +63,7 @@ public class UITheme {
private Map<String, Object> icons;
private IconPathPatcher patcher;
private Map<String, Object> background;
private Map<String, Object> emptyFrameBackground;
private Map<String, Object> colors;
private ClassLoader providerClassLoader = getClass().getClassLoader();
private String editorSchemeName;
@@ -323,6 +324,10 @@ public class UITheme {
return background;
}
public Map<String, Object> getEmptyFrameBackground() {
return emptyFrameBackground;
}
public void applyProperties(UIDefaults defaults) {
if (ui == null) return;
@@ -600,10 +605,7 @@ public class UITheme {
}
}
//
//json deserialization methods
//
//<editor-fold desc="JSON deserialization methods">
@SuppressWarnings("unused")
private void setName(String name) {
this.name = name;
@@ -638,6 +640,10 @@ public class UITheme {
this.background = background;
}
public void setEmptyFrameBackground(Map<String, Object> emptyFrameBackground) {
this.emptyFrameBackground = emptyFrameBackground;
}
public Map<String, Object> getColors() {
return colors;
}
@@ -645,4 +651,5 @@ public class UITheme {
public void setColors(Map<String, Object> colors) {
this.colors = colors;
}
//</editor-fold>
}
@@ -99,10 +99,14 @@ public class UIThemeBasedLookAndFeelInfo extends UIManager.LookAndFeelInfo {
}
private void installBackgroundImage() {
installBackgroundImage(myTheme.getBackground(), IdeBackgroundUtil.EDITOR_PROP);
installBackgroundImage(myTheme.getEmptyFrameBackground(), IdeBackgroundUtil.FRAME_PROP);
}
private void installBackgroundImage(Map<String, Object> backgroundProps, String bgImageProperty) {
try {
Map<String, Object> background = myTheme.getBackground();
if (background != null) {
Object path = background.get("image");
if (backgroundProps != null) {
Object path = backgroundProps.get("image");
if (path instanceof String) {
File tmpImage = FileUtil.createTempFile("ijBackgroundImage", path.toString().substring(((String)path).lastIndexOf(".")), true);
URL resource = myTheme.getResource((String)path);
@@ -114,16 +118,16 @@ public class UIThemeBasedLookAndFeelInfo extends UIManager.LookAndFeelInfo {
}
String image = tmpImage.getPath();
Object transparency = background.get("transparency");
Object transparency = backgroundProps.get("transparency");
String alpha = String.valueOf(transparency instanceof Integer ? (int)transparency : 15);
String fill = parseEnumValue(background.get("fill"), IdeBackgroundUtil.Fill.SCALE);
String anchor = parseEnumValue(background.get("anchor"), IdeBackgroundUtil.Anchor.CENTER);
String fill = parseEnumValue(backgroundProps.get("fill"), IdeBackgroundUtil.Fill.SCALE);
String anchor = parseEnumValue(backgroundProps.get("anchor"), IdeBackgroundUtil.Anchor.CENTER);
String spec = StringUtil.join(new String[]{image, alpha, fill, anchor}, ",");
String currentSpec = PropertiesComponent.getInstance().getValue(IdeBackgroundUtil.EDITOR_PROP);
PropertiesComponent.getInstance().setValue("old." + IdeBackgroundUtil.EDITOR_PROP, currentSpec);
String currentSpec = PropertiesComponent.getInstance().getValue(bgImageProperty);
PropertiesComponent.getInstance().setValue("old." + bgImageProperty, currentSpec);
PropertiesComponent.getInstance().setValue(IdeBackgroundUtil.EDITOR_PROP, spec);
PropertiesComponent.getInstance().setValue(bgImageProperty, spec);
IdeBackgroundUtil.repaintAllWindows();
}
else {
@@ -156,15 +160,20 @@ public class UIThemeBasedLookAndFeelInfo extends UIManager.LookAndFeelInfo {
}
SVGLoader.setColorPatcherProvider(null);
unsetBackgroundProperties(IdeBackgroundUtil.EDITOR_PROP);
unsetBackgroundProperties(IdeBackgroundUtil.FRAME_PROP);
}
private void unsetBackgroundProperties(String backgroundPropertyKey) {
PropertiesComponent propertyManager = PropertiesComponent.getInstance();
String value = propertyManager.getValue("old." + IdeBackgroundUtil.EDITOR_PROP);
propertyManager.unsetValue("old." + IdeBackgroundUtil.EDITOR_PROP);
String value = propertyManager.getValue("old." + backgroundPropertyKey);
propertyManager.unsetValue("old." + backgroundPropertyKey);
if (value == null) {
if (myTheme.getBackground() != null) {
propertyManager.unsetValue(IdeBackgroundUtil.EDITOR_PROP);
propertyManager.unsetValue(backgroundPropertyKey);
}
} else {
propertyManager.setValue(IdeBackgroundUtil.EDITOR_PROP, value);
propertyManager.setValue(backgroundPropertyKey, value);
}
}
}
@@ -1,5 +1,5 @@
{
"version": "0.3",
"version": "0.4",
"definitions": {
"color": {
"type": "string",
@@ -10,6 +10,71 @@
"#123abc", "#123abc80"
]
},
"background": {
"type": "object",
"required": [
"image"
],
"title": "Background image",
"description": "Background image for entire window",
"properties": {
"image": {
"type": "string",
"title": "Path to the background image",
"description": "Path to the background image starting with '/'",
"default": "",
"examples": [
"/background.jpg"
]
},
"transparency": {
"type": "integer",
"title": "Transparency for background image.",
"description": "An integer from 0 to 100.",
"default": 10,
"minimum": 0,
"maximum": 100,
"examples": [
10
]
},
"fill": {
"type": "string",
"title": "Background image filling options",
"default": "scale",
"description": "Background image filling options. One of the following values: plain, scale, tile",
"enum": [
"plain",
"scale",
"tile"
],
"examples": [
"scale"
]
},
"anchor": {
"type": "string",
"title": "Background image anchor",
"default": "center",
"description": "Background image anchor. One of the following values: top_left, top_center, top_right, middle_left, center, middle_right, bottom_left, bottom_center, bottom_right",
"enum": [
"top_left",
"top_center",
"top_right",
"middle_left",
"center",
"middle_right",
"bottom_left",
"bottom_center",
"bottom_right"
],
"examples": [
"center"
]
}
}
},
"ColorPaletteBase": {
"type": "object",
"properties": {
@@ -222,68 +287,10 @@
"type": "object"
},
"background": {
"type": "object",
"required": [
"image"
],
"title": "Background image",
"description": "Background image for entire window",
"properties": {
"image": {
"type": "string",
"title": "Path to the background image",
"description": "Path to the background image starting with '/'",
"default": "",
"examples": [
"/background.jpg"
]
},
"transparency": {
"type": "integer",
"title": "Transparency for background image.",
"description": "An integer from 0 to 100.",
"default": 10,
"minimum": 0,
"maximum": 100,
"examples": [
10
]
},
"fill": {
"type": "string",
"title": "Background image filling options",
"default": "scale",
"description": "Background image filling options. One of the following values: plain, scale, tile",
"enum": [
"plain",
"scale",
"tile"
],
"examples": [
"scale"
]
},
"anchor": {
"type": "string",
"title": "Background image anchor",
"default": "center",
"description": "Background image anchor. One of the following values: top_left, top_center, top_right, middle_left, center, middle_right, bottom_left, bottom_center, bottom_right",
"enum": [
"top_left",
"top_center",
"top_right",
"middle_left",
"center",
"middle_right",
"bottom_left",
"bottom_center",
"bottom_right"
],
"examples": [
"center"
]
}
}
"$ref": "#/definitions/background"
},
"emptyFrameBackground": {
"$ref": "#/definitions/background"
},
"icons": {
"type": "object",
@@ -77,13 +77,9 @@ public class ApplyThemeAction extends DumbAwareAction {
if (pathToScheme != null) {
editorScheme = findThemeFile(json, project, pathToScheme);
}
Map<String, Object> background = theme.getBackground();
if (background != null) {
VirtualFile pathToBg = findThemeFile(json, project, background.get("image").toString());
if (pathToBg != null) {
background.put("image", pathToBg.getPath());
}
}
patchBackgroundImagePath(json, project, theme.getBackground());
patchBackgroundImagePath(json, project, theme.getEmptyFrameBackground());
LafManager.getInstance().setCurrentLookAndFeel(new TempUIThemeBasedLookAndFeelInfo(theme, editorScheme));
IconLoader.clearCache();
@@ -94,6 +90,15 @@ public class ApplyThemeAction extends DumbAwareAction {
return false;
}
private static void patchBackgroundImagePath(@NotNull VirtualFile json, Project project, Map<String, Object> background) {
if (background != null) {
VirtualFile pathToBg = findThemeFile(json, project, background.get("image").toString());
if (pathToBg != null) {
background.put("image", pathToBg.getPath());
}
}
}
@Nullable
private static VirtualFile findThemeFile(@NotNull VirtualFile json, Project project, String pathToFile) {
Module module = ModuleUtilCore.findModuleForFile(json, project);