From 6791db356fe5dccb29ab7074033f00724973ffe9 Mon Sep 17 00:00:00 2001 From: Sergey Simonchik Date: Thu, 12 Oct 2017 16:58:37 +0300 Subject: [PATCH] WEB-29204 "Rerun tests" notification's location and font --- .../runners/RerunTestsNotification.java | 49 ++++++++++++------- .../src/com/intellij/ui/GotItMessage.java | 9 +++- .../src/com/intellij/ui/GotItPanel.form | 2 +- .../src/com/intellij/ui/GotItPanel.java | 18 +++++-- 4 files changed, 53 insertions(+), 25 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/execution/runners/RerunTestsNotification.java b/platform/lang-impl/src/com/intellij/execution/runners/RerunTestsNotification.java index f5e3de0a97e0..df8a73565861 100644 --- a/platform/lang-impl/src/com/intellij/execution/runners/RerunTestsNotification.java +++ b/platform/lang-impl/src/com/intellij/execution/runners/RerunTestsNotification.java @@ -15,6 +15,8 @@ */ package com.intellij.execution.runners; +import com.intellij.execution.impl.ConsoleViewImpl; +import com.intellij.execution.ui.ConsoleView; import com.intellij.execution.ui.ExecutionConsole; import com.intellij.execution.ui.RunContentDescriptor; import com.intellij.ide.util.PropertiesComponent; @@ -26,21 +28,22 @@ import com.intellij.openapi.util.Disposer; import com.intellij.ui.GotItMessage; import com.intellij.ui.awt.RelativePoint; import com.intellij.util.Alarm; +import com.intellij.util.ui.JBUI; +import com.intellij.util.ui.PositionTracker; +import com.intellij.util.ui.UIUtil; import com.intellij.util.ui.update.UiNotifyConnector; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import javax.swing.*; import java.awt.*; -/** -* @author Sergey Simonchik -*/ public class RerunTestsNotification { private static final String KEY = "rerun.tests.notification.shown"; public static void showRerunNotification(@Nullable RunContentDescriptor contentToReuse, - @NotNull final ExecutionConsole executionConsole) { + @NotNull ExecutionConsole executionConsole) { if (contentToReuse == null) { return; } @@ -51,8 +54,8 @@ public class RerunTestsNotification { } } - private static void doShow(@NotNull final ExecutionConsole executionConsole) { - final Alarm alarm = new Alarm(); + private static void doShow(@NotNull ExecutionConsole executionConsole) { + Alarm alarm = new Alarm(); alarm.addRequest(() -> { String shortcutText = KeymapUtil.getFirstKeyboardShortcutText( ActionManager.getInstance().getAction(RerunTestsAction.ID) @@ -61,19 +64,27 @@ public class RerunTestsNotification { return; } - GotItMessage message = GotItMessage.createMessage("Rerun tests with " + shortcutText, ""); - message.setDisposable(executionConsole); - message.setCallback(() -> PropertiesComponent.getInstance().setValue(KEY, true)); - message.setShowCallout(false); - Dimension consoleSize = executionConsole.getComponent().getSize(); - - message.show( - new RelativePoint( - executionConsole.getComponent(), - new Point(consoleSize.width - 185, consoleSize.height - 60) - ), - Balloon.Position.below - ); + ConsoleView consoleView = UIUtil.findComponentOfType(executionConsole.getComponent(), ConsoleViewImpl.class); + if (consoleView != null) { + GotItMessage message = GotItMessage.createMessage("Rerun tests with " + shortcutText, ""); + message.setDisposable(executionConsole); + message.setCallback(() -> PropertiesComponent.getInstance().setValue(KEY, true)); + message.setShowCallout(false); + JComponent consoleComponent = consoleView.getComponent(); + message.show( + new PositionTracker(consoleComponent) { + @Override + public RelativePoint recalculateLocation(@NotNull Balloon balloon) { + RelativePoint point = RelativePoint.getSouthEastOf(consoleComponent); + Dimension balloonSize = balloon.getPreferredSize(); + int scrollBarSize = JBUI.scale(10); + point.getPoint().translate(-balloonSize.width / 2 - scrollBarSize, -balloonSize.height / 2 - scrollBarSize); + return point; + } + }, + Balloon.Position.below + ); + } Disposer.dispose(alarm); }, 1000); diff --git a/platform/platform-impl/src/com/intellij/ui/GotItMessage.java b/platform/platform-impl/src/com/intellij/ui/GotItMessage.java index a12fe44eb127..012a5064135d 100644 --- a/platform/platform-impl/src/com/intellij/ui/GotItMessage.java +++ b/platform/platform-impl/src/com/intellij/ui/GotItMessage.java @@ -23,6 +23,7 @@ import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.text.StringUtil; import com.intellij.ui.awt.RelativePoint; import com.intellij.util.ui.JBUI; +import com.intellij.util.ui.PositionTracker; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -76,7 +77,11 @@ public class GotItMessage { return this; } - public void show(RelativePoint point, Balloon.Position position) { + public void show(@NotNull RelativePoint point, @NotNull Balloon.Position position) { + show(new PositionTracker.Static<>(point), position); + } + + public void show(@NotNull PositionTracker tracker, @NotNull Balloon.Position position) { if (myDisposable != null && Disposer.isDisposed(myDisposable)) { return; } @@ -115,6 +120,6 @@ public class GotItMessage { } }); - balloon.show(point, position); + balloon.show(tracker, position); } } diff --git a/platform/platform-impl/src/com/intellij/ui/GotItPanel.form b/platform/platform-impl/src/com/intellij/ui/GotItPanel.form index e26061e5d83a..d0e298110185 100644 --- a/platform/platform-impl/src/com/intellij/ui/GotItPanel.form +++ b/platform/platform-impl/src/com/intellij/ui/GotItPanel.form @@ -57,7 +57,7 @@ - + diff --git a/platform/platform-impl/src/com/intellij/ui/GotItPanel.java b/platform/platform-impl/src/com/intellij/ui/GotItPanel.java index e61715792767..c0b2915962db 100644 --- a/platform/platform-impl/src/com/intellij/ui/GotItPanel.java +++ b/platform/platform-impl/src/com/intellij/ui/GotItPanel.java @@ -17,7 +17,9 @@ package com.intellij.ui; import com.intellij.ide.IdeTooltipManager; import com.intellij.util.ui.GraphicsUtil; +import com.intellij.util.ui.JBUI; import com.intellij.util.ui.UIUtil; +import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.*; @@ -30,10 +32,20 @@ public class GotItPanel { private static final JBColor BODY_COLOR_2 = new JBColor(new Color(71, 135, 237), new Color(38, 53, 73)); private static final JBColor BORDER_COLOR = new JBColor(new Color(71, 91, 167), new Color(78, 120, 161)); - JPanel myButton; JPanel myRoot; JLabel myTitle; JEditorPane myMessage; + JPanel myButton; + JLabel myButtonLabel; + + public GotItPanel() { + scaleFont(myTitle); + scaleFont(myButtonLabel); + } + + private static void scaleFont(@NotNull JComponent component) { + component.setFont(component.getFont().deriveFont(1.0f * JBUI.scaleFontSize(component.getFont().getSize()))); + } private void createUIComponents() { myButton = new JPanel(new BorderLayout()) { @@ -46,10 +58,10 @@ public class GotItPanel { super.paintComponent(g); GraphicsUtil.setupAAPainting(g); ((Graphics2D)g).setPaint(new GradientPaint(0, 0, BODY_COLOR_1, 0, getHeight(), BODY_COLOR_2)); - g.fillRoundRect(0, 0, getWidth() - 1, getHeight() - 1, 5, 5); + g.fillRoundRect(0, 0, getWidth() - JBUI.scale(1), getHeight() - JBUI.scale(1), JBUI.scale(5), JBUI.scale(5)); ((Graphics2D)g).setStroke(new BasicStroke(UIUtil.isUnderDarcula() ? 2f : 1f)); g.setColor(BORDER_COLOR); - g.drawRoundRect(0, 0, getWidth() - 1, getHeight() - 1, 5, 5); + g.drawRoundRect(0, 0, getWidth() - JBUI.scale(1), getHeight() - JBUI.scale(1), JBUI.scale(5), JBUI.scale(5)); } };