Java 类com.intellij.ui.LightweightHint 实例源码

项目:intellij-ce-playground    文件:FindInEditorTest.java   
@Override
protected void setUp() throws Exception {
  super.setUp();

  myFindModel = new FindModel();

  myOutputStream = new ByteArrayOutputStream();
  LivePreview.ourTestOutput = new PrintStream(myOutputStream);
  EditorHintListener listener = new EditorHintListener() {
    @Override
    public void hintShown(Project project, LightweightHint hint, int flags) {
      LivePreview.processNotFound();
    }
  };
  ApplicationManager.getApplication().getMessageBus().connect(myTestRootDisposable).subscribe(EditorHintListener.TOPIC, listener);
}
项目:intellij-ce-playground    文件:TooltipController.java   
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;
}
项目:intellij-ce-playground    文件:ShowParameterInfoHandler.java   
private static void showLookupEditorHint(Object[] descriptors, final Editor editor, final Project project, ParameterInfoHandler handler) {
  ParameterInfoComponent component = new ParameterInfoComponent(descriptors, editor, handler);
  component.update();

  final LightweightHint hint = new LightweightHint(component);
  hint.setSelectingHint(true);
  final HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl();
  final Pair<Point, Short> pos = ShowParameterInfoContext.chooseBestHintPosition(project, editor, -1, -1, hint, true, HintManager.DEFAULT);
  ApplicationManager.getApplication().invokeLater(new Runnable() {
    @Override
    public void run() {
      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());
    }
  });
}
项目:intellij-ce-playground    文件:CompletionProgressIndicator.java   
protected void handleEmptyLookup(final boolean awaitSecondInvocation) {
  if (isAutopopupCompletion() && ApplicationManager.getApplication().isUnitTestMode()) {
    return;
  }

  LOG.assertTrue(!isAutopopupCompletion());

  if (ApplicationManager.getApplication().isUnitTestMode() || !myHandler.invokedExplicitly) {
    CompletionServiceImpl.setCompletionPhase(CompletionPhase.NoCompletion);
    return;
  }

  for (final CompletionContributor contributor : CompletionContributor.forParameters(getParameters())) {
    final String text = contributor.handleEmptyLookup(getParameters(), getEditor());
    if (StringUtil.isNotEmpty(text)) {
      LightweightHint hint = showErrorHint(getProject(), getEditor(), text);
      CompletionServiceImpl.setCompletionPhase(
        awaitSecondInvocation ? new CompletionPhase.NoSuggestionsHint(hint, this) : CompletionPhase.NoCompletion);
      return;
    }
  }
  CompletionServiceImpl.setCompletionPhase(CompletionPhase.NoCompletion);
}
项目:intellij-ce-playground    文件:CtrlMouseHandler.java   
@Override
public void hyperlinkUpdate(@NotNull 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());

  final PsiElement targetElement = myProvider.getDocumentationElementForLink(PsiManager.getInstance(myProject), elementName, myContext);
  if (targetElement != null) {
    LightweightHint hint = myHint;
    if (hint != null) {
      hint.hide(true);
    }
    myDocumentationManager.showJavaDocInfo(targetElement, myContext, null);
  }
}
项目:intellij-ce-playground    文件:TrafficTooltipRendererImpl.java   
@Override
public LightweightHint show(@NotNull Editor editor, @NotNull Point p, boolean alignToRight, @NotNull TooltipGroup group, @NotNull HintHint hintHint) {
  myTrafficLightRenderer = (TrafficLightRenderer)((EditorMarkupModelImpl)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;
}
项目:intellij-ce-playground    文件:ElementPreviewHintProvider.java   
@Nullable
private static LightweightHint getHint(@NotNull 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;
}
项目:intellij-ce-playground    文件:NavBarUpdateQueue.java   
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(new Consumer<RelativePoint>() {
          @Override
          public void consume(final RelativePoint relativePoint) {
            hint.setSize(myPanel.getPreferredSize());
            hint.setLocation(relativePoint);
            if (after != null) {
              after.run();
            }
          }
        });
      }
      else {
        if (after != null) {
          after.run();
        }
      }
    }
  });
}
项目:tools-idea    文件:TooltipController.java   
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;
}
项目:tools-idea    文件:ShowParameterInfoHandler.java   
private static void showLookupEditorHint(Object[] descriptors, final Editor editor, final Project project, ParameterInfoHandler handler) {
  ParameterInfoComponent component = new ParameterInfoComponent(descriptors, editor, handler);
  component.update();

  final LightweightHint hint = new LightweightHint(component);
  hint.setSelectingHint(true);
  final HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl();
  final Pair<Point, Short> pos = ShowParameterInfoContext.chooseBestHintPosition(project, editor, -1, -1, hint, true, HintManager.DEFAULT);
  ApplicationManager.getApplication().invokeLater(new Runnable() {
    @Override
    public void run() {
      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());
    }
  });
}
项目:tools-idea    文件:CompletionProgressIndicator.java   
protected void handleEmptyLookup(final boolean awaitSecondInvocation) {
  LOG.assertTrue(!isAutopopupCompletion());

  if (ApplicationManager.getApplication().isUnitTestMode() || !myHandler.invokedExplicitly) {
    CompletionServiceImpl.setCompletionPhase(CompletionPhase.NoCompletion);
    return;
  }

  for (final CompletionContributor contributor : CompletionContributor.forParameters(getParameters())) {
    final String text = contributor.handleEmptyLookup(getParameters(), getEditor());
    if (StringUtil.isNotEmpty(text)) {
      LightweightHint hint = showErrorHint(getProject(), getEditor(), text);
      CompletionServiceImpl.setCompletionPhase(
        awaitSecondInvocation ? new CompletionPhase.NoSuggestionsHint(hint, this) : CompletionPhase.NoCompletion);
      return;
    }
  }
  CompletionServiceImpl.setCompletionPhase(CompletionPhase.NoCompletion);
}
项目:tools-idea    文件:CtrlMouseHandler.java   
@Override
public void hyperlinkUpdate(@NotNull HyperlinkEvent e) {
  if (e.getEventType() != HyperlinkEvent.EventType.ACTIVATED) {
    return;
  }

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

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

  final PsiElement targetElement = myProvider.getDocumentationElementForLink(PsiManager.getInstance(myProject), elementName, myContext);
  if (targetElement != null) {
    LightweightHint hint = myHint;
    if (hint != null) {
      hint.hide(true);
    }
    myDocumentationManager.showJavaDocInfo(targetElement, myContext, true, null);
  }
}
项目:tools-idea    文件:TrafficTooltipRendererImpl.java   
@Override
public LightweightHint show(@NotNull Editor editor, @NotNull Point p, boolean alignToRight, @NotNull TooltipGroup group, @NotNull HintHint hintHint) {
  myTrafficLightRenderer = (TrafficLightRenderer)((EditorMarkupModelImpl)editor.getMarkupModel()).getErrorStripeRenderer();
  myPanel = new TrafficProgressPanel(myTrafficLightRenderer, editor, hintHint);
  LineTooltipRenderer.correctLocation(editor, myPanel, p, alignToRight, false, -1);
  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();
    }
  });
  repaintTooltipWindow();
  return hint;
}
项目:tools-idea    文件:ElementPreviewHintProvider.java   
@Nullable
private static LightweightHint getHint(@NotNull 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;
}
项目:tools-idea    文件:NavBarUpdateQueue.java   
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(new AsyncResult.Handler<RelativePoint>() {
          @Override
          public void run(final RelativePoint relativePoint) {
            hint.setSize(myPanel.getPreferredSize());
            hint.setLocation(relativePoint);
            if (after != null) {
              after.run();
            }
          }
        });
      }
      else {
        if (after != null) {
          after.run();
        }
      }
    }
  });
}
项目:consulo    文件:TooltipController.java   
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;
}
项目:consulo    文件:ShowParameterInfoHandler.java   
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 = ShowParameterInfoContext.chooseBestHintPosition(project, editor, -1, -1, hint, true, HintManager.DEFAULT);
  ApplicationManager.getApplication().invokeLater(new Runnable() {
    @Override
    public void run() {
      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());
    }
  });
}
项目:consulo    文件:CompletionProgressIndicator.java   
protected void handleEmptyLookup(final boolean awaitSecondInvocation) {
  if (isAutopopupCompletion() && ApplicationManager.getApplication().isUnitTestMode()) {
    return;
  }

  LOG.assertTrue(!isAutopopupCompletion());

  if (ApplicationManager.getApplication().isUnitTestMode() || !myHandler.invokedExplicitly) {
    CompletionServiceImpl.setCompletionPhase(CompletionPhase.NoCompletion);
    return;
  }

  for (final CompletionContributor contributor : CompletionContributor.forParameters(getParameters())) {
    final String text = contributor.handleEmptyLookup(getParameters(), getEditor());
    if (StringUtil.isNotEmpty(text)) {
      LightweightHint hint = showErrorHint(getProject(), getEditor(), text);
      CompletionServiceImpl.setCompletionPhase(
              awaitSecondInvocation ? new CompletionPhase.NoSuggestionsHint(hint, this) : CompletionPhase.NoCompletion);
      return;
    }
  }
  CompletionServiceImpl.setCompletionPhase(CompletionPhase.NoCompletion);
}
项目:consulo    文件:CtrlMouseHandler.java   
@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());

  final PsiElement targetElement = myProvider.getDocumentationElementForLink(PsiManager.getInstance(myProject), elementName, myContext);
  if (targetElement != null) {
    LightweightHint hint = myHint;
    if (hint != null) {
      hint.hide(true);
    }
    myDocumentationManager.showJavaDocInfo(targetElement, myContext, null);
  }
}
项目:consulo    文件:CommentByBlockCommentHandler.java   
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);
  }
}
项目:consulo    文件:TrafficTooltipRendererImpl.java   
@Override
public LightweightHint show(@Nonnull Editor editor, @Nonnull Point p, boolean alignToRight, @Nonnull TooltipGroup group, @Nonnull HintHint hintHint) {
  myTrafficLightRenderer = (TrafficLightRenderer)((EditorMarkupModelImpl)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;
}
项目:consulo    文件:ElementPreviewHintProvider.java   
@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;
}
项目:consulo    文件:NavBarUpdateQueue.java   
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();
        }
      }
    }
  });
}
项目:intellij-ce-playground    文件:TooltipController.java   
public void showTooltipByMouseMove(@NotNull final Editor editor,
                                   @NotNull final RelativePoint point,
                                   final TooltipRenderer tooltipObject,
                                   final boolean alignToRight,
                                   @NotNull final TooltipGroup group,
                                   @NotNull 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);
    }
  }
}
项目:intellij-ce-playground    文件:TooltipController.java   
private void hideCurrentTooltip() {
  if (myCurrentTooltip != null) {
    LightweightHint currentTooltip = myCurrentTooltip;
    myCurrentTooltip = null;
    currentTooltip.hide();
    myCurrentTooltipGroup = null;
    IdeTooltipManager.getInstance().hide(null);
  }
}
项目:intellij-ce-playground    文件:EditorFragmentComponent.java   
@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 + JBUI.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);
}
项目:intellij-ce-playground    文件:LineTooltipRenderer.java   
private void expand(@NotNull LightweightHint hint,
                    @NotNull Editor editor,
                    @NotNull Point p,
                    @NotNull JEditorPane pane,
                    boolean alignToRight,
                    @NotNull TooltipGroup group,
                    @NotNull HintHint hintHint) {
  hint.hide();
  if (myCurrentWidth > 0) {
    stripDescription();
  }
  TooltipController.getInstance().showTooltip(editor, new Point(p.x - 3, p.y - 3),
                                              createRenderer(myText, myCurrentWidth > 0 ? 0 : pane.getWidth()), alignToRight, group,
                                              hintHint);
}
项目:intellij-ce-playground    文件:SelectUnselectOccurrenceActionsTest.java   
@Override
public void setUp() throws Exception {
  super.setUp();
  EditorHintListener listener = new EditorHintListener() {
    @Override
    public void hintShown(Project project, LightweightHint hint, int flags) {
      hintCount++;
    }
  };
  ApplicationManager.getApplication().getMessageBus().connect(myTestRootDisposable).subscribe(EditorHintListener.TOPIC, listener);
}
项目:intellij-ce-playground    文件:ShowParameterInfoContext.java   
@Override
@NotNull
public Pair<Point, Short> getBestPointPosition(LightweightHint hint,
                                               final PsiElement list,
                                               int offset,
                                               final boolean awtTooltip,
                                               short preferredPosition) {
  final TextRange textRange = list.getTextRange();
  offset = textRange.contains(offset) ? offset:textRange.getStartOffset() + 1;
  if (previousOffset == offset) return Pair.create(previousBestPoint, previousBestPosition);

  String listText = list.getText();
  final boolean isMultiline = listText.indexOf('\n') >= 0 || listText.indexOf('\r') >= 0;
  final LogicalPosition pos = myEditor.offsetToLogicalPosition(offset);
  Pair<Point, Short> position;

  if (!isMultiline) {
    position = chooseBestHintPosition(myEditor.getProject(), myEditor, pos.line, pos.column, hint, awtTooltip, preferredPosition);
  }
  else {
    Point p = HintManagerImpl.getHintPosition(hint, myEditor, pos, HintManager.ABOVE);
    position = new Pair<Point, Short>(p, HintManager.ABOVE);
  }
  previousBestPoint = position.getFirst();
  previousBestPosition = position.getSecond();
  previousOffset = offset;
  return position;
}
项目:intellij-ce-playground    文件:CompletionProgressIndicator.java   
private static LightweightHint showErrorHint(Project project, Editor editor, String text) {
  final LightweightHint[] result = {null};
  final EditorHintListener listener = new EditorHintListener() {
    @Override
    public void hintShown(final Project project, final LightweightHint hint, final int flags) {
      result[0] = hint;
    }
  };
  final MessageBusConnection connection = project.getMessageBus().connect();
  connection.subscribe(EditorHintListener.TOPIC, listener);
  assert text != null;
  HintManager.getInstance().showErrorHint(editor, text, HintManager.UNDER);
  connection.disconnect();
  return result[0];
}
项目:intellij-ce-playground    文件:BraceHighlightingHandler.java   
private void showScopeHint(final int lbraceStart, final int lbraceEnd) {
  LogicalPosition bracePosition = myEditor.offsetToLogicalPosition(lbraceStart);
  Point braceLocation = myEditor.logicalPositionToXY(bracePosition);
  final int y = braceLocation.y;
  myAlarm.addRequest(
      new Runnable() {
        @Override
        public void run() {
          if (!myEditor.getComponent().isShowing()) return;
          Rectangle viewRect = myEditor.getScrollingModel().getVisibleArea();
          if (y < viewRect.y) {
            int start = lbraceStart;
            if (!(myPsiFile instanceof PsiPlainTextFile) && myPsiFile.isValid()) {
              PsiDocumentManager.getInstance(myProject).commitAllDocuments();
              start = BraceMatchingUtil.getBraceMatcher(getFileTypeByOffset(lbraceStart), PsiUtilCore
                .getLanguageAtOffset(myPsiFile, lbraceStart)).getCodeConstructStart(myPsiFile, lbraceStart);
            }
            TextRange range = new TextRange(start, lbraceEnd);
            int line1 = myDocument.getLineNumber(range.getStartOffset());
            int line2 = myDocument.getLineNumber(range.getEndOffset());
            line1 = Math.max(line1, line2 - 5);
            range = new TextRange(myDocument.getLineStartOffset(line1), range.getEndOffset());
            LightweightHint hint = EditorFragmentComponent.showEditorFragmentHint(myEditor, range, true, true);
            myEditor.putUserData(HINT_IN_EDITOR_KEY, hint);
          }
        }
      },
      300, ModalityState.stateForComponent(myEditor.getComponent()));
}
项目:intellij-ce-playground    文件:BraceHighlightingHandler.java   
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);
  }
}
项目:intellij-ce-playground    文件:CtrlMouseHandler.java   
@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());
}
项目:intellij-ce-playground    文件:CtrlMouseHandler.java   
public void showHint(@NotNull LightweightHint hint) {
  final HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl();
  Point p = HintManagerImpl.getHintPosition(hint, myEditor, myPosition, HintManager.ABOVE);
  hintManager.showEditorHint(hint, myEditor, p,
                             HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING,
                             0, false, HintManagerImpl.createHintHint(myEditor, p,  hint, HintManager.ABOVE).setContentActive(false));
}
项目:intellij-ce-playground    文件:FileInEditorProcessor.java   
public static void showHint(@NotNull Editor editor, @NotNull 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);
}
项目:intellij-ce-playground    文件:CodeInsightUtilBase.java   
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);
}
项目:intellij-ce-playground    文件:ElementPreviewHintProvider.java   
@Override
public void show(@NotNull PsiElement element, @NotNull Editor editor, @NotNull 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);
}
项目:intellij-ce-playground    文件:SelectOccurrencesActionHandler.java   
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);
}
项目:intellij-ce-playground    文件:FindUsagesManager.java   
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);
}
项目:intellij-ce-playground    文件:QuickFixManager.java   
/**
 * Shows intention hint (light bulb) if it's not visible yet.
 */
final void showIntentionHint(){
  if(!myComponent.isShowing() || !IJSwingUtilities.hasFocus(myComponent)){
    hideIntentionHint();
    return;
  }

  // 1. Hide previous hint (if any)
  hideIntentionHint();

  // 2. Found error (if any)
  final ErrorInfo[] errorInfos = getErrorInfos();
  if(!haveFixes(errorInfos)) {
    hideIntentionHint();
    return;
  }

  // 3. Determine position where this hint should be shown
  final Rectangle bounds = getErrorBounds();
  if(bounds == null){
    return;
  }

  // 4. Show light bulb to fix this error
  final LightBulbComponentImpl lightBulbComponent = new LightBulbComponentImpl(this, AllIcons.Actions.IntentionBulb);
  myHint = new LightweightHint(lightBulbComponent);
  myLastHintBounds = bounds;
  myHint.show(myComponent, bounds.x - AllIcons.Actions.IntentionBulb.getIconWidth() - 4, bounds.y, myComponent, new HintHint(myComponent, bounds.getLocation()));
}