com.intellij.ui.LightweightHint Java Examples

The following examples show how to use com.intellij.ui.LightweightHint. 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: FlutterReloadManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private LightweightHint showEditorHint(@NotNull Editor editor, String message, boolean isError) {
  final AtomicReference<LightweightHint> ref = new AtomicReference<>();

  ApplicationManager.getApplication().invokeAndWait(() -> {
    final JComponent component = isError
                                 ? HintUtil.createErrorLabel(message)
                                 : HintUtil.createInformationLabel(message);
    final LightweightHint hint = new LightweightHint(component);
    ref.set(hint);
    HintManagerImpl.getInstanceImpl().showEditorHint(
      hint, editor, HintManager.UNDER,
      HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING | HintManager.HIDE_BY_OTHER_HINT,
      isError ? 0 : 3000, false);
  });

  return ref.get();
}
 
Example #2
Source File: NavBarUpdateQueue.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void queueRevalidate(@Nullable final Runnable after) {
  queue(new AfterModelUpdate(ID.REVALIDATE) {
    @Override
    protected void after() {
      final LightweightHint hint = myPanel.getHint();
      if (hint != null) {
        myPanel.getHintContainerShowPoint().doWhenDone((Consumer<RelativePoint>)relativePoint -> {
          hint.setSize(myPanel.getPreferredSize());
          hint.setLocation(relativePoint);
          if (after != null) {
            after.run();
          }
        });
      }
      else {
        if (after != null) {
          after.run();
        }
      }
    }
  });
}
 
Example #3
Source File: ElementPreviewHintProvider.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
private static LightweightHint getHint(@Nonnull PsiElement element) {
  for (PreviewHintProvider hintProvider : Extensions.getExtensions(PreviewHintProvider.EP_NAME)) {
    JComponent preview;
    try {
      preview = hintProvider.getPreviewComponent(element);
    }
    catch (Exception e) {
      LOG.error(e);
      continue;
    }
    if (preview != null) {
      return new LightweightHint(preview);
    }
  }
  return null;
}
 
Example #4
Source File: TrafficTooltipRendererImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public LightweightHint show(@Nonnull Editor editor, @Nonnull Point p, boolean alignToRight, @Nonnull TooltipGroup group, @Nonnull HintHint hintHint) {
  myTrafficLightRenderer = (TrafficLightRenderer)((EditorMarkupModel)editor.getMarkupModel()).getErrorStripeRenderer();
  myPanel = new TrafficProgressPanel(myTrafficLightRenderer, editor, hintHint);
  repaintTooltipWindow();
  LineTooltipRenderer.correctLocation(editor, myPanel, p, alignToRight, true, myPanel.getMinWidth());
  LightweightHint hint = new LightweightHint(myPanel);

  HintManagerImpl hintManager = (HintManagerImpl)HintManager.getInstance();
  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);
  hint.addHintListener(new HintListener() {
    @Override
    public void hintHidden(EventObject event) {
      if (myPanel == null) return; //double hide?
      myPanel = null;
      onHide.run();
    }
  });
  return hint;
}
 
Example #5
Source File: CommentByBlockCommentHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
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 #6
Source File: CtrlMouseHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void hyperlinkUpdate(@Nonnull HyperlinkEvent e) {
  if (e.getEventType() != HyperlinkEvent.EventType.ACTIVATED) {
    return;
  }

  String description = e.getDescription();
  if (StringUtil.isEmpty(description) || !description.startsWith(DocumentationManagerProtocol.PSI_ELEMENT_PROTOCOL)) {
    return;
  }

  String elementName = e.getDescription().substring(DocumentationManagerProtocol.PSI_ELEMENT_PROTOCOL.length());

  DumbService.getInstance(myProject).withAlternativeResolveEnabled(() -> {
    PsiElement targetElement = myProvider.getDocumentationElementForLink(PsiManager.getInstance(myProject), elementName, myContext);
    if (targetElement != null) {
      LightweightHint hint = myHint;
      if (hint != null) {
        hint.hide(true);
      }
      DocumentationManager.getInstance(myProject).showJavaDocInfo(targetElement, myContext, null);
    }
  });
}
 
Example #7
Source File: CtrlMouseHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void updateOnPsiChanges(@Nonnull LightweightHint hint, @Nonnull Info info, @Nonnull Consumer<? super String> textConsumer, @Nonnull String oldText, @Nonnull Editor editor) {
  if (!hint.isVisible()) return;
  Disposable hintDisposable = Disposable.newDisposable("CtrlMouseHandler.TooltipProvider.updateOnPsiChanges");
  hint.addHintListener(__ -> Disposer.dispose(hintDisposable));
  myProject.getMessageBus().connect(hintDisposable).subscribe(PsiModificationTracker.TOPIC, () -> ReadAction.nonBlocking(() -> {
    try {
      DocInfo newDocInfo = info.getInfo();
      return (Runnable)() -> {
        if (newDocInfo.text != null && !oldText.equals(newDocInfo.text)) {
          updateText(newDocInfo.text, textConsumer, hint, editor);
        }
      };
    }
    catch (IndexNotReadyException e) {
      showDumbModeNotification(myProject);
      return createDisposalContinuation();
    }
  }).finishOnUiThread(ModalityState.defaultModalityState(), Runnable::run).withDocumentsCommitted(myProject).expireWith(hintDisposable).expireWhen(() -> !info.isValid(editor.getDocument()))
          .coalesceBy(hint).submit(AppExecutorUtil.getAppExecutorService()));
}
 
Example #8
Source File: CompletionProgressIndicator.java    From consulo with Apache License 2.0 6 votes vote down vote up
void handleEmptyLookup(boolean awaitSecondInvocation) {
  if (isAutopopupCompletion() && ApplicationManager.getApplication().isUnitTestMode()) {
    return;
  }

  LOG.assertTrue(!isAutopopupCompletion());

  CompletionParameters parameters = getParameters();
  if (myHandler.invokedExplicitly && parameters != null) {
    LightweightHint hint = showErrorHint(getProject(), getEditor(), getNoSuggestionsMessage(parameters));
    if (awaitSecondInvocation) {
      CompletionServiceImpl.setCompletionPhase(new CompletionPhase.NoSuggestionsHint(hint, this));
      return;
    }
  }
  CompletionServiceImpl.setCompletionPhase(CompletionPhase.NoCompletion);
}
 
Example #9
Source File: FlutterReloadManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private LightweightHint showEditorHint(@NotNull Editor editor, String message, boolean isError) {
  final AtomicReference<LightweightHint> ref = new AtomicReference<>();

  ApplicationManager.getApplication().invokeAndWait(() -> {
    final JComponent component = isError
                                 ? HintUtil.createErrorLabel(message)
                                 : HintUtil.createInformationLabel(message);
    final LightweightHint hint = new LightweightHint(component);
    ref.set(hint);
    HintManagerImpl.getInstanceImpl().showEditorHint(
      hint, editor, HintManager.UNDER,
      HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING | HintManager.HIDE_BY_OTHER_HINT,
      isError ? 0 : 3000, false);
  });

  return ref.get();
}
 
Example #10
Source File: TooltipController.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void showTooltip(@Nonnull Editor editor,
                        @Nonnull Point p,
                        @Nonnull TooltipRenderer tooltipRenderer,
                        boolean alignToRight,
                        @Nonnull TooltipGroup group,
                        @Nonnull 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;
}
 
Example #11
Source File: CtrlMouseHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private Rectangle getHintBounds() {
  LightweightHint hint = myHint;
  if (hint == null) {
    return null;
  }
  JComponent hintComponent = hint.getComponent();
  if (!hintComponent.isShowing()) {
    return null;
  }
  return new Rectangle(hintComponent.getLocationOnScreen(), hintComponent.getSize());
}
 
Example #12
Source File: LSPReferencesAction.java    From lsp4intellij with Apache License 2.0 5 votes vote down vote up
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 #13
Source File: FindUsagesManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #14
Source File: SelectOccurrencesActionHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected static void showHint(final Editor editor) {
  String message = FindBundle.message("select.next.occurence.not.found.message");
  final LightweightHint hint = new LightweightHint(HintUtil.createInformationLabel(message));
  HintManagerImpl.getInstanceImpl().showEditorHint(hint,
                                                   editor,
                                                   HintManager.UNDER,
                                                   HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING,
                                                   0,
                                                   false);
}
 
Example #15
Source File: ElementPreviewHintProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void show(@Nonnull PsiElement element, @Nonnull Editor editor, @Nonnull Point point, boolean keyTriggered) {
  LightweightHint newHint = getHint(element);
  hideCurrentHintIfAny();
  if (newHint == null) {
    return;
  }

  hint = newHint;
  HintManagerImpl.getInstanceImpl().showEditorHint(newHint, editor,
                                                   getHintPosition(newHint, editor, editor.xyToLogicalPosition(point), HintManager.RIGHT_UNDER),
                                                   HINT_HIDE_FLAGS, 0, false);
}
 
Example #16
Source File: CodeInsightUtilBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void showReadOnlyViewWarning(Editor editor) {
  if (ApplicationManager.getApplication().isHeadlessEnvironment()) return;

  JComponent component = HintUtil.createInformationLabel("This view is read-only");
  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);
}
 
Example #17
Source File: FileInEditorProcessor.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void showHint(@Nonnull Editor editor, @Nonnull String info, @Nullable HyperlinkListener hyperlinkListener) {
  JComponent component = HintUtil.createInformationLabel(info, hyperlinkListener, null, null);
  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);
}
 
Example #18
Source File: JSGraphQLQueryContextHighlightVisitor.java    From js-graphql-intellij-plugin with MIT License 5 votes vote down vote up
/**
 * 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 #19
Source File: InputPanel.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 #20
Source File: CoverageLineMarkerRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
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 Editor 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 = 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));
}
 
Example #21
Source File: CtrlMouseHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
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 #22
Source File: TooltipController.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void showTooltipByMouseMove(@Nonnull final Editor editor,
                                   @Nonnull final RelativePoint point,
                                   final TooltipRenderer tooltipObject,
                                   final boolean alignToRight,
                                   @Nonnull final TooltipGroup group,
                                   @Nonnull HintHint hintHint) {
  LightweightHint currentTooltip = myCurrentTooltip;
  if (currentTooltip == null || !currentTooltip.isVisible()) {
    if (currentTooltip != null) {
      if (!IdeTooltipManager.getInstance().isQueuedToShow(currentTooltip.getCurrentIdeTooltip())) {
        myCurrentTooltipObject = null;
      }
    }
    else {
      myCurrentTooltipObject = null;
    }
  }

  if (Comparing.equal(tooltipObject, myCurrentTooltipObject)) {
    IdeTooltipManager.getInstance().cancelAutoHide();
    return;
  }
  hideCurrentTooltip();

  if (tooltipObject != null) {
    final Point p = point.getPointOn(editor.getComponent().getRootPane().getLayeredPane()).getPoint();
    if (!hintHint.isAwtTooltip()) {
      p.x += alignToRight ? -10 : 10;
    }

    Project project = editor.getProject();
    if (project != null && !project.isOpen()) return;
    if (editor.getContentComponent().isShowing()) {
      showTooltip(editor, p, tooltipObject, alignToRight, group, hintHint);
    }
  }
}
 
Example #23
Source File: BraceHighlightingHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
void clearBraceHighlighters() {
  List<RangeHighlighter> highlighters = getHighlightersList();
  for (final RangeHighlighter highlighter : highlighters) {
    highlighter.dispose();
  }
  highlighters.clear();

  LightweightHint hint = myEditor.getUserData(HINT_IN_EDITOR_KEY);
  if (hint != null) {
    hint.hide();
    myEditor.putUserData(HINT_IN_EDITOR_KEY, null);
  }
}
 
Example #24
Source File: TooltipController.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void hideCurrentTooltip() {
  if (myCurrentTooltip != null) {
    LightweightHint currentTooltip = myCurrentTooltip;
    myCurrentTooltip = null;
    currentTooltip.hide();
    myCurrentTooltipGroup = null;
    IdeTooltipManager.getInstance().hide(null);
  }
}
 
Example #25
Source File: CompletionProgressIndicator.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static LightweightHint showErrorHint(Project project, Editor editor, String text) {
  final LightweightHint[] result = {null};
  final EditorHintListener listener = (project1, hint, flags) -> result[0] = hint;
  final MessageBusConnection connection = project.getMessageBus().connect();
  connection.subscribe(EditorHintListener.TOPIC, listener);
  assert text != null;
  HintManager.getInstance().showInformationHint(editor, StringUtil.escapeXmlEntities(text), HintManager.UNDER);
  connection.disconnect();
  return result[0];
}
 
Example #26
Source File: EditorFragmentComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static LightweightHint showEditorFragmentHint(Editor editor, TextRange range, boolean showFolding, boolean hideByAnyKey) {
  if (!(editor instanceof EditorEx)) return null;
  JRootPane rootPane = editor.getComponent().getRootPane();
  if (rootPane == null) return null;
  JLayeredPane layeredPane = rootPane.getLayeredPane();
  int lineHeight = editor.getLineHeight();
  int overhang = editor.getScrollingModel().getVisibleArea().y - editor.logicalPositionToXY(editor.offsetToLogicalPosition(range.getEndOffset())).y;
  int yRelative = overhang > 0 && overhang < lineHeight ? lineHeight - overhang + JBUIScale.scale(LINE_BORDER_THICKNESS + EMPTY_BORDER_THICKNESS) : 0;
  Point point = SwingUtilities.convertPoint(((EditorEx)editor).getScrollPane().getViewport(), -2, yRelative, layeredPane);
  return showEditorFragmentHintAt(editor, range, point.y, true, showFolding, hideByAnyKey, true, false);
}
 
Example #27
Source File: ShowExpressionTypeHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
void showHint(String informationHint) {
  JComponent label = HintUtil.createInformationLabel(informationHint);
  setInstance(this);
  AccessibleContextUtil.setName(label, "Expression type hint");
  HintManagerImpl hintManager = (HintManagerImpl)HintManager.getInstance();
  LightweightHint hint = new LightweightHint(label);
  hint.addHintListener(e -> ApplicationManager.getApplication().invokeLater(() -> setInstance(null)));
  Point p = hintManager.getHintPosition(hint, myEditor, HintManager.ABOVE);
  int flags = HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING;
  hintManager.showEditorHint(hint, myEditor, p, flags, 0, false);
}
 
Example #28
Source File: ParameterInfoController.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private Pair<Point, Short> getBestPointPosition(LightweightHint hint, final PsiElement list, int offset, VisualPosition pos, short preferredPosition) {
  if (list != null) {
    TextRange range = list.getTextRange();
    TextRange rangeWithoutParens = TextRange.from(range.getStartOffset() + 1, Math.max(range.getLength() - 2, 0));
    if (!rangeWithoutParens.contains(offset)) {
      offset = offset < rangeWithoutParens.getStartOffset() ? rangeWithoutParens.getStartOffset() : rangeWithoutParens.getEndOffset();
      pos = null;
    }
  }
  if (previousOffset == offset) return Pair.create(previousBestPoint, previousBestPosition);

  final boolean isMultiline = list != null && StringUtil.containsAnyChar(list.getText(), "\n\r");
  if (pos == null) pos = EditorUtil.inlayAwareOffsetToVisualPosition(myEditor, offset);
  Pair<Point, Short> position;

  if (!isMultiline) {
    position = chooseBestHintPosition(myEditor, pos, hint, preferredPosition, false);
  }
  else {
    Point p = HintManagerImpl.getHintPosition(hint, myEditor, pos, HintManager.ABOVE);
    position = new Pair<>(p, HintManager.ABOVE);
  }
  previousBestPoint = position.getFirst();
  previousBestPosition = position.getSecond();
  previousOffset = offset;
  return position;
}
 
Example #29
Source File: ParameterInfoController.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Returned Point is in layered pane coordinate system.
 * Second value is a {@link HintManager.PositionFlags position flag}.
 */
static Pair<Point, Short> chooseBestHintPosition(Editor editor, VisualPosition pos, LightweightHint hint, short preferredPosition, boolean showLookupHint) {
  if (ApplicationManager.getApplication().isUnitTestMode() || ApplicationManager.getApplication().isHeadlessEnvironment()) 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;
  if (showLookupHint) {
    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);
  }

  boolean p1Ok = p1.y + hintSize.height < layeredPane.getHeight();
  boolean p2Ok = p2.y >= 0;

  if (!showLookupHint) {
    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);
}
 
Example #30
Source File: ShowParameterInfoHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void showLookupEditorHint(Object[] descriptors, final Editor editor, ParameterInfoHandler handler, boolean requestFocus) {
  ParameterInfoComponent component = new ParameterInfoComponent(descriptors, editor, handler, requestFocus, false);
  component.update(false);

  final LightweightHint hint = new LightweightHint(component);
  hint.setSelectingHint(true);
  final HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl();
  final Pair<Point, Short> pos = ParameterInfoController.chooseBestHintPosition(editor, null, hint, HintManager.DEFAULT, true);
  ApplicationManager.getApplication().invokeLater(() -> {
    if (!EditorActivityManager.getInstance().isVisible(editor)) 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());
  });
}