mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-84027 Balloons should fit window despite long textual content
This commit is contained in:
@@ -41,9 +41,7 @@ import com.intellij.openapi.ui.SimpleToolWindowPanel;
|
||||
import com.intellij.openapi.ui.popup.Balloon;
|
||||
import com.intellij.openapi.util.*;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.wm.ToolWindow;
|
||||
import com.intellij.openapi.wm.ToolWindowFactory;
|
||||
import com.intellij.openapi.wm.ToolWindowManager;
|
||||
import com.intellij.openapi.wm.*;
|
||||
import com.intellij.ui.awt.RelativePoint;
|
||||
import com.intellij.ui.content.Content;
|
||||
import com.intellij.ui.content.ContentFactory;
|
||||
@@ -532,7 +530,9 @@ public class EventLog implements Notifications {
|
||||
|
||||
RelativePoint target = EventLog.getProjectComponent(project).myConsole.getHyperlinkLocation(this);
|
||||
if (target != null) {
|
||||
Balloon balloon = NotificationsManagerImpl.createBalloon(myNotification, true, true);
|
||||
IdeFrame frame = WindowManager.getInstance().getIdeFrame(project);
|
||||
assert frame != null;
|
||||
Balloon balloon = NotificationsManagerImpl.createBalloon(frame, myNotification, true, true);
|
||||
Disposer.register(project, balloon);
|
||||
balloon.show(target, Balloon.Position.above);
|
||||
}
|
||||
|
||||
+18
-5
@@ -28,10 +28,12 @@ import com.intellij.openapi.ui.MessageType;
|
||||
import com.intellij.openapi.ui.popup.*;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.wm.IdeFrame;
|
||||
import com.intellij.openapi.wm.ToolWindowManager;
|
||||
import com.intellij.openapi.wm.WindowManager;
|
||||
import com.intellij.openapi.wm.impl.IdeFrameImpl;
|
||||
import com.intellij.ui.BalloonImpl;
|
||||
import com.intellij.ui.ScrollPaneFactory;
|
||||
import com.intellij.ui.components.panels.NonOpaquePanel;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
@@ -203,7 +205,7 @@ public class NotificationsManagerImpl extends NotificationsManager implements No
|
||||
final ProjectManager projectManager = ProjectManager.getInstance();
|
||||
final boolean noProjects = projectManager.getOpenProjects().length == 0;
|
||||
final boolean sticky = NotificationDisplayType.STICKY_BALLOON == displayType || noProjects;
|
||||
final Balloon balloon = createBalloon(notification, false, false);
|
||||
final Balloon balloon = createBalloon((IdeFrameImpl)window, notification, false, false);
|
||||
Disposer.register(project != null ? project : ApplicationManager.getApplication(), balloon);
|
||||
|
||||
if (notification.isExpired()) {
|
||||
@@ -251,7 +253,7 @@ public class NotificationsManagerImpl extends NotificationsManager implements No
|
||||
return frame;
|
||||
}
|
||||
|
||||
public static Balloon createBalloon(final Notification notification, final boolean showCallout, final boolean hideOnClickOutside) {
|
||||
public static Balloon createBalloon(@NotNull final IdeFrame window, final Notification notification, final boolean showCallout, final boolean hideOnClickOutside) {
|
||||
final JEditorPane text = new JEditorPane();
|
||||
text.setEditorKit(UIUtil.getHTMLEditorKit());
|
||||
|
||||
@@ -273,9 +275,14 @@ public class NotificationsManagerImpl extends NotificationsManager implements No
|
||||
|
||||
final JPanel content = new NonOpaquePanel(new BorderLayout((int)(label.getIconTextGap() * 1.5), (int)(label.getIconTextGap() * 1.5)));
|
||||
|
||||
final NonOpaquePanel textWrapper = new NonOpaquePanel(new GridBagLayout());
|
||||
textWrapper.add(text);
|
||||
content.add(textWrapper, BorderLayout.CENTER);
|
||||
text.setCaretPosition(0);
|
||||
JScrollPane pane = ScrollPaneFactory.createScrollPane(text,
|
||||
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
|
||||
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
||||
pane.setBorder(null);
|
||||
pane.setOpaque(false);
|
||||
pane.getViewport().setOpaque(false);
|
||||
content.add(pane, BorderLayout.CENTER);
|
||||
|
||||
final NonOpaquePanel north = new NonOpaquePanel(new BorderLayout());
|
||||
north.add(new JLabel(NotificationsUtil.getIcon(notification)), BorderLayout.NORTH);
|
||||
@@ -283,6 +290,12 @@ public class NotificationsManagerImpl extends NotificationsManager implements No
|
||||
|
||||
content.setBorder(new EmptyBorder(2, 4, 2, 4));
|
||||
|
||||
Dimension preferredSize = pane.getPreferredSize();
|
||||
int maxHeight = Math.min(400, window.getComponent().getHeight() - 20);
|
||||
if (preferredSize.height > maxHeight) {
|
||||
pane.setPreferredSize(new Dimension(preferredSize.width, maxHeight));
|
||||
}
|
||||
|
||||
final BalloonBuilder builder = JBPopupFactory.getInstance().createBalloonBuilder(content);
|
||||
builder.setFillColor(NotificationsUtil.getBackground(notification)).setCloseButtonEnabled(true).setShowCallout(showCallout)
|
||||
.setHideOnClickOutside(hideOnClickOutside)
|
||||
|
||||
+4
-1
@@ -25,6 +25,7 @@ import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.messages.MessageBus;
|
||||
|
||||
import javax.swing.event.HyperlinkEvent;
|
||||
@@ -61,7 +62,9 @@ public class NotificationTestAction extends AnAction implements DumbAware {
|
||||
};
|
||||
|
||||
final Notification notification = new Notification(TEST_GROUP_ID, "This is a test notification", //"a",
|
||||
"You can<br> close this very<p> very very very long notification by clicking <a href=\"close\">this link</a>. Long long long long. It should be long. Very long. Too long. And even longer.",
|
||||
"You can<br> close this very<p> very very very long notification by clicking <a href=\"close\">this link</a>. Long long long long. It should be long. Very long. Too long." +
|
||||
StringUtil.repeat("<br>line", 100) +
|
||||
" And even longer.",
|
||||
type, listener);
|
||||
|
||||
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
|
||||
|
||||
Reference in New Issue
Block a user