use of com.intellij.ui.LightweightHint in project intellij-community by JetBrains.
the class LineTooltipRenderer method show.
@Override
public LightweightHint show(@NotNull final Editor editor, @NotNull final Point p, final boolean alignToRight, @NotNull final TooltipGroup group, @NotNull final HintHint hintHint) {
if (myText == null)
return null;
//setup text
myText = myText.replaceAll(String.valueOf(UIUtil.MNEMONIC), "");
final boolean expanded = myCurrentWidth > 0 && dressDescription(editor);
final HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl();
final JComponent contentComponent = editor.getContentComponent();
final JComponent editorComponent = editor.getComponent();
if (!editorComponent.isShowing())
return null;
final JLayeredPane layeredPane = editorComponent.getRootPane().getLayeredPane();
final JEditorPane pane = IdeTooltipManager.initPane(new Html(myText).setKeepFont(true), hintHint, layeredPane);
hintHint.setContentActive(isActiveHtml(myText));
if (!hintHint.isAwtTooltip()) {
correctLocation(editor, pane, p, alignToRight, expanded, myCurrentWidth);
}
final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(pane);
scrollPane.setBorder(null);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
scrollPane.setOpaque(hintHint.isOpaqueAllowed());
scrollPane.getViewport().setOpaque(hintHint.isOpaqueAllowed());
scrollPane.setBackground(hintHint.getTextBackground());
scrollPane.getViewport().setBackground(hintHint.getTextBackground());
scrollPane.setViewportBorder(null);
if (hintHint.isRequestFocus()) {
pane.setFocusable(true);
}
final Ref<AnAction> actionRef = new Ref<>();
final LightweightHint hint = new LightweightHint(scrollPane) {
@Override
public void hide() {
onHide(pane);
super.hide();
final AnAction action = actionRef.get();
if (action != null) {
action.unregisterCustomShortcutSet(contentComponent);
}
}
};
actionRef.set(new AnAction() {
// an action to expand description when tooltip was shown after mouse move; need to unregister from editor component
{
registerCustomShortcutSet(new CustomShortcutSet(KeymapManager.getInstance().getActiveKeymap().getShortcuts(IdeActions.ACTION_SHOW_ERROR_DESCRIPTION)), contentComponent);
}
@Override
public void actionPerformed(final AnActionEvent e) {
// The tooltip gets the focus if using a screen reader and invocation through a keyboard shortcut.
hintHint.setRequestFocus(ScreenReader.isActive() && (e.getInputEvent() instanceof KeyEvent));
expand(hint, editor, p, pane, alignToRight, group, hintHint);
}
});
pane.addHyperlinkListener(new HyperlinkListener() {
@Override
public void hyperlinkUpdate(final HyperlinkEvent e) {
myActiveLink = true;
if (e.getEventType() == HyperlinkEvent.EventType.EXITED) {
myActiveLink = false;
return;
}
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
final URL url = e.getURL();
if (url != null) {
BrowserUtil.browse(url);
hint.hide();
return;
}
final String description = e.getDescription();
if (description != null && handle(description, editor)) {
hint.hide();
return;
}
if (!expanded) {
expand(hint, editor, p, pane, alignToRight, group, hintHint);
} else {
stripDescription();
hint.hide();
TooltipController.getInstance().showTooltip(editor, new Point(p.x - 3, p.y - 3), createRenderer(myText, 0), false, group, hintHint);
}
}
}
});
// This listener makes hint transparent for mouse events. It means that hint is closed
// by MousePressed and this MousePressed goes into the underlying editor component.
pane.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(final MouseEvent e) {
if (!myActiveLink) {
MouseEvent newMouseEvent = SwingUtilities.convertMouseEvent(e.getComponent(), e, contentComponent);
hint.hide();
contentComponent.dispatchEvent(newMouseEvent);
}
}
@Override
public void mouseExited(final MouseEvent e) {
if (!expanded) {
hint.hide();
}
}
});
hintManager.showEditorHint(hint, editor, p, HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_OTHER_HINT | HintManager.HIDE_BY_SCROLLING, 0, false, hintHint);
return hint;
}
use of com.intellij.ui.LightweightHint in project intellij-community by JetBrains.
the class TooltipController method showTooltip.
public void showTooltip(@NotNull Editor editor, @NotNull Point p, @NotNull TooltipRenderer tooltipRenderer, boolean alignToRight, @NotNull TooltipGroup group, @NotNull HintHint hintInfo) {
if (myCurrentTooltip == null || !myCurrentTooltip.isVisible()) {
myCurrentTooltipObject = null;
}
if (Comparing.equal(tooltipRenderer, myCurrentTooltipObject)) {
IdeTooltipManager.getInstance().cancelAutoHide();
return;
}
if (myCurrentTooltipGroup != null && group.compareTo(myCurrentTooltipGroup) < 0)
return;
p = new Point(p);
hideCurrentTooltip();
LightweightHint hint = tooltipRenderer.show(editor, p, alignToRight, group, hintInfo);
myCurrentTooltipGroup = group;
myCurrentTooltip = hint;
myCurrentTooltipObject = tooltipRenderer;
}
use of com.intellij.ui.LightweightHint in project intellij-community by JetBrains.
the class ShowParameterInfoHandler method showLookupEditorHint.
private static void showLookupEditorHint(Object[] descriptors, final Editor editor, final Project project, ParameterInfoHandler handler, boolean requestFocus) {
ParameterInfoComponent component = new ParameterInfoComponent(descriptors, editor, handler, requestFocus);
component.update();
final LightweightHint hint = new LightweightHint(component);
hint.setSelectingHint(true);
final HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl();
final Pair<Point, Short> pos = ParameterInfoController.chooseBestHintPosition(project, editor, null, hint, true, HintManager.DEFAULT);
ApplicationManager.getApplication().invokeLater(() -> {
if (!editor.getComponent().isShowing())
return;
hintManager.showEditorHint(hint, editor, pos.getFirst(), HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_LOOKUP_ITEM_CHANGE | HintManager.UPDATE_BY_SCROLLING, 0, false, pos.getSecond());
});
}
use of com.intellij.ui.LightweightHint in project intellij-community by JetBrains.
the class ParameterInfoController method chooseBestHintPosition.
/**
* Returned Point is in layered pane coordinate system.
*/
static Pair<Point, Short> chooseBestHintPosition(Project project, Editor editor, LogicalPosition pos, LightweightHint hint, boolean awtTooltip, short preferredPosition) {
if (ApplicationManager.getApplication().isUnitTestMode())
return Pair.pair(new Point(), HintManager.DEFAULT);
HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl();
Dimension hintSize = hint.getComponent().getPreferredSize();
JComponent editorComponent = editor.getComponent();
JLayeredPane layeredPane = editorComponent.getRootPane().getLayeredPane();
Point p1;
Point p2;
boolean isLookupShown = LookupManager.getInstance(project).getActiveLookup() != null;
if (isLookupShown) {
p1 = hintManager.getHintPosition(hint, editor, HintManager.UNDER);
p2 = hintManager.getHintPosition(hint, editor, HintManager.ABOVE);
} else {
p1 = HintManagerImpl.getHintPosition(hint, editor, pos, HintManager.UNDER);
p2 = HintManagerImpl.getHintPosition(hint, editor, pos, HintManager.ABOVE);
}
if (!awtTooltip) {
p1.x = Math.min(p1.x, layeredPane.getWidth() - hintSize.width);
p1.x = Math.max(p1.x, 0);
p2.x = Math.min(p2.x, layeredPane.getWidth() - hintSize.width);
p2.x = Math.max(p2.x, 0);
}
boolean p1Ok = p1.y + hintSize.height < layeredPane.getHeight();
boolean p2Ok = p2.y >= 0;
if (isLookupShown) {
if (p1Ok)
return new Pair<>(p1, HintManager.UNDER);
if (p2Ok)
return new Pair<>(p2, HintManager.ABOVE);
} else {
if (preferredPosition != HintManager.DEFAULT) {
if (preferredPosition == HintManager.ABOVE) {
if (p2Ok)
return new Pair<>(p2, HintManager.ABOVE);
} else if (preferredPosition == HintManager.UNDER) {
if (p1Ok)
return new Pair<>(p1, HintManager.UNDER);
}
}
if (p1Ok)
return new Pair<>(p1, HintManager.UNDER);
if (p2Ok)
return new Pair<>(p2, HintManager.ABOVE);
}
int underSpace = layeredPane.getHeight() - p1.y;
int aboveSpace = p2.y;
return aboveSpace > underSpace ? new Pair<>(new Point(p2.x, 0), HintManager.UNDER) : new Pair<>(p1, HintManager.ABOVE);
}
use of com.intellij.ui.LightweightHint in project intellij-community by JetBrains.
the class FindUsagesManager method showEditorHint.
private static void showEditorHint(String message, final Editor editor) {
JComponent component = HintUtil.createInformationLabel(message);
final LightweightHint hint = new LightweightHint(component);
HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, HintManager.UNDER, HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING, 0, false);
}
Aggregations