mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-149210 Rework IDE notifications
This commit is contained in:
+9
-4
@@ -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("<br>\nContent", lines - 1), null));
|
||||
text
|
||||
.setText(NotificationsUtil.buildHtml(null, null, "Content" + StringUtil.repeat("<br>\nContent", lines - 1), null, null, null,
|
||||
NotificationsUtil.getFontStyle()));
|
||||
text.setEditable(false);
|
||||
text.setOpaque(false);
|
||||
text.setBorder(null);
|
||||
|
||||
+18
-7
@@ -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("<p").append(contentColor == null ? ">" : " color=\"" + contentColor + "\">").append(content).append("</p>");
|
||||
result.append("<p").append(contentStyle == null ? "" : " style=\"" + contentStyle + "\"")
|
||||
.append(contentColor == null ? ">" : " color=\"" + contentColor + "\">").append(content).append("</p>");
|
||||
}
|
||||
if (style != null) {
|
||||
result.append("</div>");
|
||||
@@ -114,6 +119,12 @@ public class NotificationsUtil {
|
||||
return XmlStringUtil.wrapInHtml(result.toString());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getFontStyle() {
|
||||
Pair<String, Integer> 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();
|
||||
|
||||
Reference in New Issue
Block a user