diff --git a/platform/lang-impl/src/com/intellij/codeInsight/navigation/CtrlMouseHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/navigation/CtrlMouseHandler.java index 8a26fcc2b3a7..187c8fbef5ac 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/navigation/CtrlMouseHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/navigation/CtrlMouseHandler.java @@ -513,10 +513,7 @@ public class CtrlMouseHandler extends AbstractProjectComponent { if (text == null) return; - JLabel label = HintUtil.createInformationLabel(text); - label.setUI(new MultiLineLabelUI()); - Font FONT = UIUtil.getLabelFont(); - label.setFont(FONT); + JComponent label = HintUtil.createInformationLabel(text); final LightweightHint hint = new LightweightHint(label); final HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl(); label.addMouseMotionListener(new MouseMotionAdapter() { diff --git a/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesAction.java b/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesAction.java index 12698445dbf4..416042161f59 100644 --- a/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesAction.java +++ b/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesAction.java @@ -254,7 +254,7 @@ public class ShowUsagesAction extends AnAction { private JComponent createHintComponent(String text, final FindUsagesHandler handler, final RelativePoint popupPosition, final Editor editor, final Runnable cancelAction, int maxUsages) { - JLabel label = HintUtil.createInformationLabel(text); + JComponent label = HintUtil.createInformationLabel(text); InplaceButton button = createSettingsButton(handler, popupPosition, editor, maxUsages, cancelAction); JPanel panel = new JPanel(new BorderLayout()); button.setBackground(label.getBackground()); diff --git a/platform/platform-impl/src/com/intellij/codeInsight/hint/HintManagerImpl.java b/platform/platform-impl/src/com/intellij/codeInsight/hint/HintManagerImpl.java index 6fd58d6ddd64..4d552f86dc96 100644 --- a/platform/platform-impl/src/com/intellij/codeInsight/hint/HintManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/codeInsight/hint/HintManagerImpl.java @@ -575,14 +575,14 @@ public class HintManagerImpl extends HintManager implements Disposable { } public void showErrorHint(@NotNull Editor editor, @NotNull String text) { - JLabel label = HintUtil.createErrorLabel(text); + JComponent label = HintUtil.createErrorLabel(text); LightweightHint hint = new LightweightHint(label); Point p = getHintPosition(hint, editor, ABOVE); showEditorHint(hint, editor, p, HIDE_BY_ANY_KEY | HIDE_BY_TEXT_CHANGE | HIDE_BY_SCROLLING, 0, false); } public void showInformationHint(@NotNull Editor editor, @NotNull String text) { - JLabel label = HintUtil.createInformationLabel(text); + JComponent label = HintUtil.createInformationLabel(text); showInformationHint(editor, label); } @@ -598,7 +598,7 @@ public class HintManagerImpl extends HintManager implements Disposable { } public void showErrorHint(@NotNull Editor editor, @NotNull String hintText, int offset1, int offset2, short constraint, int flags, int timeout) { - JLabel label = HintUtil.createErrorLabel(hintText); + JComponent label = HintUtil.createErrorLabel(hintText); LightweightHint hint = new LightweightHint(label); final LogicalPosition pos1 = editor.offsetToLogicalPosition(offset1); final LogicalPosition pos2 = editor.offsetToLogicalPosition(offset2); @@ -614,7 +614,7 @@ public class HintManagerImpl extends HintManager implements Disposable { int offset2, @NotNull QuestionAction action) { - JLabel label = HintUtil.createQuestionLabel(hintText); + JComponent label = HintUtil.createQuestionLabel(hintText); LightweightHint hint = new LightweightHint(label); showQuestionHint(editor, offset1, offset2, hint, action, ABOVE); } diff --git a/platform/platform-impl/src/com/intellij/codeInsight/hint/HintUtil.java b/platform/platform-impl/src/com/intellij/codeInsight/hint/HintUtil.java index 445212bc1a49..594a04dbbfae 100644 --- a/platform/platform-impl/src/com/intellij/codeInsight/hint/HintUtil.java +++ b/platform/platform-impl/src/com/intellij/codeInsight/hint/HintUtil.java @@ -15,10 +15,13 @@ */ package com.intellij.codeInsight.hint; +import com.intellij.ide.IdeTooltipManager; import com.intellij.openapi.util.IconLoader; import com.intellij.ui.ColoredSideBorder; +import com.intellij.ui.HintHint; import com.intellij.ui.SimpleColoredComponent; import com.intellij.ui.SimpleColoredText; +import com.intellij.ui.components.panels.NonOpaquePanel; import com.intellij.util.ui.UIUtil; import javax.swing.*; @@ -41,15 +44,20 @@ public class HintUtil { private HintUtil() { } - public static JLabel createInformationLabel(String text) { - JLabel label = new HintLabel(); - label.setText(text); + public static JComponent createInformationLabel(String text) { + HintHint hintHint = new HintHint().setTextBg(INFORMATION_COLOR).setTextFg(Color.black).setFont(getBoldFont()).setAwtTooltip(true); + + HintLabel label = new HintLabel(); + label.setText(text, hintHint); label.setIcon(INFORMATION_ICON); - label.setBorder(createHintBorder()); - label.setForeground(Color.black); - label.setFont(getBoldFont()); - label.setBackground(INFORMATION_COLOR); - label.setOpaque(true); + + if (!hintHint.isAwtTooltip()) { + label.setBorder(createHintBorder()); + label.setForeground(Color.black); + label.setFont(getBoldFont()); + label.setBackground(INFORMATION_COLOR); + label.setOpaque(true); + } return label; } @@ -65,16 +73,20 @@ public class HintUtil { return createInformationLabel(text, INFORMATION_ICON); } - public static JLabel createQuestionLabel(String text) { - JLabel label = new HintLabel(); - label.setText(text); + public static JComponent createQuestionLabel(String text) { + HintHint hintHint = new HintHint().setTextBg(QUESTION_COLOR).setTextFg(Color.black).setFont(getBoldFont()).setAwtTooltip(true); + + HintLabel label = new HintLabel(); + label.setText(text, hintHint); label.setIcon(QUESTION_ICON); -// label.setBorder(BorderFactory.createLineBorder(Color.black)); - label.setBorder(createHintBorder()); - label.setForeground(Color.black); - label.setFont(getBoldFont()); - label.setBackground(QUESTION_COLOR); - label.setOpaque(true); + + if (!hintHint.isAwtTooltip()) { + label.setBorder(createHintBorder()); + label.setForeground(Color.black); + label.setFont(getBoldFont()); + label.setBackground(QUESTION_COLOR); + label.setOpaque(true); + } return label; } @@ -87,26 +99,27 @@ public class HintUtil { highlighted.setFont(getBoldFont()); text.appendToComponent(highlighted); - Box box = Box.createHorizontalBox(); - box.setBorder(new ColoredSideBorder(Color.white, Color.white, Color.gray, Color.gray, 1)); - box.setForeground(Color.black); - box.setBackground(INFORMATION_COLOR); - box.add(highlighted); - box.setOpaque(true); - return box; + HintLabel label = new HintLabel(); + label.setText(highlighted); + + return label; } - public static JLabel createErrorLabel(String text) { - JLabel label = new HintLabel(); - label.setText(text.replaceAll("\n"," ")); + public static JComponent createErrorLabel(String text) { + HintHint hintHint = new HintHint().setTextBg(ERROR_COLOR).setTextFg(Color.black).setFont(getBoldFont()).setAwtTooltip(true); + HintLabel label = new HintLabel(); + label.setText(text, hintHint); label.setIcon(ERROR_ICON); -// label.setBorder(BorderFactory.createLineBorder(Color.black)); - label.setBorder(createHintBorder() - ); - label.setForeground(Color.black); - label.setFont(getBoldFont()); - label.setBackground(ERROR_COLOR); - label.setOpaque(true); + + if (!hintHint.isAwtTooltip()) { + label.setBorder(createHintBorder() + ); + label.setForeground(Color.black); + label.setFont(getBoldFont()); + label.setBackground(ERROR_COLOR); + label.setOpaque(true); + } + return label; } @@ -128,27 +141,75 @@ public class HintUtil { return label; } - private static class HintLabel extends JLabel { - public void setText(String s) { - if (s == null) { - super.setText(null); - } - else { - final int length = s.length(); + private static class HintLabel extends JPanel { - final String alignedText; - if (length < 100 && !s.contains("\n")) { - alignedText = s; - } else { - alignedText = s.replaceAll("(\n)|(\r\n)", " \n "); - } - super.setText(" " + alignedText + " "); + private JEditorPane myPane; + private SimpleColoredComponent myColored; + private JLabel myIcon; + + private HintLabel() { + setLayout(new BorderLayout()); + } + + + public void setText(SimpleColoredComponent colored) { + clearText(); + + myColored = colored; + add(myColored, BorderLayout.CENTER); + + setOpaque(true); + setBackground(colored.getBackground()); + + revalidate(); + repaint(); + } + + public void setText(String s, HintHint hintHint) { + clearText(); + + if (s != null) { + myPane = IdeTooltipManager.initPane(s, hintHint, null); + add(myPane, BorderLayout.CENTER); } + + setOpaque(true); + setBackground(hintHint.getTextBackground()); + + revalidate(); + repaint(); + } + + private void clearText() { + if (myPane != null) { + remove(myPane); + myPane = null; + } + + if (myColored != null) { + remove(myColored); + myColored = null; + } + } + + public void setIcon(Icon icon) { + if (myIcon != null) { + remove(myIcon); + } + + myIcon = new JLabel(icon, JLabel.CENTER); + myIcon.setVerticalAlignment(JLabel.TOP); + + add(myIcon, BorderLayout.WEST); + + revalidate(); + repaint(); } @Override public String toString() { - return "Hint: '" + getText() + "'"; + return "Hint: text='" + (myPane != null ? myPane.getText() : "") + "'"; } + } } \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/ide/IdeTooltipManager.java b/platform/platform-impl/src/com/intellij/ide/IdeTooltipManager.java index 37c882ab89c4..fb5ce84f1030 100644 --- a/platform/platform-impl/src/com/intellij/ide/IdeTooltipManager.java +++ b/platform/platform-impl/src/com/intellij/ide/IdeTooltipManager.java @@ -489,7 +489,7 @@ public class IdeTooltipManager implements ApplicationComponent, AWTEventListener } if (hintHint.isAwtTooltip()) { - Dimension size = layeredPane.getSize(); + Dimension size = layeredPane != null ? layeredPane.getSize() : new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE); int fitWidth = (int)(size.width * 0.8); Dimension prefSizeOriginal = pane.getPreferredSize(); if (prefSizeOriginal.width > fitWidth) { diff --git a/platform/platform-impl/src/com/intellij/openapi/fileChooser/ex/FileTextFieldImpl.java b/platform/platform-impl/src/com/intellij/openapi/fileChooser/ex/FileTextFieldImpl.java index e3e07c664083..ddda44542ffa 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileChooser/ex/FileTextFieldImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileChooser/ex/FileTextFieldImpl.java @@ -410,7 +410,7 @@ public abstract class FileTextFieldImpl implements FileLookup, Disposable, FileT if (!isExplicit) return; - final JLabel message = HintUtil.createErrorLabel(IdeBundle.message("file.chooser.completion.no.suggestions")); + final JComponent message = HintUtil.createErrorLabel(IdeBundle.message("file.chooser.completion.no.suggestions")); final ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(message, message); builder.setRequestFocus(false).setResizable(false).setAlpha(0.1f).setFocusOwners(new Component[] {myPathTextField}); myNoSuggestionsPopup = builder.createPopup(); 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 3662ecf17aac..9262f1739fa3 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 @@ -15,6 +15,7 @@ */ package com.intellij.openapi.wm.impl.status; +import com.intellij.codeInsight.hint.HintManager; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.PlatformDataKeys; @@ -39,6 +40,10 @@ public class AddTestProcessAction extends AnAction implements DumbAware { } public void actionPerformed(AnActionEvent e) { + HintManager.getInstance().showErrorHint(PlatformDataKeys.EDITOR.getData(e.getDataContext()), "Fuck
Fuck again"); + if (true) return; + + final Project p = PlatformDataKeys.PROJECT.getData(e.getDataContext()); if (p != null) { ToolWindowManager.getInstance(p) diff --git a/platform/platform-impl/src/com/intellij/ui/HintHint.java b/platform/platform-impl/src/com/intellij/ui/HintHint.java index 21baf0444008..853093969f01 100644 --- a/platform/platform-impl/src/com/intellij/ui/HintHint.java +++ b/platform/platform-impl/src/com/intellij/ui/HintHint.java @@ -48,6 +48,9 @@ public class HintHint { private int myPositionChangeX; private int myPositionChangeY; + public HintHint() { + } + public HintHint(MouseEvent e) { this(e.getComponent(), e.getPoint()); } diff --git a/plugins/android/src/org/jetbrains/android/util/AndroidUtils.java b/plugins/android/src/org/jetbrains/android/util/AndroidUtils.java index 73076f328d7f..c543ec8c5d83 100644 --- a/plugins/android/src/org/jetbrains/android/util/AndroidUtils.java +++ b/plugins/android/src/org/jetbrains/android/util/AndroidUtils.java @@ -377,7 +377,7 @@ public class AndroidUtils { public static void navigateTo(@NotNull PsiElement[] targets, @Nullable RelativePoint pointToShowPopup) { if (targets.length == 0) { - final JLabel renderer = HintUtil.createErrorLabel("Empty text"); + final JComponent renderer = HintUtil.createErrorLabel("Empty text"); final JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(renderer, renderer).createPopup(); if (pointToShowPopup != null) { popup.show(pointToShowPopup); diff --git a/plugins/tasks/tasks-core/src/com/intellij/tasks/actions/SearchSupport.java b/plugins/tasks/tasks-core/src/com/intellij/tasks/actions/SearchSupport.java index 8b70e6e2df13..13e38cc72a83 100644 --- a/plugins/tasks/tasks-core/src/com/intellij/tasks/actions/SearchSupport.java +++ b/plugins/tasks/tasks-core/src/com/intellij/tasks/actions/SearchSupport.java @@ -288,7 +288,7 @@ public abstract class SearchSupport { private void showNoSuggestions() { hideCurrentPopup(); - final JLabel message = HintUtil.createErrorLabel(IdeBundle.message("file.chooser.completion.no.suggestions")); + final JComponent message = HintUtil.createErrorLabel(IdeBundle.message("file.chooser.completion.no.suggestions")); final ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(message, message); builder.setRequestFocus(false).setResizable(false).setAlpha(0.1f). setFocusOwners(new Component[] {myTextField}); diff --git a/xml/dom-openapi/src/com/intellij/codeInsight/navigation/NavigationGutterIconRenderer.java b/xml/dom-openapi/src/com/intellij/codeInsight/navigation/NavigationGutterIconRenderer.java index d24600976705..5d101e112c19 100644 --- a/xml/dom-openapi/src/com/intellij/codeInsight/navigation/NavigationGutterIconRenderer.java +++ b/xml/dom-openapi/src/com/intellij/codeInsight/navigation/NavigationGutterIconRenderer.java @@ -104,7 +104,7 @@ public abstract class NavigationGutterIconRenderer extends GutterIconRenderer im final List list = getTargetElements(); if (list.isEmpty()) { if (myEmptyText != null) { - final JLabel renderer = HintUtil.createErrorLabel(myEmptyText); + final JComponent renderer = HintUtil.createErrorLabel(myEmptyText); final JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(renderer, renderer).createPopup(); if (event != null) { popup.show(new RelativePoint(event));