Java 类com.intellij.openapi.editor.markup.HighlighterLayer 实例源码

项目:MultiHighlight    文件:ColorPreviewPanel.java   
private void highlightLine(int index, NamedTextAttr namedTextAttr) {
    UIUtil.invokeAndWaitIfNeeded((Runnable) () -> {
        try {
            MarkupModelEx markupModel = myEditor.getMarkupModel();
            final Document doc = markupModel.getDocument();
            final int lineStartOffset = doc.getLineStartOffset(index);
            final int lineEndOffset = doc.getLineEndOffset(index);
            // IDEA-53203: add ERASE_MARKER for manually defined attributes
            markupModel.addRangeHighlighter(lineStartOffset, lineEndOffset,
                    HighlighterLayer.SELECTION - 1, TextAttributes.ERASE_MARKER,
                    HighlighterTargetArea.EXACT_RANGE);
            RangeHighlighter rangeHighlight =
                    markupModel.addRangeHighlighter(lineStartOffset, lineEndOffset,
                            HighlighterLayer.SELECTION - 1, namedTextAttr,
                            HighlighterTargetArea.EXACT_RANGE);
            rangeHighlight.setErrorStripeMarkColor(namedTextAttr.getErrorStripeColor());
            rangeHighlight.setErrorStripeTooltip(namedTextAttr.getName());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    });
}
项目:MultiHighlight    文件:MultiHighlightClearAction.java   
@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR);

    final HighlightManager highlightManager = HighlightManager.getInstance(project);
    final RangeHighlighter[] highlighters =
            ((HighlightManagerImpl) highlightManager).getHighlighters(editor);
    for (RangeHighlighter highlighter : highlighters) {
        final TextAttributes ta = highlighter.getTextAttributes();
        if (ta != null && ta instanceof NamedTextAttr
                && highlighter.getLayer() == HighlighterLayer.SELECTION - 1) {
            highlightManager.removeSegmentHighlighter(editor, highlighter);
        }
    }
}
项目:samebug-idea-plugin    文件:ConsoleWatcher.java   
private RangeHighlighter addMarkerAtOffset(int offset, SearchMark mark) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    final Document document = editor.getDocument();

    if (0 <= offset && offset < document.getTextLength()) {
        editor.getSettings().setLineMarkerAreaShown(true);
        final int line = document.getLineNumber(offset);
        final MarkupModel markupModel = editor.getMarkupModel();

        RangeHighlighter highlighter;
        highlighter = markupModel.addLineHighlighter(line, HighlighterLayer.ADDITIONAL_SYNTAX, null);
        highlighter.setGutterIconRenderer(mark);
        return highlighter;
    } else {
        return null;
    }
}
项目:intellij-ce-playground    文件:IterationStateTest.java   
public void testColumnModeSelectionWithCurrentBreakpointHighlighting() {
  init("line1\n" +
       "line2");
  setColumnModeOn();

  Color breakpointColor = Color.RED;
  myFixture.getEditor().getMarkupModel().addLineHighlighter(0,
                                                            HighlighterLayer.CARET_ROW + 1,
                                                            new TextAttributes(null, breakpointColor, null, null, 0));
  Color currentDebuggingLineColor = Color.CYAN;
  myFixture.getEditor().getMarkupModel().addLineHighlighter(0,
                                                            HighlighterLayer.SELECTION - 1,
                                                            new TextAttributes(null, currentDebuggingLineColor, null, null, 0));

  mouse().clickAt(0, 4).dragTo(0, 6).release();
  verifySplitting(false,
                  new Segment(0, 4, currentDebuggingLineColor),
                  new Segment(4, 5, SELECTION_BACKGROUND),
                  new Segment(5, 6, currentDebuggingLineColor).plus(1, SELECTION_BACKGROUND),
                  new Segment(6, 11, DEFAULT_BACKGROUND));
}
项目:intellij-ce-playground    文件:IterationStateTest.java   
public void testLinesInRange() {
  init("     line1\n" +
       "     line2");

  Color breakpointColor = Color.RED;
  myFixture.getEditor().getMarkupModel().addLineHighlighter(0,
                                                            HighlighterLayer.CARET_ROW + 1,
                                                            new TextAttributes(null, breakpointColor, null, null, 0));

  verifySplitting(false,
                  new Segment(0, 5, breakpointColor),
                  new Segment(5, 10, breakpointColor),
                  new Segment(10, 11, breakpointColor),
                  new Segment(11, 16, DEFAULT_BACKGROUND),
                  new Segment(16, 21, DEFAULT_BACKGROUND));
}
项目:intellij-ce-playground    文件:CtrlMouseHandler.java   
@NotNull
private HighlightersSet installHighlighterSet(@NotNull Info info, @NotNull Editor editor) {
  final JComponent internalComponent = editor.getContentComponent();
  internalComponent.addKeyListener(myEditorKeyListener);
  editor.getScrollingModel().addVisibleAreaListener(myVisibleAreaListener);
  final Cursor cursor = internalComponent.getCursor();
  internalComponent.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
  myFileEditorManager.addFileEditorManagerListener(myFileEditorManagerListener);

  List<RangeHighlighter> highlighters = new ArrayList<RangeHighlighter>();
  TextAttributes attributes = myEditorColorsManager.getGlobalScheme().getAttributes(EditorColors.REFERENCE_HYPERLINK_COLOR);
  for (TextRange range : info.getRanges()) {
    TextAttributes attr = NavigationUtil.patchAttributesColor(attributes, range, editor);
    final RangeHighlighter highlighter = editor.getMarkupModel().addRangeHighlighter(range.getStartOffset(), range.getEndOffset(),
                                                                                     HighlighterLayer.SELECTION + 1,
                                                                                     attr,
                                                                                     HighlighterTargetArea.EXACT_RANGE);
    highlighters.add(highlighter);
  }

  return new HighlightersSet(highlighters, editor, cursor, info);
}
项目:jetbrains-plugin-st4    文件:SyntaxHighlighter.java   
protected void syntaxError(String annotation, Token offendingToken) {
//      Annotation annot = new Annotation(20, 30, HighlightSeverity.ERROR, "Test!", "Test Message!");
//      HighlightInfo info = HighlightInfo.fromAnnotation(annot);
//      List<HighlightInfo> al = new ArrayList<HighlightInfo>();
//      al.add(info);
//      UpdateHighlightersUtil.setHighlightersToEditor(project, doc, 20, 30, al, null, 0)

        final TextAttributes attr = new TextAttributes();
        attr.setForegroundColor(JBColor.RED);
        attr.setEffectColor(JBColor.RED);
        attr.setEffectType(EffectType.WAVE_UNDERSCORE);
        MarkupModel markupModel = editor.getMarkupModel();
        RangeHighlighter h =
            markupModel.addRangeHighlighter(startIndex+offendingToken.getStartIndex(),
                                            startIndex+offendingToken.getStopIndex()+1,
                                            HighlighterLayer.ERROR, // layer
                                            attr,
                                            HighlighterTargetArea.EXACT_RANGE);
        h.putUserData(SYNTAX_HIGHLIGHTING_TAG, offendingToken); // store any non-null value to tag it
    }
项目:tools-idea    文件:CtrlMouseHandler.java   
private HighlightersSet installHighlighterSet(Info info, Editor editor) {
  final JComponent internalComponent = editor.getContentComponent();
  internalComponent.addKeyListener(myEditorKeyListener);
  editor.getScrollingModel().addVisibleAreaListener(myVisibleAreaListener);
  final Cursor cursor = internalComponent.getCursor();
  internalComponent.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
  myFileEditorManager.addFileEditorManagerListener(myFileEditorManagerListener);

  List<RangeHighlighter> highlighters = new ArrayList<RangeHighlighter>();
  TextAttributes attributes = myEditorColorsManager.getGlobalScheme().getAttributes(EditorColors.REFERENCE_HYPERLINK_COLOR);
  for (TextRange range : info.getRanges()) {
    final RangeHighlighter highlighter = editor.getMarkupModel().addRangeHighlighter(range.getStartOffset(), range.getEndOffset(),
                                                                                     HighlighterLayer.SELECTION + 1,
                                                                                     attributes,
                                                                                     HighlighterTargetArea.EXACT_RANGE);
    highlighters.add(highlighter);
  }

  return new HighlightersSet(highlighters, editor, cursor, info);
}
项目:tools-idea    文件:Bookmark.java   
public RangeHighlighter createHighlighter(@NotNull MarkupModelEx markup) {
  final RangeHighlighter myHighlighter;
  int line = getLine();
  if (line >= 0) {
    myHighlighter = markup.addPersistentLineHighlighter(line, HighlighterLayer.ERROR + 1, null);
    if (myHighlighter != null) {
      myHighlighter.setGutterIconRenderer(new MyGutterIconRenderer(this));

      myHighlighter.setErrorStripeMarkColor(Color.black);
      myHighlighter.setErrorStripeTooltip(getBookmarkTooltip());
    }
  }
  else {
    myHighlighter = null;
  }
  return myHighlighter;
}
项目:intellij-plugin-v4    文件:ProfilerPanel.java   
public Token addDecisionEventHighlighter(PreviewState previewState, MarkupModel markupModel,
                                         DecisionEventInfo info, Color errorStripeColor,
                                         EffectType effectType) {
    TokenStream tokens = previewState.parsingResult.parser.getInputStream();
    Token startToken = tokens.get(info.startIndex);
    Token stopToken = tokens.get(info.stopIndex);
    TextAttributes textAttributes =
        new TextAttributes(JBColor.BLACK, JBColor.WHITE, errorStripeColor,
                           effectType, Font.PLAIN);
    textAttributes.setErrorStripeColor(errorStripeColor);
    final RangeHighlighter rangeHighlighter =
        markupModel.addRangeHighlighter(
            startToken.getStartIndex(), stopToken.getStopIndex()+1,
            HighlighterLayer.ADDITIONAL_SYNTAX, textAttributes,
            HighlighterTargetArea.EXACT_RANGE);
    rangeHighlighter.putUserData(DECISION_EVENT_INFO_KEY, info);
    rangeHighlighter.setErrorStripeMarkColor(errorStripeColor);
    return startToken;
}
项目:Crucible4IDEA    文件:CommentsDiffTool.java   
private static void addGutter(@NotNull Editor editor2,
                              @NotNull final Review review,
                              @NotNull FilePath filePath,
                              @Nullable final ContentRevision revision) {
  if (revision == null) return;

  for (Comment comment : review.getComments()) {
    final String id = comment.getReviewItemId();
    final String path = review.getPathById(id);
    if (path != null && filePath.getPath().endsWith(path) &&
        (review.isInPatch(comment) || revision.getRevisionNumber().asString().equals(comment.getRevision()))) {

      int line = Integer.parseInt(comment.getLine()) - 1;
      final RangeHighlighter highlighter = editor2.getMarkupModel().addLineHighlighter(line, HighlighterLayer.ERROR + 1, null);
      final ReviewGutterIconRenderer gutterIconRenderer = new ReviewGutterIconRenderer(review, filePath, comment);
      highlighter.setGutterIconRenderer(gutterIconRenderer);
    }
  }
}
项目:consulo    文件:ApplyPatchChange.java   
private void createStatusHighlighter() {
  int line1 = myPatchDeletionRange.start;
  int line2 = myPatchInsertionRange.end;

  Color color = getStatusColor();
  if (isResolved()) {
    color = ColorUtil.mix(color, myViewer.getPatchEditor().getGutterComponentEx().getBackground(), 0.6f);
  }

  String tooltip = getStatusText();

  EditorEx patchEditor = myViewer.getPatchEditor();
  Document document = patchEditor.getDocument();
  MarkupModelEx markupModel = patchEditor.getMarkupModel();
  TextRange textRange = DiffUtil.getLinesRange(document, line1, line2);

  RangeHighlighter highlighter = markupModel.addRangeHighlighter(textRange.getStartOffset(), textRange.getEndOffset(),
                                                                 HighlighterLayer.LAST, null, HighlighterTargetArea.LINES_IN_RANGE);

  PairConsumer<Editor, MouseEvent> clickHandler = getResultRange() != null ?
                                                  (e, event) -> myViewer.scrollToChange(this, Side.RIGHT, false) :
                                                  null;
  highlighter.setLineMarkerRenderer(LineStatusMarkerRenderer.createRenderer(line1, line2, color, tooltip, clickHandler));

  myHighlighters.add(highlighter);
}
项目:consulo    文件:ApplyPatchChange.java   
@Nullable
private MyGutterOperation createOperation(@Nonnull OperationType type) {
  if (isResolved()) return null;

  EditorEx editor = myViewer.getPatchEditor();
  Document document = editor.getDocument();

  int line = getPatchRange().start;
  int offset = line == DiffUtil.getLineCount(document) ? document.getTextLength() : document.getLineStartOffset(line);

  RangeHighlighter highlighter = editor.getMarkupModel().addRangeHighlighter(offset, offset,
                                                                             HighlighterLayer.ADDITIONAL_SYNTAX,
                                                                             null,
                                                                             HighlighterTargetArea.LINES_IN_RANGE);
  return new MyGutterOperation(highlighter, type);
}
项目:consulo    文件:CtrlMouseHandler.java   
@Nonnull
private HighlightersSet installHighlighterSet(@Nonnull Info info, @Nonnull Editor editor) {
  final JComponent internalComponent = editor.getContentComponent();
  internalComponent.addKeyListener(myEditorKeyListener);
  editor.getScrollingModel().addVisibleAreaListener(myVisibleAreaListener);
  final Cursor cursor = internalComponent.getCursor();
  internalComponent.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
  myFileEditorManager.addFileEditorManagerListener(myFileEditorManagerListener);

  List<RangeHighlighter> highlighters = new ArrayList<RangeHighlighter>();
  TextAttributes attributes = myEditorColorsManager.getGlobalScheme().getAttributes(EditorColors.REFERENCE_HYPERLINK_COLOR);
  for (TextRange range : info.getRanges()) {
    TextAttributes attr = NavigationUtil.patchAttributesColor(attributes, range, editor);
    final RangeHighlighter highlighter =
            editor.getMarkupModel().addRangeHighlighter(range.getStartOffset(), range.getEndOffset(), HighlighterLayer.SELECTION + 1, attr, HighlighterTargetArea.EXACT_RANGE);
    highlighters.add(highlighter);
  }

  return new HighlightersSet(highlighters, editor, cursor, info);
}
项目:MultiHighlight    文件:MultiHighlightHandler.java   
private static void clearHighlights(Editor editor, HighlightManager highlightManager,
        List<TextRange> toRemoves) {
    if (editor instanceof EditorWindow) {
        editor = ((EditorWindow) editor).getDelegate();
    }

    RangeHighlighter[] highlighters =
            ((HighlightManagerImpl) highlightManager).getHighlighters(editor);

    Arrays.sort(highlighters, (o1, o2) -> o1.getStartOffset() - o2.getStartOffset());
    Collections.sort(toRemoves, (o1, o2) -> o1.getStartOffset() - o2.getStartOffset());

    int i = 0;
    int j = 0;
    while (i < highlighters.length && j < toRemoves.size()) {
        RangeHighlighter highlighter = highlighters[i];
        final TextAttributes ta = highlighter.getTextAttributes();
        final TextRange textRange = TextRange.create(highlighter);
        final TextRange toRemove = toRemoves.get(j);
        if (ta != null && ta instanceof NamedTextAttr // wrap
                && highlighter.getLayer() == HighlighterLayer.SELECTION - 1 // wrap
                && toRemove.equals(textRange)) {
            highlightManager.removeSegmentHighlighter(editor, highlighter);
            i++;
        } else if (toRemove.getStartOffset() > textRange.getEndOffset()) {
            i++;
        } else if (toRemove.getEndOffset() < textRange.getStartOffset()) {
            j++;
        } else {
            i++;
            j++;
        }
    }
}
项目:intellij-ce-playground    文件:NumberedFragmentHighlighter.java   
public void addRangeHighlighter(final boolean left, int start, int end, final TextAttributes attributes) {
  if (left) {
    myAppender1.getEditor().getMarkupModel().addRangeHighlighter(start, end, HighlighterLayer.SELECTION - 3, attributes,
                                                                 HighlighterTargetArea.EXACT_RANGE);
  } else {
    myAppender2.getEditor().getMarkupModel().addRangeHighlighter(start, end, HighlighterLayer.SELECTION - 3, attributes,
                                                                       HighlighterTargetArea.EXACT_RANGE);
  }
}
项目:intellij-ce-playground    文件:IterationState.java   
@Nullable
public Color getPastFileEndBackground() {
  boolean isInCaretRow = myEditor.getCaretModel().getLogicalPosition().line >= myDocument.getLineCount() - 1;

  Color caret = isInCaretRow && myCaretRowAttributes != null ? myCaretRowAttributes.getBackgroundColor() : null;

  ContainerUtil.quickSort(myCurrentHighlighters, LayerComparator.INSTANCE);

  //noinspection ForLoopReplaceableByForEach
  for (int i = 0; i < myCurrentHighlighters.size(); i++) {
    RangeHighlighterEx highlighter = myCurrentHighlighters.get(i);
    if (caret != null && highlighter.getLayer() < HighlighterLayer.CARET_ROW) {
      return caret;
    }

    if (highlighter.getTargetArea() != HighlighterTargetArea.LINES_IN_RANGE
        || myDocument.getLineNumber(highlighter.getEndOffset()) < myDocument.getLineCount() - 1) {
      continue;
    }

    TextAttributes textAttributes = highlighter.getTextAttributes();
    if (textAttributes != null) {
      Color backgroundColor = textAttributes.getBackgroundColor();
      if (backgroundColor != null) return backgroundColor;
    }
  }

  return caret;
}
项目:intellij-ce-playground    文件:EditorTextFieldCellRenderer.java   
protected void setTextToEditor(String text) {
  myEditor.getMarkupModel().removeAllHighlighters();
  myEditor.getDocument().setText(text);
  myEditor.getHighlighter().setText(text);
  if (myTextAttributes != null) {
    myEditor.getMarkupModel().addRangeHighlighter(0, myEditor.getDocument().getTextLength(),
                                                  HighlighterLayer.ADDITIONAL_SYNTAX, myTextAttributes, HighlighterTargetArea.EXACT_RANGE);
  }

  ((EditorImpl)myEditor).resetSizes();

  ((EditorImpl)myEditor).setPaintSelection(mySelected);
  SelectionModel selectionModel = myEditor.getSelectionModel();
  selectionModel.setSelection(0, mySelected ? myEditor.getDocument().getTextLength() : 0);
}
项目:intellij-ce-playground    文件:ReplacementPreviewDialog.java   
private void hilight(VirtualFile file,int start, int end) {
  removeHilighter();

  editor = FileEditorManager.getInstance(project).openTextEditor(
    new OpenFileDescriptor(project, file),
    false
  );
  hilighter = editor.getMarkupModel().addRangeHighlighter(
    start,
    end,
    HighlighterLayer.SELECTION - 100,
    EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES),
    HighlighterTargetArea.EXACT_RANGE
  );
}
项目:intellij-ce-playground    文件:AbstractValueHint.java   
public void invokeHint(Runnable hideRunnable) {
  myHideRunnable = hideRunnable;

  if (!canShowHint()) {
    hideHint();
    return;
  }

  if (myType == ValueHintType.MOUSE_ALT_OVER_HINT) {
    EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
    TextAttributes attributes = scheme.getAttributes(EditorColors.REFERENCE_HYPERLINK_COLOR);
    attributes = NavigationUtil.patchAttributesColor(attributes, myCurrentRange, myEditor);

    myHighlighter = myEditor.getMarkupModel().addRangeHighlighter(myCurrentRange.getStartOffset(), myCurrentRange.getEndOffset(),
                                                                  HighlighterLayer.SELECTION + 1, attributes,
                                                                  HighlighterTargetArea.EXACT_RANGE);
    Component internalComponent = myEditor.getContentComponent();
    myStoredCursor = internalComponent.getCursor();
    internalComponent.addKeyListener(myEditorKeyListener);
    internalComponent.setCursor(hintCursor());
    if (LOG.isDebugEnabled()) {
      LOG.debug("internalComponent.setCursor(hintCursor())");
    }
  }
  else {
    evaluateAndShowHint();
  }
}
项目:intellij-ce-playground    文件:TemplateState.java   
private RangeHighlighter getSegmentHighlighter(int segmentNumber, boolean isSelected, boolean isEnd) {
  final TextAttributes lvAttr = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.LIVE_TEMPLATE_ATTRIBUTES);
  TextAttributes attributes = isSelected ? lvAttr : new TextAttributes();
  TextAttributes endAttributes = new TextAttributes();

  int start = mySegments.getSegmentStart(segmentNumber);
  int end = mySegments.getSegmentEnd(segmentNumber);
  RangeHighlighter segmentHighlighter = myEditor.getMarkupModel()
    .addRangeHighlighter(start, end, HighlighterLayer.LAST + 1, isEnd ? endAttributes : attributes, HighlighterTargetArea.EXACT_RANGE);
  segmentHighlighter.setGreedyToLeft(true);
  segmentHighlighter.setGreedyToRight(true);
  return segmentHighlighter;
}
项目:intellij-ce-playground    文件:HighlightData.java   
public void addHighlToView(final Editor view, EditorColorsScheme scheme, final Map<TextAttributesKey,String> displayText) {

    // XXX: Hack
    if (HighlighterColors.BAD_CHARACTER.equals(myHighlightType)) {
      return;
    }

    final TextAttributes attr = scheme.getAttributes(myHighlightType);
    if (attr != null) {
      UIUtil.invokeAndWaitIfNeeded(new Runnable() {
        @Override
        public void run() {
          try {
            // IDEA-53203: add ERASE_MARKER for manually defined attributes
            view.getMarkupModel().addRangeHighlighter(myStartOffset, myEndOffset, HighlighterLayer.ADDITIONAL_SYNTAX,
                                                      TextAttributes.ERASE_MARKER, HighlighterTargetArea.EXACT_RANGE);
            RangeHighlighter highlighter = view.getMarkupModel()
              .addRangeHighlighter(myStartOffset, myEndOffset, HighlighterLayer.ADDITIONAL_SYNTAX, attr,
                                   HighlighterTargetArea.EXACT_RANGE);
            final Color errorStripeColor = attr.getErrorStripeColor();
            highlighter.setErrorStripeMarkColor(errorStripeColor);
            final String tooltip = displayText.get(myHighlightType);
            highlighter.setErrorStripeTooltip(tooltip);
          }
          catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
      });
    }
  }
项目:intellij-ce-playground    文件:LanguageConsoleBuilder.java   
private void addLineSeparatorPainterIfNeed() {
  if (lineSeparatorPainter != null) {
    return;
  }

  RangeHighlighter highlighter = getHistoryViewer().getMarkupModel().addRangeHighlighter(0, getDocument().getTextLength(), HighlighterLayer.ADDITIONAL_SYNTAX, null, HighlighterTargetArea.EXACT_RANGE);
  highlighter.setGreedyToRight(true);
  highlighter.setCustomRenderer(renderer);
  lineSeparatorPainter = highlighter;
}
项目:review-board-idea-plugin    文件:CommentsDiffTool.java   
private void updateHighLights(Editor editor) {
    MarkupModel markup = editor.getMarkupModel();

    for (RangeHighlighter customRangeHighlighter : newCommentHighlighters) {
        markup.removeHighlighter(customRangeHighlighter);
    }
    newCommentHighlighters.clear();

    int lineCount = markup.getDocument().getLineCount();

    Map<Integer, List<Comment>> lineComments = lineComments(comments);
    for (Map.Entry<Integer, List<Comment>> entry : lineComments.entrySet()) {
        if (entry.getKey() > lineCount) continue;

        boolean hasNewComments = false;
        for (Comment comment : entry.getValue()) {
            if (comment.id == null) {
                hasNewComments = true;
                break;
            }
        }

        TextAttributes attributes = new TextAttributes();
        if (hasNewComments) attributes.setBackgroundColor(JBColor.PINK);
        else attributes.setBackgroundColor(JBColor.YELLOW);

        RangeHighlighter rangeHighlighter = markup
                .addLineHighlighter(entry.getKey() - 1, HighlighterLayer.SELECTION + (hasNewComments ? 2 : 1), attributes);
        rangeHighlighter.setGutterIconRenderer(new CommentGutterIconRenderer());
        newCommentHighlighters.add(rangeHighlighter);
    }
}
项目:jetbrains-plugin-st4    文件:SyntaxHighlighter.java   
protected void highlightToken(Token t, TextAttributesKey[] keys) {
    MarkupModel markupModel = getEditor().getMarkupModel();
    EditorColorsScheme scheme = editorColorsManager.getGlobalScheme();
    TextAttributes attr = merge(scheme, keys);
    RangeHighlighter h =
        markupModel.addRangeHighlighter(
            startIndex+t.getStartIndex(),
            startIndex+t.getStopIndex()+1,
            HighlighterLayer.SYNTAX, // layer
            attr,
            HighlighterTargetArea.EXACT_RANGE);
    h.putUserData(SYNTAX_HIGHLIGHTING_TAG, t); // store any non-null value to tag it
}
项目:tools-idea    文件:TemplateState.java   
private RangeHighlighter getSegmentHighlighter(int segmentNumber, boolean isSelected, boolean isEnd) {
  final TextAttributes lvAttr = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.LIVE_TEMPLATE_ATTRIBUTES);
  TextAttributes attributes = isSelected ? lvAttr : new TextAttributes();
  TextAttributes endAttributes = new TextAttributes();

  int start = mySegments.getSegmentStart(segmentNumber);
  int end = mySegments.getSegmentEnd(segmentNumber);
  RangeHighlighter segmentHighlighter = myEditor.getMarkupModel()
    .addRangeHighlighter(start, end, HighlighterLayer.LAST + 1, isEnd ? endAttributes : attributes, HighlighterTargetArea.EXACT_RANGE);
  segmentHighlighter.setGreedyToLeft(true);
  segmentHighlighter.setGreedyToRight(true);
  return segmentHighlighter;
}
项目:tools-idea    文件:HighlightData.java   
public void addHighlToView(final Editor view, EditorColorsScheme scheme, final Map<TextAttributesKey,String> displayText) {

    // XXX: Hack
    if (HighlighterColors.BAD_CHARACTER.equals(myHighlightType)) {
      return;
    }

    final TextAttributes attr = scheme.getAttributes(myHighlightType);
    if (attr != null) {
      UIUtil.invokeAndWaitIfNeeded(new Runnable() {
        @Override
        public void run() {
          try {
            // IDEA-53203: add ERASE_MARKER for manually defined attributes
            view.getMarkupModel().addRangeHighlighter(myStartOffset, myEndOffset, HighlighterLayer.ADDITIONAL_SYNTAX,
                                                      TextAttributes.ERASE_MARKER, HighlighterTargetArea.EXACT_RANGE);
            RangeHighlighter highlighter = view.getMarkupModel()
              .addRangeHighlighter(myStartOffset, myEndOffset, HighlighterLayer.ADDITIONAL_SYNTAX, attr,
                                   HighlighterTargetArea.EXACT_RANGE);
            final Color errorStripeColor = attr.getErrorStripeColor();
            highlighter.setErrorStripeMarkColor(errorStripeColor);
            final String tooltip = displayText.get(myHighlightType);
            highlighter.setErrorStripeTooltip(tooltip);
          }
          catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
      });
    }
  }
项目:consulo    文件:TextMergeChange.java   
@Nullable
private MyGutterOperation createOperation(@Nonnull ThreeSide side, @Nonnull OperationType type) {
  if (isResolved(side)) return null;

  EditorEx editor = myViewer.getEditor(side);
  Document document = editor.getDocument();

  int line = getStartLine(side);
  int offset = line == DiffUtil.getLineCount(document) ? document.getTextLength() : document.getLineStartOffset(line);

  RangeHighlighter highlighter =
          editor.getMarkupModel().addRangeHighlighter(offset, offset, HighlighterLayer.ADDITIONAL_SYNTAX, null, HighlighterTargetArea.LINES_IN_RANGE);
  return new MyGutterOperation(side, highlighter, type);
}
项目:consulo    文件:UnifiedDiffChange.java   
@Nonnull
private MyGutterOperation createOperation(@Nonnull Side sourceSide) {
  int offset = myEditor.getDocument().getLineStartOffset(myLine1);
  RangeHighlighter highlighter = myEditor.getMarkupModel().addRangeHighlighter(offset, offset,
                                                                               HighlighterLayer.ADDITIONAL_SYNTAX,
                                                                               null,
                                                                               HighlighterTargetArea.LINES_IN_RANGE);
  return new MyGutterOperation(sourceSide, highlighter);
}
项目:consulo    文件:SimpleDiffChange.java   
@Nonnull
private MyGutterOperation createOperation(@Nonnull Side side) {
  int offset = side.getStartOffset(myFragment);
  EditorEx editor = myViewer.getEditor(side);
  RangeHighlighter highlighter = editor.getMarkupModel().addRangeHighlighter(offset, offset,
                                                                             HighlighterLayer.ADDITIONAL_SYNTAX,
                                                                             null,
                                                                             HighlighterTargetArea.LINES_IN_RANGE);
  return new MyGutterOperation(side, highlighter);
}
项目:consulo    文件:EditorTextFieldCellRenderer.java   
protected void setTextToEditor(String text) {
  myEditor.getMarkupModel().removeAllHighlighters();
  myEditor.getDocument().setText(text);
  ((EditorImpl)myEditor).resetSizes();
  myEditor.getHighlighter().setText(text);
  if (myTextAttributes != null) {
    myEditor.getMarkupModel().addRangeHighlighter(0, myEditor.getDocument().getTextLength(), HighlighterLayer.ADDITIONAL_SYNTAX, myTextAttributes, HighlighterTargetArea.EXACT_RANGE);
  }

  ((EditorImpl)myEditor).setPaintSelection(mySelected);
  SelectionModel selectionModel = myEditor.getSelectionModel();
  selectionModel.setSelection(0, mySelected ? myEditor.getDocument().getTextLength() : 0);
}
项目:consulo    文件:AbstractValueHint.java   
public void invokeHint(Runnable hideRunnable) {
  myHideRunnable = hideRunnable;

  if (!canShowHint()) {
    hideHint();
    return;
  }

  if (myType == ValueHintType.MOUSE_ALT_OVER_HINT) {
    EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
    TextAttributes attributes = scheme.getAttributes(EditorColors.REFERENCE_HYPERLINK_COLOR);
    attributes = NavigationUtil.patchAttributesColor(attributes, myCurrentRange, myEditor);

    myHighlighter = myEditor.getMarkupModel().addRangeHighlighter(myCurrentRange.getStartOffset(), myCurrentRange.getEndOffset(),
                                                                  HighlighterLayer.SELECTION + 1, attributes,
                                                                  HighlighterTargetArea.EXACT_RANGE);
    Component internalComponent = myEditor.getContentComponent();
    myStoredCursor = internalComponent.getCursor();
    internalComponent.addKeyListener(myEditorKeyListener);
    internalComponent.setCursor(hintCursor());
    if (LOG.isDebugEnabled()) {
      LOG.debug("internalComponent.setCursor(hintCursor())");
    }
  }
  else {
    evaluateAndShowHint();
  }
}
项目:consulo    文件:HighlightUsagesHandler.java   
private static void clearHighlights(Editor editor,
                                    HighlightManager highlightManager,
                                    List<TextRange> rangesToHighlight,
                                    TextAttributes attributes) {
  if (editor instanceof EditorWindow) editor = ((EditorWindow)editor).getDelegate();
  RangeHighlighter[] highlighters = ((HighlightManagerImpl)highlightManager).getHighlighters(editor);
  Arrays.sort(highlighters, (o1, o2) -> o1.getStartOffset() - o2.getStartOffset());
  Collections.sort(rangesToHighlight, (o1, o2) -> o1.getStartOffset() - o2.getStartOffset());
  int i = 0;
  int j = 0;
  while (i < highlighters.length && j < rangesToHighlight.size()) {
    RangeHighlighter highlighter = highlighters[i];
    TextRange highlighterRange = TextRange.create(highlighter);
    TextRange refRange = rangesToHighlight.get(j);
    if (refRange.equals(highlighterRange) && attributes.equals(highlighter.getTextAttributes()) &&
        highlighter.getLayer() == HighlighterLayer.SELECTION - 1) {
      highlightManager.removeSegmentHighlighter(editor, highlighter);
      i++;
    }
    else if (refRange.getStartOffset() > highlighterRange.getEndOffset()) {
      i++;
    }
    else if (refRange.getEndOffset() < highlighterRange.getStartOffset()) {
      j++;
    }
    else {
      i++;
      j++;
    }
  }
}
项目:consulo    文件:LineMarkersUtil.java   
@Nonnull
private static RangeHighlighter createOrReuseLineMarker(@Nonnull LineMarkerInfo info,
                                                        @Nonnull MarkupModel markupModel,
                                                        @Nullable HighlightersRecycler toReuse) {
  RangeHighlighter highlighter = toReuse == null ? null : toReuse.pickupHighlighterFromGarbageBin(info.startOffset, info.endOffset, HighlighterLayer.ADDITIONAL_SYNTAX);
  if (highlighter == null) {
    highlighter = markupModel.addRangeHighlighter(info.startOffset, info.endOffset, HighlighterLayer.ADDITIONAL_SYNTAX, null, HighlighterTargetArea.LINES_IN_RANGE);
  }
  highlighter.putUserData(LINE_MARKER_INFO, info);
  LineMarkerInfo.LineMarkerGutterIconRenderer newRenderer = (LineMarkerInfo.LineMarkerGutterIconRenderer)info.createGutterRenderer();
  LineMarkerInfo.LineMarkerGutterIconRenderer oldRenderer = highlighter.getGutterIconRenderer() instanceof LineMarkerInfo.LineMarkerGutterIconRenderer ? (LineMarkerInfo.LineMarkerGutterIconRenderer)highlighter.getGutterIconRenderer() : null;
  boolean rendererChanged = oldRenderer == null || newRenderer == null || !newRenderer.equals(oldRenderer);
  boolean lineSeparatorColorChanged = !Comparing.equal(highlighter.getLineSeparatorColor(), info.separatorColor);
  boolean lineSeparatorPlacementChanged = !Comparing.equal(highlighter.getLineSeparatorPlacement(), info.separatorPlacement);

  if (rendererChanged || lineSeparatorColorChanged || lineSeparatorPlacementChanged) {
    ((MarkupModelEx)markupModel).changeAttributesInBatch((RangeHighlighterEx)highlighter, markerEx -> {
      if (rendererChanged) {
        markerEx.setGutterIconRenderer(newRenderer);
      }
      if (lineSeparatorColorChanged) {
        markerEx.setLineSeparatorColor(info.separatorColor);
      }
      if (lineSeparatorPlacementChanged) {
        markerEx.setLineSeparatorPlacement(info.separatorPlacement);
      }
    });
  }
  info.highlighter = highlighter;
  return highlighter;
}
项目:consulo    文件:TemplateState.java   
private RangeHighlighter getSegmentHighlighter(int segmentNumber, boolean isSelected, boolean isEnd) {
  final TextAttributes lvAttr = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.LIVE_TEMPLATE_ATTRIBUTES);
  TextAttributes attributes = isSelected ? lvAttr : new TextAttributes();
  TextAttributes endAttributes = new TextAttributes();

  int start = mySegments.getSegmentStart(segmentNumber);
  int end = mySegments.getSegmentEnd(segmentNumber);
  RangeHighlighter segmentHighlighter = myEditor.getMarkupModel()
          .addRangeHighlighter(start, end, HighlighterLayer.LAST + 1, isEnd ? endAttributes : attributes, HighlighterTargetArea.EXACT_RANGE);
  segmentHighlighter.setGreedyToLeft(true);
  segmentHighlighter.setGreedyToRight(true);
  return segmentHighlighter;
}
项目:consulo    文件:HighlightData.java   
public void addHighlToView(final Editor view, EditorColorsScheme scheme, final Map<TextAttributesKey,String> displayText) {

    // XXX: Hack
    if (HighlighterColors.BAD_CHARACTER.equals(myHighlightType)) {
      return;
    }

    final TextAttributes attr = scheme.getAttributes(myHighlightType);
    if (attr != null) {
      UIUtil.invokeAndWaitIfNeeded((Runnable)() -> {
        try {
          // IDEA-53203: add ERASE_MARKER for manually defined attributes
          view.getMarkupModel().addRangeHighlighter(myStartOffset, myEndOffset, HighlighterLayer.ADDITIONAL_SYNTAX,
                                                    TextAttributes.ERASE_MARKER, HighlighterTargetArea.EXACT_RANGE);
          RangeHighlighter highlighter = view.getMarkupModel()
                  .addRangeHighlighter(myStartOffset, myEndOffset, HighlighterLayer.ADDITIONAL_SYNTAX, attr,
                                       HighlighterTargetArea.EXACT_RANGE);
          final Color errorStripeColor = attr.getErrorStripeColor();
          highlighter.setErrorStripeMarkColor(errorStripeColor);
          final String tooltip = displayText.get(myHighlightType);
          highlighter.setErrorStripeTooltip(tooltip);
        }
        catch (Exception e) {
          throw new RuntimeException(e);
        }
      });
    }
  }
项目:consulo    文件:LanguageConsoleBuilder.java   
private void addLineSeparatorPainterIfNeed() {
  if (lineSeparatorPainter != null) {
    return;
  }

  RangeHighlighter highlighter = getHistoryViewer().getMarkupModel().addRangeHighlighter(0, getDocument().getTextLength(), HighlighterLayer.ADDITIONAL_SYNTAX, null, HighlighterTargetArea.EXACT_RANGE);
  highlighter.setGreedyToRight(true);
  highlighter.setCustomRenderer(renderer);
  lineSeparatorPainter = highlighter;
}
项目:consulo    文件:DetailViewImpl.java   
@Override
public void navigateInPreviewEditor(PreviewEditorState editorState) {
  final VirtualFile file = editorState.getFile();
  final LogicalPosition positionToNavigate = editorState.getNavigate();
  final TextAttributes lineAttributes = editorState.getAttributes();
  Document document = FileDocumentManager.getInstance().getDocument(file);

  clearEditor();
  myEditorState = editorState;
  remove(myLabel);
  if (document != null) {
    if (getEditor() == null || getEditor().getDocument() != document) {
      setEditor(createEditor(myProject, document, file));
      add(getEditor().getComponent(), BorderLayout.CENTER);
    }

    if (positionToNavigate != null) {
      getEditor().getCaretModel().moveToLogicalPosition(positionToNavigate);
      validate();
      getEditor().getScrollingModel().scrollToCaret(ScrollType.CENTER);
    } else {
      revalidate();
      repaint();
    }

    clearHighlighting();
    if (lineAttributes != null && positionToNavigate != null && positionToNavigate.line < getEditor().getDocument().getLineCount()) {
      myHighlighter = getEditor().getMarkupModel().addLineHighlighter(positionToNavigate.line, HighlighterLayer.SELECTION - 1,
                                                                      lineAttributes);
    }
  }
  else {
    myLabel.setText("Navigate to selected " + (file.isDirectory() ? "directory " : "file ") + "in Project View");
    add(myLabel, BorderLayout.CENTER);
    validate();
  }
}
项目:consulo    文件:Bookmark.java   
public RangeHighlighter createHighlighter(@Nonnull MarkupModelEx markup) {
  final RangeHighlighterEx myHighlighter;
  int line = getLine();
  if (line >= 0) {
    myHighlighter = markup.addPersistentLineHighlighter(line, HighlighterLayer.ERROR + 1, null);
    if (myHighlighter != null) {
      myHighlighter.setGutterIconRenderer(new MyGutterIconRenderer(this));

      TextAttributes textAttributes =
              EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.BOOKMARKS_ATTRIBUTES);

      Color stripeColor = textAttributes.getErrorStripeColor();
      myHighlighter.setErrorStripeMarkColor(stripeColor != null ? stripeColor : Color.black);
      myHighlighter.setErrorStripeTooltip(getBookmarkTooltip());

      TextAttributes attributes = myHighlighter.getTextAttributes();
      if (attributes == null) {
        attributes = new TextAttributes();
      }
      attributes.setBackgroundColor(textAttributes.getBackgroundColor());
      attributes.setForegroundColor(textAttributes.getForegroundColor());
      myHighlighter.setTextAttributes(attributes);
    }
  }
  else {
    myHighlighter = null;
  }
  return myHighlighter;
}
项目:intellij-ce-playground    文件:EditorPaintingTest.java   
public void testWholeLineHighlighterAtDocumentEnd() throws Exception {
  initText("foo");
  addLineHighlighter(0, 3, HighlighterLayer.WARNING, null, Color.red);
  checkResult();
}