[fix] ui: allow to override background color for Editor notification panel

pass background color in constructor, so it could be used in `createActionLabel` call

follow-up: 0de9910, 1e42810, 9089601
This commit is contained in:
Aleksey Pivovarov
2016-12-01 20:21:48 +03:00
parent 5b30ac1531
commit 52d9d450f4
7 changed files with 19 additions and 24 deletions
@@ -59,8 +59,7 @@ 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 = EditorNotificationPanel()
panel.background(LightColors.RED)
val panel = EditorNotificationPanel(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)
@@ -66,8 +66,7 @@ public class JsonSchemaConflictNotificationProvider extends EditorNotifications.
final String message = worker.createMessage(descriptors);
if (message == null) return null;
final EditorNotificationPanel panel = new EditorNotificationPanel();
panel.background(LightColors.RED);
final EditorNotificationPanel panel = new EditorNotificationPanel(LightColors.RED);
panel.setText(message);
panel.createActionLabel("Edit JSON Schema Mappings", () -> {
ShowSettingsUtil.getInstance().editConfigurable(myProject, new JsonSchemaMappingsConfigurable(myProject));
@@ -87,9 +87,8 @@ public class DiffNotifications {
@NotNull
public static JPanel createNotification(@NotNull String text, @Nullable final Color background, boolean showHideAction) {
final EditorNotificationPanel panel = new EditorNotificationPanel();
final EditorNotificationPanel panel = new EditorNotificationPanel(background);
panel.text(text);
panel.background(background);
if (showHideAction) {
HyperlinkLabel link = panel.createActionLabel("Hide", () -> panel.setVisible(false));
link.setToolTipText("Hide this notification");
@@ -56,8 +56,8 @@ public class FileLevelIntentionComponent extends EditorNotificationPanel {
@NotNull final Project project,
@NotNull final PsiFile psiFile,
@NotNull final Editor editor, @Nullable String tooltip) {
super(getColor(project, severity));
myProject = project;
background(getColor(severity));
final ShowIntentionsPass.IntentionsInfo info = new ShowIntentionsPass.IntentionsInfo();
@@ -106,12 +106,12 @@ public class FileLevelIntentionComponent extends EditorNotificationPanel {
}
@NotNull
private Color getColor(@NotNull HighlightSeverity severity) {
if (SeverityRegistrar.getSeverityRegistrar(myProject).compare(severity, HighlightSeverity.ERROR) >= 0) {
private static Color getColor(@NotNull Project project, @NotNull HighlightSeverity severity) {
if (SeverityRegistrar.getSeverityRegistrar(project).compare(severity, HighlightSeverity.ERROR) >= 0) {
return LightColors.RED;
}
if (SeverityRegistrar.getSeverityRegistrar(myProject).compare(severity, HighlightSeverity.WARNING) >= 0) {
if (SeverityRegistrar.getSeverityRegistrar(project).compare(severity, HighlightSeverity.WARNING) >= 0) {
return LightColors.YELLOW;
}
@@ -60,6 +60,16 @@ public class EditorNotificationPanel extends JPanel implements IntentionActionPr
protected Color myBackgroundColor;
protected ColorKey myBackgroundColorKey;
public EditorNotificationPanel(@Nullable Color backgroundColor) {
this();
myBackgroundColor = backgroundColor;
}
public EditorNotificationPanel(@Nullable ColorKey backgroundColorKey) {
this();
myBackgroundColorKey = backgroundColorKey;
}
public EditorNotificationPanel() {
super(new BorderLayout());
@@ -83,16 +93,6 @@ 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;
@@ -42,8 +42,7 @@ 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()
.background(LightColors.GREEN)
final EditorNotificationPanel panel = new EditorNotificationPanel(LightColors.GREEN)
.text("EditorConfig is overriding Code Style settings for this file")
.icon(EditorconfigIcons.Editorconfig);
panel.createActionLabel("OK", () -> {
@@ -65,8 +65,7 @@ public class CCSubtaskEditorNotificationProvider extends EditorNotifications.Pro
if (task == null || !task.hasSubtasks()) {
return null;
}
EditorNotificationPanel panel = new EditorNotificationPanel();
panel.background(EditorColors.GUTTER_BACKGROUND);
EditorNotificationPanel panel = new EditorNotificationPanel(EditorColors.GUTTER_BACKGROUND);
String header = (isTestFile ? "test" : "task") + " file";
int activeSubtaskIndex = task.getActiveSubtaskIndex() + 1;
int subtaskSize = task.getLastSubtaskIndex() + 1;