From 6d9ada3e2b7c19877cd57563391244f92bf87783 Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Thu, 10 Feb 2011 17:32:47 +0300 Subject: [PATCH] WI-1326 Notification message is way too long --- .../com/intellij/ide/IdeTooltipManager.java | 45 +++++++++++++------ .../wm/impl/status/AddTestProcessAction.java | 32 +++++++------ .../src/com/intellij/ui/BalloonImpl.java | 1 + .../intellij/ui/popup/PopupFactoryImpl.java | 19 +++++--- .../src/misc/registry.properties | 2 +- .../util/src/com/intellij/util/ui/UIUtil.java | 24 ++++++++++ 6 files changed, 85 insertions(+), 38 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ide/IdeTooltipManager.java b/platform/platform-impl/src/com/intellij/ide/IdeTooltipManager.java index 427037524f67..7d4d43dd76c1 100644 --- a/platform/platform-impl/src/com/intellij/ide/IdeTooltipManager.java +++ b/platform/platform-impl/src/com/intellij/ide/IdeTooltipManager.java @@ -438,7 +438,7 @@ public class IdeTooltipManager implements ApplicationComponent, AWTEventListener } - public static JEditorPane initPane(@NonNls String text, final HintHint hintHint, @Nullable JLayeredPane layeredPane) { + public static JEditorPane initPane(@NonNls String text, final HintHint hintHint, @Nullable final JLayeredPane layeredPane) { final Ref prefSize = new Ref(null); String htmlBody = getHtmlBody(text); text = "" + @@ -447,9 +447,38 @@ public class IdeTooltipManager implements ApplicationComponent, AWTEventListener htmlBody + ""; + final boolean[] prefSizeWasComputed = new boolean[] {false}; final JEditorPane pane = new JEditorPane() { @Override public Dimension getPreferredSize() { + if (!prefSizeWasComputed[0] && hintHint.isAwtTooltip()) { + JLayeredPane lp = layeredPane; + if (lp == null) { + JRootPane rootPane = UIUtil.getRootPane(this); + if (rootPane != null) { + lp = rootPane.getLayeredPane(); + } + } + + Dimension size; + if (lp != null) { + size = lp.getSize(); + prefSizeWasComputed[0] = true; + } else { + size = ScreenUtil.getScreenRectangle(0, 0).getSize(); + } + int fitWidth = (int)(size.width * 0.8); + Dimension prefSizeOriginal = super.getPreferredSize(); + if (prefSizeOriginal.width > fitWidth) { + setSize(new Dimension(fitWidth, Integer.MAX_VALUE)); + Dimension fixedWidthSize = super.getPreferredSize(); + prefSize.set(new Dimension(fitWidth, fixedWidthSize.height)); + } + else { + prefSize.set(new Dimension(prefSizeOriginal)); + } + } + Dimension s = prefSize.get() != null ? new Dimension(prefSize.get()) : super.getPreferredSize(); Border b = getBorder(); if (b != null) { @@ -499,18 +528,8 @@ public class IdeTooltipManager implements ApplicationComponent, AWTEventListener pane.setBorder(null); } - if (hintHint.isAwtTooltip()) { - Dimension size = layeredPane != null ? layeredPane.getSize() : ScreenUtil.getScreenRectangle(0, 0).getSize(); - int fitWidth = (int)(size.width * 0.8); - Dimension prefSizeOriginal = pane.getPreferredSize(); - if (prefSizeOriginal.width > fitWidth) { - pane.setSize(new Dimension(fitWidth, Integer.MAX_VALUE)); - Dimension fixedWidthSize = pane.getPreferredSize(); - prefSize.set(new Dimension(fitWidth, fixedWidthSize.height)); - } - else { - prefSize.set(new Dimension(prefSizeOriginal)); - } + if (!hintHint.isAwtTooltip()) { + prefSizeWasComputed[0] = true; } pane.setOpaque(hintHint.isOpaqueAllowed()); diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/AddTestProcessAction.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/AddTestProcessAction.java index 0d61f08fd4f3..d0d6743f1258 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/AddTestProcessAction.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/AddTestProcessAction.java @@ -27,7 +27,11 @@ import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.MessageType; +import com.intellij.openapi.ui.popup.Balloon; +import com.intellij.openapi.ui.popup.BalloonBuilder; +import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.openapi.wm.ToolWindowManager; +import com.intellij.ui.awt.RelativePoint; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -43,24 +47,18 @@ public class AddTestProcessAction extends AnAction implements DumbAware { public void actionPerformed(AnActionEvent e) { - DialogWrapper fuck = new DialogWrapper(false) { + BalloonBuilder builder = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder("" + + "Load up on guns bring your friends it's fun to loose and to pretend Load up on guns bring your friends it's fun to loose and to pretend Load up on guns bring your friends it's fun to loose and to pretend Load up on guns bring your friends it's fun to loose and to pretend " + + "Load up on guns bring your friends it's fun to loose and to pretend Load up on guns bring your friends it's fun to loose and to pretend Load up on guns bring your friends it's fun to loose and to pretend Load up on guns bring your friends it's fun to loose and to pretend " + + "Load up on guns bring your friends it's fun to loose and to pretend Load up on guns bring your friends it's fun to loose and to pretend Load up on guns bring your friends it's fun to loose and to pretend Load up on guns bring your friends it's fun to loose and to pretend " + + "Load up on guns bring your friends it's fun to loose and to pretend Load up on guns bring your friends it's fun to loose and to pretend Load up on guns bring your friends it's fun to loose and to pretend Load up on guns bring your friends it's fun to loose and to pretend " + + "Load up on guns bring your friends it's fun to loose and to pretend Load up on guns bring your friends it's fun to loose and to pretend Load up on guns bring your friends it's fun to loose and to pretend Load up on guns bring your friends it's fun to loose and to pretend " + + "", MessageType.INFO, null); - { - init(); - } - - @Override - protected JComponent createCenterPanel() { - JPanel panel = new JPanel(new BorderLayout()); - JLabel label = new JLabel("Fuck"); - panel.add(label, BorderLayout.CENTER); - panel.setMinimumSize(label.getPreferredSize()); - panel.setPreferredSize(new Dimension(-1, -1)); - return panel; - } - }; - - fuck.show(); + JFrame wnd = (JFrame)KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow(); + JRootPane ro = wnd.getRootPane(); + Point point = new Point(ro.getWidth() - 200, ro.getHeight() - 200); + builder.createBalloon().show(new RelativePoint(ro, point), Balloon.Position.above); if (true) return; diff --git a/platform/platform-impl/src/com/intellij/ui/BalloonImpl.java b/platform/platform-impl/src/com/intellij/ui/BalloonImpl.java index e28621b70ac0..92373029be56 100644 --- a/platform/platform-impl/src/com/intellij/ui/BalloonImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/BalloonImpl.java @@ -303,6 +303,7 @@ public class BalloonImpl implements Disposable, Balloon, LightweightWindow, Posi myLayeredPane = root.getLayeredPane(); myPosition = position; + UIUtil.setFutureRootPane(myContent, root); myLayeredPane.addComponentListener(myComponentListener); diff --git a/platform/platform-impl/src/com/intellij/ui/popup/PopupFactoryImpl.java b/platform/platform-impl/src/com/intellij/ui/popup/PopupFactoryImpl.java index b08def016294..1242748a288f 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/PopupFactoryImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/PopupFactoryImpl.java @@ -18,6 +18,7 @@ package com.intellij.ui.popup; import com.intellij.CommonBundle; import com.intellij.ide.DataManager; import com.intellij.ide.IdeEventQueue; +import com.intellij.ide.IdeTooltipManager; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.actionSystem.ex.ActionUtil; import com.intellij.openapi.actionSystem.impl.ActionMenu; @@ -37,7 +38,9 @@ import com.intellij.openapi.wm.WindowManager; import com.intellij.openapi.wm.ex.WindowManagerEx; import com.intellij.openapi.wm.impl.IdeFrameImpl; import com.intellij.ui.FocusTrackback; +import com.intellij.ui.HintHint; import com.intellij.ui.awt.RelativePoint; +import com.intellij.ui.components.JBScrollPane; import com.intellij.ui.components.panels.NonOpaquePanel; import com.intellij.ui.popup.list.ListPopupImpl; import com.intellij.ui.popup.mock.MockConfirmation; @@ -730,24 +733,26 @@ public class PopupFactoryImpl extends JBPopupFactory { @Nullable final HyperlinkListener listener) { - final JEditorPane text = new JEditorPane(); - text.setEditorKit(new HTMLEditorKit()); + JEditorPane text = IdeTooltipManager.initPane(htmlContent, new HintHint().setAwtTooltip(true), null); + if (listener != null) { text.addHyperlinkListener(listener); } - text.setText(UIUtil.toHtml(htmlContent)); - final JLabel label = new JLabel(text.getText()); - final Dimension size = label.getPreferredSize(); text.setEditable(false); NonOpaquePanel.setTransparent(text); text.setBorder(null); - text.setPreferredSize(size); + JLabel label = new JLabel(); 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); + JScrollPane scrolledText = new JScrollPane(text); + scrolledText.setBackground(fillColor); + scrolledText.getViewport().setBackground(fillColor); + scrolledText.getViewport().setBorder(null); + scrolledText.setBorder(null); + textWrapper.add(scrolledText); content.add(textWrapper, BorderLayout.CENTER); final NonOpaquePanel north = new NonOpaquePanel(new BorderLayout()); diff --git a/platform/platform-resources-en/src/misc/registry.properties b/platform/platform-resources-en/src/misc/registry.properties index 98a8486d80ad..62d58746993b 100644 --- a/platform/platform-resources-en/src/misc/registry.properties +++ b/platform/platform-resources-en/src/misc/registry.properties @@ -66,7 +66,7 @@ ide.splitter.mouseZone=6 ide.tooltip.callout=true ide.tooltip.mode=default ide.tooltip.description=Available options are: default,system,graphite -ide.tooltip.animationCycle=500 +ide.tooltip.animationCycle=150 ide.tooltip.initialDelay=1200 ide.tooltip.initialDelay.highlighter=150 ide.tooltip.reshowDelay=500 diff --git a/platform/util/src/com/intellij/util/ui/UIUtil.java b/platform/util/src/com/intellij/util/ui/UIUtil.java index f418d324ce57..0f5590c3a49b 100644 --- a/platform/util/src/com/intellij/util/ui/UIUtil.java +++ b/platform/util/src/com/intellij/util/ui/UIUtil.java @@ -26,6 +26,7 @@ import com.intellij.ui.ColorUtil; import com.intellij.ui.SideBorder; import com.intellij.util.ArrayUtil; import com.intellij.util.ReflectionUtil; +import com.intellij.util.WeakListener; import org.intellij.lang.annotations.Language; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -46,6 +47,7 @@ import java.awt.*; import java.awt.event.*; import java.awt.font.FontRenderContext; import java.awt.image.BufferedImage; +import java.lang.ref.WeakReference; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.net.URL; @@ -85,6 +87,8 @@ public class UIUtil { @NonNls public static final String CENTER_TOOLTIP = "ToCenterTooltip"; + private static final String ROOT_PANE = "JRootPane.future"; + private UIUtil() { } @@ -1789,5 +1793,25 @@ public class UIUtil { } return null; } + + public static JRootPane getRootPane(Component c) { + JRootPane root = getParentOfType(JRootPane.class, c); + if (root != null) return root; + Component eachParent = c; + while (eachParent != null) { + if (eachParent instanceof JComponent) { + WeakReference pane = (WeakReference)((JComponent)eachParent).getClientProperty(ROOT_PANE); + if (pane != null) return pane.get(); + } + eachParent = eachParent.getParent(); + } + + return null; + } + + public static void setFutureRootPane(JComponent c, JRootPane pane) { + c.putClientProperty(ROOT_PANE, new WeakReference(pane)); + } + }