From 380fbd3d2fb8aac1de9a58903a31e2ffef7d5a60 Mon Sep 17 00:00:00 2001 From: Alexander Lobas Date: Wed, 3 Feb 2016 00:21:56 +0300 Subject: [PATCH] IDEA-149210 Rework IDE notifications --- .../impl/NotificationsManagerImpl.java | 13 +++++++--- .../impl/ui/NotificationsUtil.java | 25 +++++++++++++------ 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/notification/impl/NotificationsManagerImpl.java b/platform/platform-impl/src/com/intellij/notification/impl/NotificationsManagerImpl.java index 5557484092b7..b7e33420da3b 100644 --- a/platform/platform-impl/src/com/intellij/notification/impl/NotificationsManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/notification/impl/NotificationsManagerImpl.java @@ -452,11 +452,12 @@ public class NotificationsManagerImpl extends NotificationsManager { text.addHyperlinkListener(listener); } - int prefSize = new JLabel(NotificationsUtil.buildHtml(notification, null, true, null)).getPreferredSize().width; + String fontStyle = NotificationsUtil.getFontStyle(); + int prefSize = new JLabel(NotificationsUtil.buildHtml(notification, null, true, null, fontStyle)).getPreferredSize().width; int maxSize = BalloonLayoutConfiguration.MaxWidth; String style = prefSize > maxSize ? "width:" + maxSize + "px;" : null; - text.setText(NotificationsUtil.buildHtml(notification, style, true, foreground)); + text.setText(NotificationsUtil.buildHtml(notification, style, true, foreground, fontStyle)); text.setEditable(false); text.setOpaque(false); @@ -612,7 +613,9 @@ public class NotificationsManagerImpl extends NotificationsManager { content.add(centerPanel, BorderLayout.CENTER); if (notification.isTitle()) { - JLabel title = new JLabel(NotificationsUtil.buildHtml(notification, "white-space: nowrap;", false, foreground)) { + String titleValue = NotificationsUtil + .buildHtml(notification, StringUtil.defaultIfEmpty(fontStyle, "") + "white-space: nowrap;", false, foreground, null); + JLabel title = new JLabel(titleValue) { @Override public void paint(Graphics g) { super.paint(g); @@ -757,7 +760,9 @@ public class NotificationsManagerImpl extends NotificationsManager { public static int calculateContentHeight(int lines) { JEditorPane text = new JEditorPane(); text.setEditorKit(UIUtil.getHTMLEditorKit()); - text.setText(NotificationsUtil.buildHtml(null, null, "Content" + StringUtil.repeat("
\nContent", lines - 1), null)); + text + .setText(NotificationsUtil.buildHtml(null, null, "Content" + StringUtil.repeat("
\nContent", lines - 1), null, null, null, + NotificationsUtil.getFontStyle())); text.setEditable(false); text.setOpaque(false); text.setBorder(null); diff --git a/platform/platform-impl/src/com/intellij/notification/impl/ui/NotificationsUtil.java b/platform/platform-impl/src/com/intellij/notification/impl/ui/NotificationsUtil.java index d6c5c622955b..1c513a8a74fe 100644 --- a/platform/platform-impl/src/com/intellij/notification/impl/ui/NotificationsUtil.java +++ b/platform/platform-impl/src/com/intellij/notification/impl/ui/NotificationsUtil.java @@ -19,9 +19,11 @@ import com.intellij.notification.Notification; import com.intellij.notification.NotificationListener; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.ui.MessageType; +import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.text.StringUtil; import com.intellij.ui.ColorUtil; import com.intellij.ui.JBColor; +import com.intellij.util.ui.UIUtil; import com.intellij.xml.util.XmlStringUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -51,14 +53,15 @@ public class NotificationsUtil { title = StringUtil.trimLog(title, TITLE_LIMIT); content = StringUtil.trimLog(content, CONTENT_LIMIT); } - return buildHtml(title, null, content, style, "#" + ColorUtil.toHex(getMessageType(notification).getTitleForeground()), null); + return buildHtml(title, null, content, style, "#" + ColorUtil.toHex(getMessageType(notification).getTitleForeground()), null, null); } @NotNull public static String buildHtml(@NotNull final Notification notification, @Nullable String style, boolean isContent, - @Nullable Color color) { + @Nullable Color color, + @Nullable String contentStyle) { String title = !isContent ? notification.getTitle() : ""; String subtitle = !isContent ? notification.getSubtitle() : null; String content = isContent ? notification.getContent() : ""; @@ -73,20 +76,21 @@ public class NotificationsUtil { content = StringUtil.trimLog(content, CONTENT_LIMIT); } String colorText = color == null ? null : "#" + ColorUtil.toHex(color); - return buildHtml(title, subtitle, content, style, isContent ? null : colorText, isContent ? colorText : null); + return buildHtml(title, subtitle, content, style, isContent ? null : colorText, isContent ? colorText : null, contentStyle); } public static String buildHtml(@Nullable String title, @Nullable String subtitle, @Nullable String content, @Nullable String style) { - return buildHtml(title, subtitle, content, style, null, null); + return buildHtml(title, subtitle, content, style, null, null, null); } @NotNull - private static String buildHtml(@Nullable String title, + public static String buildHtml(@Nullable String title, @Nullable String subtitle, @Nullable String content, @Nullable String style, @Nullable String titleColor, - @Nullable String contentColor) { + @Nullable String contentColor, + @Nullable String contentStyle) { if (StringUtil.isEmpty(title) && !StringUtil.isEmpty(subtitle)) { title = subtitle; subtitle = null; @@ -106,7 +110,8 @@ public class NotificationsUtil { result.append(" ").append(subtitle); } if (!StringUtil.isEmpty(content)) { - result.append("" : " color=\"" + contentColor + "\">").append(content).append("

"); + result.append("" : " color=\"" + contentColor + "\">").append(content).append("

"); } if (style != null) { result.append(""); @@ -114,6 +119,12 @@ public class NotificationsUtil { return XmlStringUtil.wrapInHtml(result.toString()); } + @Nullable + public static String getFontStyle() { + Pair systemFontData = UIUtil.getSystemFontData(); + return systemFontData == null ? null : "font-family:" + systemFontData.first + ";"; + } + @Nullable public static HyperlinkListener wrapListener(@NotNull final Notification notification) { final NotificationListener listener = notification.getListener();