Search in sources :

Example 1 with TooltipController

use of com.intellij.codeInsight.hint.TooltipController in project intellij-community by JetBrains.

the class EditorGutterComponentImpl method mouseMoved.

@Override
public void mouseMoved(final MouseEvent e) {
    String toolTip = null;
    final GutterIconRenderer renderer = getGutterRenderer(e);
    TooltipController controller = TooltipController.getInstance();
    if (renderer != null) {
        toolTip = renderer.getTooltipText();
    } else {
        TextAnnotationGutterProvider provider = getProviderAtPoint(e.getPoint());
        if (provider != null) {
            final int line = getLineNumAtPoint(e.getPoint());
            toolTip = provider.getToolTip(line, myEditor);
            if (!Comparing.equal(toolTip, myLastGutterToolTip)) {
                controller.cancelTooltip(GUTTER_TOOLTIP_GROUP, e, true);
                myLastGutterToolTip = toolTip;
            }
        } else {
            ActiveGutterRenderer lineRenderer = getActiveRendererByMouseEvent(e);
            if (lineRenderer != null) {
                toolTip = lineRenderer.getTooltipText();
            }
        }
    }
    if (toolTip != null && !toolTip.isEmpty()) {
        final Ref<Point> t = new Ref<>(e.getPoint());
        int line = EditorUtil.yPositionToLogicalLine(myEditor, e);
        List<GutterMark> row = getGutterRenderers(line);
        Balloon.Position ballPosition = Balloon.Position.atRight;
        if (row != null) {
            final TreeMap<Integer, GutterMark> xPos = new TreeMap<>();
            final int[] currentPos = { 0 };
            processIconsRow(line, row, (x, y, r) -> {
                xPos.put(x, r);
                if (renderer == r) {
                    currentPos[0] = x;
                    Icon icon = scaleIcon(r.getIcon());
                    t.set(new Point(x + icon.getIconWidth() / 2, y + icon.getIconHeight() / 2));
                }
            });
            List<Integer> xx = new ArrayList<>(xPos.keySet());
            int posIndex = xx.indexOf(currentPos[0]);
            if (xPos.size() > 1 && posIndex == 0) {
                ballPosition = Balloon.Position.below;
            }
        }
        RelativePoint showPoint = new RelativePoint(this, t.get());
        controller.showTooltipByMouseMove(myEditor, showPoint, ((EditorMarkupModel) myEditor.getMarkupModel()).getErrorStripTooltipRendererProvider().calcTooltipRenderer(toolTip), false, GUTTER_TOOLTIP_GROUP, new HintHint(this, t.get()).setAwtTooltip(true).setPreferredPosition(ballPosition));
    } else {
        controller.cancelTooltip(GUTTER_TOOLTIP_GROUP, e, false);
    }
}
Also used : TIntArrayList(gnu.trove.TIntArrayList) Balloon(com.intellij.openapi.ui.popup.Balloon) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) NonHideableIconGutterMark(com.intellij.codeInsight.daemon.NonHideableIconGutterMark) GutterMark(com.intellij.codeInsight.daemon.GutterMark) RelativePoint(com.intellij.ui.awt.RelativePoint) HintHint(com.intellij.ui.HintHint) Ref(com.intellij.openapi.util.Ref) HintHint(com.intellij.ui.HintHint) TooltipController(com.intellij.codeInsight.hint.TooltipController) ScalableIcon(com.intellij.openapi.util.ScalableIcon)

Example 2 with TooltipController

use of com.intellij.codeInsight.hint.TooltipController in project intellij-community by JetBrains.

the class ConsoleGutterComponent method mouseMoved.

@Override
public void mouseMoved(MouseEvent e) {
    int line = EditorUtil.yPositionToLogicalLine(editor, e.getPoint());
    if (line == lastGutterToolTipLine) {
        return;
    }
    TooltipController controller = TooltipController.getInstance();
    if (lastGutterToolTipLine != -1) {
        controller.cancelTooltip(TOOLTIP_GROUP, e, true);
    }
    String toolTip = gutterContentProvider.getToolTip(line, editor);
    setCursor(toolTip == null ? Cursor.getDefaultCursor() : Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    if (toolTip == null) {
        lastGutterToolTipLine = -1;
        controller.cancelTooltip(TOOLTIP_GROUP, e, false);
    } else {
        lastGutterToolTipLine = line;
        RelativePoint showPoint = new RelativePoint(this, e.getPoint());
        controller.showTooltipByMouseMove(editor, showPoint, ((EditorMarkupModel) editor.getMarkupModel()).getErrorStripTooltipRendererProvider().calcTooltipRenderer(toolTip), false, TOOLTIP_GROUP, new HintHint(this, e.getPoint()).setAwtTooltip(true));
    }
}
Also used : HintHint(com.intellij.ui.HintHint) TooltipController(com.intellij.codeInsight.hint.TooltipController) RelativePoint(com.intellij.ui.awt.RelativePoint) HintHint(com.intellij.ui.HintHint) RelativePoint(com.intellij.ui.awt.RelativePoint) EditorMarkupModel(com.intellij.openapi.editor.ex.EditorMarkupModel)

Aggregations

TooltipController (com.intellij.codeInsight.hint.TooltipController)2 HintHint (com.intellij.ui.HintHint)2 RelativePoint (com.intellij.ui.awt.RelativePoint)2 GutterMark (com.intellij.codeInsight.daemon.GutterMark)1 NonHideableIconGutterMark (com.intellij.codeInsight.daemon.NonHideableIconGutterMark)1 EditorMarkupModel (com.intellij.openapi.editor.ex.EditorMarkupModel)1 Balloon (com.intellij.openapi.ui.popup.Balloon)1 Ref (com.intellij.openapi.util.Ref)1 ScalableIcon (com.intellij.openapi.util.ScalableIcon)1 TIntArrayList (gnu.trove.TIntArrayList)1