Java Code Examples for com.intellij.codeInsight.hint.HintManagerImpl#getHintPosition()
The following examples show how to use
com.intellij.codeInsight.hint.HintManagerImpl#getHintPosition() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommentByBlockCommentHandler.java From consulo with Apache License 2.0 | 6 votes |
private void showMessageIfNeeded() { if (myWarning != null) { myEditor.getScrollingModel().disableAnimation(); myEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); myEditor.getScrollingModel().enableAnimation(); LogicalPosition hintPosition = myCaret.getLogicalPosition(); if (myWarningLocation != null) { LogicalPosition targetPosition = myEditor.offsetToLogicalPosition(myWarningLocation.getStartOffset()); Point targetPoint = myEditor.logicalPositionToXY(targetPosition); if (myEditor.getScrollingModel().getVisibleArea().contains(targetPoint)) { hintPosition = targetPosition; } } LightweightHint hint = new LightweightHint(HintUtil.createInformationLabel(myWarning)); Point p = HintManagerImpl.getHintPosition(hint, myEditor, hintPosition, HintManager.ABOVE); HintManagerImpl.getInstanceImpl().showEditorHint(hint, myEditor, p, 0, 0, false); } }
Example 2
Source File: LSPReferencesAction.java From lsp4intellij with Apache License 2.0 | 5 votes |
private void showReferences(Editor editor, List<PsiElement2UsageTargetAdapter> targets, LogicalPosition position) { if (targets.isEmpty()) { short constraint = HintManager.ABOVE; int flags = HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING; JLabel label = new JLabel("No references found"); label.setBackground(new JBColor(new Color(150, 0, 0), new Color(150, 0, 0))); LightweightHint hint = new LightweightHint(label); Point p = HintManagerImpl.getHintPosition(hint, editor, position, constraint); HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, p, flags, 0, false, HintManagerImpl.createHintHint(editor, p, hint, constraint).setContentActive(false)); } else { List<Usage> usages = new ArrayList<>(); targets.forEach(ut -> { PsiElement elem = ut.getElement(); usages.add(new UsageInfo2UsageAdapter(new UsageInfo(elem, -1, -1, false))); }); if (editor == null) { return; } Project project = editor.getProject(); if (project == null) { return; } UsageViewPresentation presentation = createPresentation(targets.get(0).getElement(), new FindUsagesOptions(editor.getProject()), false); UsageViewManager.getInstance(project) .showUsages(new UsageTarget[] { targets.get(0) }, usages.toArray(new Usage[usages.size()]), presentation); } }
Example 3
Source File: JSGraphQLQueryContextHighlightVisitor.java From js-graphql-intellij-plugin with MIT License | 5 votes |
/** * Shows a query context hint under the current caret position. * The hint hides after a few seconds or when the user interacts with the editor */ private static void showQueryContextHint(Editor editor, String hintText) { final HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl(); final JComponent label = HintUtil.createInformationLabel(hintText); final LightweightHint lightweightHint = new LightweightHint(label); final Point hintPosition = hintManager.getHintPosition(lightweightHint, editor, HintManager.UNDER); hintManager.showEditorHint(lightweightHint, editor, hintPosition, 0, 2000, false, HintManager.UNDER); }
Example 4
Source File: InputPanel.java From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static void showDecisionEventToolTip(Editor editor, int offset, HintManagerImpl hintMgr, String msg) { int flags = HintManager.HIDE_BY_ANY_KEY| HintManager.HIDE_BY_TEXT_CHANGE| HintManager.HIDE_BY_SCROLLING; int timeout = 0; // default? JComponent infoLabel = HintUtil.createInformationLabel(msg); LightweightHint hint = new LightweightHint(infoLabel); final LogicalPosition pos = editor.offsetToLogicalPosition(offset); final Point p = HintManagerImpl.getHintPosition(hint, editor, pos, HintManager.ABOVE); hintMgr.showEditorHint(hint, editor, p, flags, timeout, false); }
Example 5
Source File: CtrlMouseHandler.java From consulo with Apache License 2.0 | 5 votes |
public void showHint(@Nonnull LightweightHint hint, @Nonnull Editor editor) { if (ApplicationManager.getApplication().isUnitTestMode() || editor.isDisposed()) return; final HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl(); short constraint = HintManager.ABOVE; LogicalPosition position = editor.offsetToLogicalPosition(getOffset(editor)); Point p = HintManagerImpl.getHintPosition(hint, editor, position, constraint); if (p.y - hint.getComponent().getPreferredSize().height < 0) { constraint = HintManager.UNDER; p = HintManagerImpl.getHintPosition(hint, editor, position, constraint); } hintManager.showEditorHint(hint, editor, p, HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING, 0, false, HintManagerImpl.createHintHint(editor, p, hint, constraint).setContentActive(false)); }
Example 6
Source File: LineStatusMarkerPopup.java From consulo with Apache License 2.0 | 4 votes |
public void showHintAt(@javax.annotation.Nullable Point mousePosition) { if (!myTracker.isValid()) return; final Disposable disposable = Disposable.newDisposable(); FileType fileType = getFileType(); List<DiffFragment> wordDiff = computeWordDiff(); installMasterEditorHighlighters(wordDiff, disposable); JComponent editorComponent = createEditorComponent(fileType, wordDiff); ActionToolbar toolbar = buildToolbar(mousePosition, disposable); toolbar.updateActionsImmediately(); // we need valid ActionToolbar.getPreferredSize() to calc size of popup toolbar.setReservePlaceAutoPopupIcon(false); PopupPanel popupPanel = new PopupPanel(myEditor, toolbar, editorComponent); LightweightHint hint = new LightweightHint(popupPanel); HintListener closeListener = new HintListener() { public void hintHidden(final EventObject event) { Disposer.dispose(disposable); } }; hint.addHintListener(closeListener); int line = myEditor.getCaretModel().getLogicalPosition().line; Point point = HintManagerImpl.getHintPosition(hint, myEditor, new LogicalPosition(line, 0), HintManager.UNDER); if (mousePosition != null) { // show right after the nearest line int lineHeight = myEditor.getLineHeight(); int delta = (point.y - mousePosition.y) % lineHeight; if (delta < 0) delta += lineHeight; point.y = mousePosition.y + delta; } point.x -= popupPanel.getEditorTextOffset(); // align main editor with the one in popup int flags = HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING; HintManagerImpl.getInstanceImpl().showEditorHint(hint, myEditor, point, flags, -1, false, new HintHint(myEditor, point)); if (!hint.isVisible()) { closeListener.hintHidden(null); } }