From 1fd2764dea517dbbcf52d6859676732ddb1efba1 Mon Sep 17 00:00:00 2001 From: Alexander Lobas Date: Tue, 16 Feb 2016 13:00:06 +0300 Subject: [PATCH] IDEA-149210 Rework IDE notifications --- .../impl/NotificationsManagerImpl.java | 69 ++++++++++++++++--- .../impl/ui/NotificationsUtil.java | 3 +- .../src/com/intellij/ui/BalloonImpl.java | 5 +- .../com/intellij/ui/BalloonLayoutData.java | 2 + .../com/intellij/ui/BalloonLayoutImpl.java | 42 ++++++++--- .../util/src/com/intellij/util/ui/UIUtil.java | 8 +++ 6 files changed, 107 insertions(+), 22 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 7dda120ebed4..08258bf238aa 100644 --- a/platform/platform-impl/src/com/intellij/notification/impl/NotificationsManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/notification/impl/NotificationsManagerImpl.java @@ -278,15 +278,15 @@ public class NotificationsManagerImpl extends NotificationsManager { @Nullable public static Window findWindowForBalloon(@Nullable Project project) { Window frame = WindowManager.getInstance().getFrame(project); + if (frame == null && project == null) { + frame = (Window)WelcomeFrame.getInstance(); + } if (frame == null && project == null) { frame = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); while (frame instanceof DialogWrapperDialog && ((DialogWrapperDialog)frame).getDialogWrapper().isModalProgress()) { frame = frame.getOwner(); } } - if (frame == null && project == null) { - frame = (Window)WelcomeFrame.getInstance(); - } return frame; } @@ -434,11 +434,11 @@ public class NotificationsManagerImpl extends NotificationsManager { } if (!defaultButton.isNull()) { - content.addPropertyChangeListener("ancestor", new PropertyChangeListener() { + UIUtil.addParentChangeListener(content, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent event) { if (event.getOldValue() == null && event.getNewValue() != null) { - content.removePropertyChangeListener("ancestor", this); + UIUtil.removeParentChangeListener(content, this); JRootPane rootPane = UIUtil.getRootPane(content); if (rootPane != null) { rootPane.setDefaultButton(defaultButton.get()); @@ -462,7 +462,10 @@ public class NotificationsManagerImpl extends NotificationsManager { final BalloonLayoutData layoutData = new BalloonLayoutData(); layoutDataRef.set(layoutData); - final Color foreground = new JBColor(Gray._0, Gray._191); + Color foregroundR = Gray._0; + Color foregroundD = Gray._191; + final Color foreground = new JBColor(foregroundR, foregroundD); + final JBColor fillColor = new JBColor(Gray._242, new Color(78, 80, 82)); final JEditorPane text = new JEditorPane() { @@ -490,7 +493,11 @@ public class NotificationsManagerImpl extends NotificationsManager { int prefSize = new JLabel(NotificationsUtil.buildHtml(notification, null, true, null, fontStyle)).getPreferredSize().width; String style = prefSize > BalloonLayoutConfiguration.MaxWidth ? BalloonLayoutConfiguration.MaxWidthStyle : null; - text.setText(NotificationsUtil.buildHtml(notification, style, true, foreground, fontStyle)); + String textR = NotificationsUtil.buildHtml(notification, style, true, foregroundR, fontStyle); + String textD = NotificationsUtil.buildHtml(notification, style, true, foregroundD, fontStyle); + LafHandler lafHandler = new LafHandler(text, textR, textD); + layoutData.lafHandler = lafHandler; + text.setEditable(false); text.setOpaque(false); @@ -639,9 +646,11 @@ public class NotificationsManagerImpl extends NotificationsManager { content.add(centerPanel, BorderLayout.CENTER); if (notification.isTitle()) { - String titleValue = NotificationsUtil - .buildHtml(notification, StringUtil.defaultIfEmpty(fontStyle, "") + "white-space:nowrap;", false, foreground, null); - JLabel title = new JLabel(titleValue); + String titleStyle = StringUtil.defaultIfEmpty(fontStyle, "") + "white-space:nowrap;"; + String titleR = NotificationsUtil.buildHtml(notification, titleStyle, false, foregroundR, null); + String titleD = NotificationsUtil.buildHtml(notification, titleStyle, false, foregroundD, null); + JLabel title = new JLabel(); + lafHandler.setTitle(title, titleR, titleD); title.setOpaque(false); if (UIUtil.isUnderNimbusLookAndFeel()) { title.setBackground(UIUtil.TRANSPARENT_COLOR); @@ -1049,4 +1058,44 @@ public class NotificationsManagerImpl extends NotificationsManager { } } } + + private static class LafHandler implements Runnable { + private final JEditorPane myContent; + private final String myContentTextR; + private final String myContentTextD; + + private JLabel myTitle; + private String myTitleTextR; + private String myTitleTextD; + + public LafHandler(@NotNull JEditorPane content, @NotNull String textR, @NotNull String textD) { + myContent = content; + myContentTextR = textR; + myContentTextD = textD; + updateContent(); + } + + public void setTitle(@NotNull JLabel title, @NotNull String textR, @NotNull String textD) { + myTitle = title; + myTitleTextR = textR; + myTitleTextD = textD; + updateTitle(); + } + + private void updateTitle() { + myTitle.setText(UIUtil.isUnderDarcula() ? myTitleTextD : myTitleTextR); + } + + private void updateContent() { + myContent.setText(UIUtil.isUnderDarcula() ? myContentTextD : myContentTextR); + } + + @Override + public void run() { + if (myTitle != null) { + updateTitle(); + } + updateContent(); + } + } } \ No newline at end of file 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 97478d31b083..739078c70f73 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 @@ -108,7 +108,8 @@ public class NotificationsUtil { result.append("" : " color=\"" + titleColor + "\">").append(title).append(""); } if (!StringUtil.isEmpty(subtitle)) { - result.append(" ").append(subtitle); + result.append(" ").append(titleColor == null ? "" : "").append(subtitle) + .append(titleColor == null ? "" : ""); } if (!StringUtil.isEmpty(content)) { result.append(" 0) { - BalloonImpl balloon = (BalloonImpl)eachColumn.get(0); - if (balloon.hasShadow()) { - eachY -= balloon.getShadowBorderInsets().top; - } - else { - eachY += 4; - } + if (columnSize > 0 && !((BalloonImpl)eachColumn.get(0)).hasShadow()) { + eachY += 4; } eachColumnX -= eachWidth.intValue(); @@ -249,7 +272,8 @@ public class BalloonLayoutImpl implements BalloonLayout { } else if (hasShadow) { eachY += space - shadow.top; - } else { + } + else { eachY += space - next.getShadowBorderInsets().bottom; } } diff --git a/platform/util/src/com/intellij/util/ui/UIUtil.java b/platform/util/src/com/intellij/util/ui/UIUtil.java index 9b699f022b4e..c6f5824086db 100644 --- a/platform/util/src/com/intellij/util/ui/UIUtil.java +++ b/platform/util/src/com/intellij/util/ui/UIUtil.java @@ -1947,6 +1947,14 @@ public class UIUtil { }); } + public static void addParentChangeListener(@NotNull Component component, @NotNull PropertyChangeListener listener) { + component.addPropertyChangeListener("ancestor", listener); + } + + public static void removeParentChangeListener(@NotNull Component component, @NotNull PropertyChangeListener listener) { + component.removePropertyChangeListener("ancestor", listener); + } + public static void drawVDottedLine(Graphics2D g, int lineX, int startY, int endY, @Nullable final Color bgColor, final Color fgColor) { if (bgColor != null) { g.setColor(bgColor);