ui: allow to override background color for Editor notification panel

This commit is contained in:
Aleksey Pivovarov
2016-11-30 17:28:27 +03:00
committed by Aleksey Pivovarov
parent 1eed340cde
commit 1e42810fda
7 changed files with 35 additions and 56 deletions
@@ -34,7 +34,6 @@ import com.intellij.psi.impl.source.PsiExtensibleClass
import com.intellij.ui.EditorNotificationPanel
import com.intellij.ui.EditorNotifications
import com.intellij.ui.LightColors
import java.awt.Color
class LibrarySourceNotificationProvider(private val project: Project, notifications: EditorNotifications) :
EditorNotifications.Provider<EditorNotificationPanel>() {
@@ -60,7 +59,8 @@ class LibrarySourceNotificationProvider(private val project: Project, notificati
if (offender != null) {
val clsFile = offender.originalElement.containingFile?.virtualFile
if (clsFile != null && !clsFile.path.matches(ANDROID_SDK_PATTERN)) {
val panel = ColoredNotificationPanel(LightColors.RED)
val panel = EditorNotificationPanel()
panel.background(LightColors.RED)
panel.setText(ProjectBundle.message("library.source.mismatch", offender.name))
panel.createActionLabel(ProjectBundle.message("library.source.open.class"), {
OpenFileDescriptor(project, clsFile, -1).navigate(true)
@@ -95,7 +95,3 @@ class LibrarySourceNotificationProvider(private val project: Project, notificati
.filter { !(it.isConstructor && it.parameterList.parametersCount == 0) }
private fun inners(clazz: PsiClass) = (clazz as? PsiExtensibleClass)?.ownInnerClasses ?: clazz.innerClasses.asList()
}
private class ColoredNotificationPanel(private val color: Color?) : EditorNotificationPanel() {
override fun getBackground(): Color? = color ?: super.getBackground()
}
@@ -30,7 +30,6 @@ import com.jetbrains.jsonSchema.ide.JsonSchemaService;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
@@ -67,12 +66,8 @@ public class JsonSchemaConflictNotificationProvider extends EditorNotifications.
final String message = worker.createMessage(descriptors);
if (message == null) return null;
final EditorNotificationPanel panel = new EditorNotificationPanel() {
@Override
public Color getBackground() {
return LightColors.RED;
}
};
final EditorNotificationPanel panel = new EditorNotificationPanel();
panel.background(LightColors.RED);
panel.setText(message);
panel.createActionLabel("Edit JSON Schema Mappings", () -> {
ShowSettingsUtil.getInstance().editConfigurable(myProject, new JsonSchemaMappingsConfigurable(myProject));
@@ -87,27 +87,13 @@ public class DiffNotifications {
@NotNull
public static JPanel createNotification(@NotNull String text, @Nullable final Color background, boolean showHideAction) {
final MyEditorNotificationPanel panel = new MyEditorNotificationPanel();
final EditorNotificationPanel panel = new EditorNotificationPanel();
panel.text(text);
panel.setBackgroundColor(background);
panel.background(background);
if (showHideAction) {
HyperlinkLabel link = panel.createActionLabel("Hide", () -> panel.setVisible(false));
link.setToolTipText("Hide this notification");
}
return panel;
}
private static class MyEditorNotificationPanel extends EditorNotificationPanel {
@Nullable private Color myBackground;
public void setBackgroundColor(@Nullable Color value) {
myBackground = value;
}
@Override
@Nullable
public Color getBackground() {
return myBackground != null ? myBackground : super.getBackground();
}
}
}
@@ -48,7 +48,6 @@ import java.util.List;
*/
public class FileLevelIntentionComponent extends EditorNotificationPanel {
private final Project myProject;
private final Color myBackground;
public FileLevelIntentionComponent(final String description,
@NotNull HighlightSeverity severity,
@@ -58,7 +57,7 @@ public class FileLevelIntentionComponent extends EditorNotificationPanel {
@NotNull final PsiFile psiFile,
@NotNull final Editor editor, @Nullable String tooltip) {
myProject = project;
myBackground = getColor(severity);
background(getColor(severity));
final ShowIntentionsPass.IntentionsInfo info = new ShowIntentionsPass.IntentionsInfo();
@@ -106,11 +105,6 @@ public class FileLevelIntentionComponent extends EditorNotificationPanel {
}
}
@Override
public Color getBackground() {
return myBackground;
}
@NotNull
private Color getColor(@NotNull HighlightSeverity severity) {
if (SeverityRegistrar.getSeverityRegistrar(myProject).compare(severity, HighlightSeverity.ERROR) >= 0) {
@@ -24,8 +24,10 @@ import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorBundle;
import com.intellij.openapi.editor.colors.ColorKey;
import com.intellij.openapi.editor.colors.EditorColors;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Iconable;
import com.intellij.openapi.util.Weighted;
@@ -55,6 +57,8 @@ public class EditorNotificationPanel extends JPanel implements IntentionActionPr
protected final JLabel myLabel = new JLabel();
protected final JLabel myGearLabel = new JLabel();
protected final JPanel myLinksPanel = new NonOpaquePanel(new HorizontalLayout(JBUI.scale(5)));
protected Color myBackgroundColor;
protected ColorKey myBackgroundColorKey;
public EditorNotificationPanel() {
super(new BorderLayout());
@@ -79,6 +83,16 @@ public class EditorNotificationPanel extends JPanel implements IntentionActionPr
return this;
}
public EditorNotificationPanel background(@Nullable Color color) {
myBackgroundColor = color;
return this;
}
public EditorNotificationPanel background(@Nullable ColorKey colorKey) {
myBackgroundColorKey = colorKey;
return this;
}
public EditorNotificationPanel icon(@NotNull Icon icon) {
myLabel.setIcon(icon);
return this;
@@ -86,8 +100,14 @@ public class EditorNotificationPanel extends JPanel implements IntentionActionPr
@Override
public Color getBackground() {
Color color = EditorColorsManager.getInstance().getGlobalScheme().getColor(EditorColors.NOTIFICATION_BACKGROUND);
return color == null ? UIUtil.getToolTipBackground() : color;
EditorColorsScheme globalScheme = EditorColorsManager.getInstance().getGlobalScheme();
if (myBackgroundColor != null) return myBackgroundColor;
if (myBackgroundColorKey != null) {
Color color = globalScheme.getColor(myBackgroundColorKey);
if (color != null) return color;
}
Color color = globalScheme.getColor(EditorColors.NOTIFICATION_BACKGROUND);
return color != null ? color : UIUtil.getToolTipBackground();
}
public HyperlinkLabel createActionLabel(final String text, @NonNls final String actionId) {
@@ -18,7 +18,6 @@ import org.editorconfig.core.EditorConfig;
import org.editorconfig.settings.EditorConfigSettings;
import org.jetbrains.annotations.NotNull;
import java.awt.*;
import java.util.List;
/**
@@ -43,13 +42,10 @@ public class EditorConfigNotifierProvider extends EditorNotifications.Provider<E
final List<EditorConfig.OutPair> pairs = SettingsProviderComponent.getInstance().getOutPairs(project, Utils.getFilePath(project, file));
if (!pairs.isEmpty()) {
final EditorNotificationPanel panel = new EditorNotificationPanel() {
@Override
public Color getBackground() {
return LightColors.GREEN;
}
}.text("EditorConfig is overriding Code Style settings for this file").
icon(EditorconfigIcons.Editorconfig);
final EditorNotificationPanel panel = new EditorNotificationPanel()
.background(LightColors.GREEN)
.text("EditorConfig is overriding Code Style settings for this file")
.icon(EditorconfigIcons.Editorconfig);
panel.createActionLabel("OK", () -> {
PropertiesComponent.getInstance(project).setValue(EDITOR_CONFIG_ACCEPTED, true);
EditorNotifications.getInstance(project).updateAllNotifications();
@@ -3,7 +3,6 @@ package com.jetbrains.edu.coursecreator;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.colors.EditorColors;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.project.DumbAware;
@@ -32,10 +31,8 @@ import com.jetbrains.edu.learning.courseFormat.TaskFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.awt.*;
import java.io.IOException;
import java.util.*;
import java.util.List;
public class CCSubtaskEditorNotificationProvider extends EditorNotifications.Provider<EditorNotificationPanel> implements DumbAware {
private static final Key<EditorNotificationPanel> KEY = Key.create("edu.coursecreator.subtask");
@@ -68,13 +65,8 @@ public class CCSubtaskEditorNotificationProvider extends EditorNotifications.Pro
if (task == null || !task.hasSubtasks()) {
return null;
}
EditorNotificationPanel panel = new EditorNotificationPanel() {
@Override
public Color getBackground() {
Color color = EditorColorsManager.getInstance().getGlobalScheme().getColor(EditorColors.GUTTER_BACKGROUND);
return color == null ? super.getBackground() : color;
}
};
EditorNotificationPanel panel = new EditorNotificationPanel();
panel.background(EditorColors.GUTTER_BACKGROUND);
String header = (isTestFile ? "test" : "task") + " file";
int activeSubtaskIndex = task.getActiveSubtaskIndex() + 1;
int subtaskSize = task.getLastSubtaskIndex() + 1;