Java Code Examples for com.intellij.codeInsight.highlighting.HighlightManager#addRangeHighlight()

The following examples show how to use com.intellij.codeInsight.highlighting.HighlightManager#addRangeHighlight() . 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: FlowInPlaceRenamer.java    From mule-intellij-plugins with Apache License 2.0 6 votes vote down vote up
private static void addHighlights(List<TextRange> ranges, Editor editor, ArrayList<RangeHighlighter> highlighters) {
    EditorColorsManager colorsManager = EditorColorsManager.getInstance();
    TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.WRITE_SEARCH_RESULT_ATTRIBUTES);
    HighlightManager highlightManager = HighlightManager.getInstance(editor.getProject());
    Iterator iterator = ranges.iterator();

    while (iterator.hasNext()) {
        TextRange range = (TextRange) iterator.next();
        //highlightManager.addOccurrenceHighlight(editor, range.getStartOffset() + 1, range.getEndOffset() - 1, attributes, 0, highlighters, (Color) null);
        highlightManager.addRangeHighlight(editor, range.getStartOffset() + 1, range.getEndOffset() - 1, attributes, false, highlighters);
    }

    iterator = highlighters.iterator();

    while (iterator.hasNext()) {
        RangeHighlighter highlighter = (RangeHighlighter) iterator.next();
        highlighter.setGreedyToLeft(true);
        highlighter.setGreedyToRight(true);
    }

}
 
Example 2
Source File: CallerChooserBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void updateEditorTexts(final MethodNodeBase<M> node) {
  final MethodNodeBase<M> parentNode = (MethodNodeBase)node.getParent();
  final String callerText = node != myRoot ? getText(node.getMethod()) : "";
  final Document callerDocument = myCallerEditor.getDocument();
  final String calleeText = node != myRoot ? getText(parentNode.getMethod()) : "";
  final Document calleeDocument = myCalleeEditor.getDocument();

  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    @Override
    public void run() {
      callerDocument.setText(callerText);
      calleeDocument.setText(calleeText);
    }
  });

  final M caller = node.getMethod();
  final PsiElement callee = parentNode != null ? parentNode.getElementToSearch() : null;
  if (caller != null && caller.isPhysical() && callee != null) {
    HighlightManager highlighter = HighlightManager.getInstance(myProject);
    EditorColorsManager colorManager = EditorColorsManager.getInstance();
    TextAttributes attributes = colorManager.getGlobalScheme().getAttributes(EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES);
    int start = getStartOffset(caller);
    for (PsiElement element : findElementsToHighlight(caller, callee)) {
      highlighter.addRangeHighlight(myCallerEditor, element.getTextRange().getStartOffset() - start,
                                    element.getTextRange().getEndOffset() - start, attributes, false, null);
    }
  }
}
 
Example 3
Source File: InplaceChangeSignature.java    From consulo with Apache License 2.0 5 votes vote down vote up
public InplaceChangeSignature(Project project, Editor editor, @Nonnull PsiElement element) {
  myDocumentManager = PsiDocumentManager.getInstance(project);
  myProject = project;
  try {
    myMarkAction = StartMarkAction.start(editor, project, ChangeSignatureHandler.REFACTORING_NAME);
  }
  catch (StartMarkAction.AlreadyStartedException e) {
    final int exitCode = Messages.showYesNoDialog(myProject, e.getMessage(), ChangeSignatureHandler.REFACTORING_NAME, "Navigate to Started", "Cancel", Messages.getErrorIcon());
    if (exitCode == Messages.CANCEL) return;
    PsiElement method = myStableChange.getMethod();
    VirtualFile virtualFile = PsiUtilCore.getVirtualFile(method);
    new OpenFileDescriptor(project, virtualFile, method.getTextOffset()).navigate(true);
    return;
  }


  myEditor = editor;
  myDetector = LanguageChangeSignatureDetectors.INSTANCE.forLanguage(element.getLanguage());
  myStableChange = myDetector.createInitialChangeInfo(element);
  myInitialSignature = myDetector.extractSignature(myStableChange);
  myInitialName = DescriptiveNameUtil.getDescriptiveName(myStableChange.getMethod());
  TextRange highlightingRange = myDetector.getHighlightingRange(myStableChange);

  HighlightManager highlightManager = HighlightManager.getInstance(myProject);
  TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.LIVE_TEMPLATE_ATTRIBUTES);
  highlightManager.addRangeHighlight(editor, highlightingRange.getStartOffset(), highlightingRange.getEndOffset(), attributes, false, myHighlighters);
  for (RangeHighlighter highlighter : myHighlighters) {
    highlighter.setGreedyToRight(true);
    highlighter.setGreedyToLeft(true);
  }
  myEditor.getDocument().addDocumentListener(this);
  myEditor.putUserData(INPLACE_CHANGE_SIGNATURE, this);
  myPreview = InplaceRefactoring.createPreviewComponent(project, myDetector.getFileType());
  showBalloon();
}
 
Example 4
Source File: ExtractMethodHelper.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void highlightInEditor(@Nonnull final Project project, @Nonnull final SimpleMatch match,
                                      @Nonnull final Editor editor, Map<SimpleMatch, RangeHighlighter> highlighterMap) {
  final List<RangeHighlighter> highlighters = new ArrayList<>();
  final HighlightManager highlightManager = HighlightManager.getInstance(project);
  final EditorColorsManager colorsManager = EditorColorsManager.getInstance();
  final TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
  final int startOffset = match.getStartElement().getTextRange().getStartOffset();
  final int endOffset = match.getEndElement().getTextRange().getEndOffset();
  highlightManager.addRangeHighlight(editor, startOffset, endOffset, attributes, true, highlighters);
  highlighterMap.put(match, highlighters.get(0));
  final LogicalPosition logicalPosition = editor.offsetToLogicalPosition(startOffset);
  editor.getScrollingModel().scrollTo(logicalPosition, ScrollType.MAKE_VISIBLE);
}
 
Example 5
Source File: ExtractIncludeFileBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void highlightInEditor(final Project project, final IncludeDuplicate pair, final Editor editor) {
  final HighlightManager highlightManager = HighlightManager.getInstance(project);
  EditorColorsManager colorsManager = EditorColorsManager.getInstance();
  TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
  final int startOffset = pair.getStart().getTextRange().getStartOffset();
  final int endOffset = pair.getEnd().getTextRange().getEndOffset();
  highlightManager.addRangeHighlight(editor, startOffset, endOffset, attributes, true, null);
  final LogicalPosition logicalPosition = editor.offsetToLogicalPosition(startOffset);
  editor.getScrollingModel().scrollTo(logicalPosition, ScrollType.MAKE_VISIBLE);
}