WI-1326 Notification message is way too long

This commit is contained in:
Kirill Kalishev
2011-02-10 17:32:47 +03:00
parent ff908e73d6
commit 6d9ada3e2b
6 changed files with 85 additions and 38 deletions
@@ -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<Dimension> prefSize = new Ref<Dimension>(null);
String htmlBody = getHtmlBody(text);
text = "<html><head>" +
@@ -447,9 +447,38 @@ public class IdeTooltipManager implements ApplicationComponent, AWTEventListener
htmlBody +
"</body></html>";
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());
@@ -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;
@@ -303,6 +303,7 @@ public class BalloonImpl implements Disposable, Balloon, LightweightWindow, Posi
myLayeredPane = root.getLayeredPane();
myPosition = position;
UIUtil.setFutureRootPane(myContent, root);
myLayeredPane.addComponentListener(myComponentListener);
@@ -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());
@@ -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
@@ -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<JRootPane> pane = (WeakReference<JRootPane>)((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<JRootPane>(pane));
}
}