Search in sources :

Example 6 with HintHint

use of com.intellij.ui.HintHint 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)

Example 7 with HintHint

use of com.intellij.ui.HintHint in project intellij-community by JetBrains.

the class EditorFragmentComponent method showEditorFragmentHintAt.

/**
   * @param y <code>y</code> coordinate in layered pane coordinate system.
   */
@Nullable
public static LightweightHint showEditorFragmentHintAt(Editor editor, TextRange range, int y, boolean showUpward, boolean showFolding, boolean hideByAnyKey, boolean hideByScrolling, boolean useCaretRowBackground) {
    if (ApplicationManager.getApplication().isUnitTestMode())
        return null;
    Document document = editor.getDocument();
    int startOffset = range.getStartOffset();
    int startLine = document.getLineNumber(startOffset);
    CharSequence text = document.getCharsSequence();
    // There is a possible case that we have a situation like below:
    //    line 1
    //    line 2 <fragment start>
    //    line 3<fragment end>
    // We don't want to include 'line 2' to the target fragment then.
    boolean incrementLine = false;
    for (int offset = startOffset, max = Math.min(range.getEndOffset(), text.length()); offset < max; offset++) {
        char c = text.charAt(offset);
        incrementLine = StringUtil.isWhiteSpace(c);
        if (!incrementLine || c == '\n') {
            break;
        }
    }
    if (incrementLine) {
        startLine++;
    }
    int endLine = Math.min(document.getLineNumber(range.getEndOffset()) + 1, document.getLineCount() - 1);
    if (startLine >= endLine)
        return null;
    EditorFragmentComponent fragmentComponent = createEditorFragmentComponent(editor, startLine, endLine, showFolding, true, useCaretRowBackground);
    if (showUpward) {
        y -= fragmentComponent.getPreferredSize().height;
        y = Math.max(0, y);
    }
    final JComponent c = editor.getComponent();
    //IDEA-68016
    int x = SwingUtilities.convertPoint(c, new Point(JBUI.scale(-3), 0), UIUtil.getRootPane(c)).x;
    Point p = new Point(x, y);
    LightweightHint hint = new MyComponentHint(fragmentComponent);
    HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, p, (hideByAnyKey ? HintManager.HIDE_BY_ANY_KEY : 0) | (hideByScrolling ? HintManager.HIDE_BY_SCROLLING : 0) | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_MOUSEOVER, 0, false, new HintHint(editor, p));
    return hint;
}
Also used : HintHint(com.intellij.ui.HintHint) LightweightHint(com.intellij.ui.LightweightHint) Document(com.intellij.openapi.editor.Document) HintHint(com.intellij.ui.HintHint) LightweightHint(com.intellij.ui.LightweightHint) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with HintHint

use of com.intellij.ui.HintHint in project intellij-community by JetBrains.

the class UIUtil method showTooltip.

static void showTooltip(@NotNull Editor editor, final int start, int end, @NotNull String text) {
    final Rectangle visibleArea = editor.getScrollingModel().getVisibleArea();
    final Point left = editor.logicalPositionToXY(editor.offsetToLogicalPosition(start));
    final int documentLength = editor.getDocument().getTextLength();
    if (end >= documentLength)
        end = documentLength;
    final Point right = editor.logicalPositionToXY(editor.offsetToLogicalPosition(end));
    final Point bestPoint = new Point(left.x + (right.x - left.x) / 2, right.y + editor.getLineHeight() / 2);
    if (visibleArea.x > bestPoint.x) {
        bestPoint.x = visibleArea.x;
    } else if (visibleArea.x + visibleArea.width < bestPoint.x) {
        bestPoint.x = visibleArea.x + visibleArea.width - 5;
    }
    final Point p = SwingUtilities.convertPoint(editor.getContentComponent(), bestPoint, editor.getComponent().getRootPane().getLayeredPane());
    final HintHint hint = new HintHint(editor, bestPoint).setAwtTooltip(true).setHighlighterType(true).setShowImmediately(true).setCalloutShift(editor.getLineHeight() / 2 - 1);
    TooltipController.getInstance().showTooltip(editor, p, text, visibleArea.width, false, SS_INFO_TOOLTIP_GROUP, hint);
}
Also used : HintHint(com.intellij.ui.HintHint) HintHint(com.intellij.ui.HintHint)

Example 9 with HintHint

use of com.intellij.ui.HintHint 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 10 with HintHint

use of com.intellij.ui.HintHint in project intellij-community by JetBrains.

the class CoverageLineMarkerRenderer method showHint.

private void showHint(final Editor editor, final Point point, final int lineNumber) {
    final JPanel panel = new JPanel(new BorderLayout());
    panel.add(createActionsToolbar(editor, lineNumber), BorderLayout.NORTH);
    final LineData lineData = getLineData(lineNumber);
    final EditorImpl uEditor;
    if (lineData != null && lineData.getStatus() != LineCoverage.NONE && !mySubCoverageActive) {
        final EditorFactory factory = EditorFactory.getInstance();
        final Document doc = factory.createDocument(getReport(editor, lineNumber));
        doc.setReadOnly(true);
        uEditor = (EditorImpl) factory.createEditor(doc, editor.getProject());
        panel.add(EditorFragmentComponent.createEditorFragmentComponent(uEditor, 0, doc.getLineCount(), false, false), BorderLayout.CENTER);
    } else {
        uEditor = null;
    }
    final LightweightHint hint = new LightweightHint(panel) {

        @Override
        public void hide() {
            if (uEditor != null)
                EditorFactory.getInstance().releaseEditor(uEditor);
            super.hide();
        }
    };
    HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, point, HintManagerImpl.HIDE_BY_ANY_KEY | HintManagerImpl.HIDE_BY_TEXT_CHANGE | HintManagerImpl.HIDE_BY_OTHER_HINT | HintManagerImpl.HIDE_BY_SCROLLING, -1, false, new HintHint(editor, point));
}
Also used : LineData(com.intellij.rt.coverage.data.LineData) EditorFactory(com.intellij.openapi.editor.EditorFactory) HintHint(com.intellij.ui.HintHint) EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) LightweightHint(com.intellij.ui.LightweightHint) Document(com.intellij.openapi.editor.Document)

Aggregations

HintHint (com.intellij.ui.HintHint)18 LightweightHint (com.intellij.ui.LightweightHint)10 Document (com.intellij.openapi.editor.Document)4 TooltipController (com.intellij.codeInsight.hint.TooltipController)2 Editor (com.intellij.openapi.editor.Editor)2 RelativePoint (com.intellij.ui.awt.RelativePoint)2 NonOpaquePanel (com.intellij.ui.components.panels.NonOpaquePanel)2 GutterMark (com.intellij.codeInsight.daemon.GutterMark)1 NonHideableIconGutterMark (com.intellij.codeInsight.daemon.NonHideableIconGutterMark)1 ErrorInfo (com.intellij.designer.model.ErrorInfo)1 DiffFragment (com.intellij.diff.fragments.DiffFragment)1 LineRange (com.intellij.diff.util.LineRange)1 IdeTooltip (com.intellij.ide.IdeTooltip)1 EditorWindow (com.intellij.injected.editor.EditorWindow)1 Disposable (com.intellij.openapi.Disposable)1 EditorFactory (com.intellij.openapi.editor.EditorFactory)1 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)1 EditorActionManager (com.intellij.openapi.editor.actionSystem.EditorActionManager)1 TypedAction (com.intellij.openapi.editor.actionSystem.TypedAction)1 EditorEx (com.intellij.openapi.editor.ex.EditorEx)1