private void highlightNotification( final Notification notification, String message, final int line1, final int line2) { final MarkupModel markupModel = myLogEditor.getValue().getMarkupModel(); TextAttributes bold = new TextAttributes(null, null, null, null, Font.BOLD); final List<RangeHighlighter> lineColors = new ArrayList<RangeHighlighter>(); for (int line = line1; line < line2; line++) { final RangeHighlighter lineHighlighter = markupModel.addLineHighlighter(line, HighlighterLayer.CARET_ROW + 1, bold); Color color = notification.getType() == NotificationType.ERROR ? JBColor.RED : notification.getType() == NotificationType.WARNING ? JBColor.YELLOW : JBColor.GREEN; lineHighlighter.setErrorStripeMarkColor(color); lineHighlighter.setErrorStripeTooltip(message); lineColors.add(lineHighlighter); } final Runnable removeHandler = new Runnable() { @Override public void run() { for (RangeHighlighter color : lineColors) { markupModel.removeHighlighter(color); } TextAttributes attributes = EditorColorsManager.getInstance() .getGlobalScheme() .getAttributes(ConsoleViewContentType.LOG_EXPIRED_ENTRY); for (int line = line1; line < line2; line++) { markupModel.addLineHighlighter(line, HighlighterLayer.CARET_ROW + 1, attributes); } TextAttributes italic = new TextAttributes(null, null, null, null, Font.ITALIC); for (int line = line1; line < line2; line++) { for (RangeHighlighter highlighter : myHyperlinkSupport.getValue().findAllHyperlinksOnLine(line)) { markupModel.addRangeHighlighter( highlighter.getStartOffset(), highlighter.getEndOffset(), HighlighterLayer.CARET_ROW + 2, italic, HighlighterTargetArea.EXACT_RANGE); myHyperlinkSupport.getValue().removeHyperlink(highlighter); } } } }; if (!notification.isExpired()) { myProjectModel.removeHandlers.put(notification, removeHandler); } else { removeHandler.run(); } }
@NotNull public static RangeHighlighter createRangeHighlighter( @NotNull Range range, @NotNull TextRange textRange, @NotNull MarkupModel markupModel) { TextAttributes attributes = getTextAttributes(range); final RangeHighlighter highlighter = markupModel.addRangeHighlighter( textRange.getStartOffset(), textRange.getEndOffset(), HighlighterLayer.FIRST - 1, attributes, HighlighterTargetArea.LINES_IN_RANGE); highlighter.setThinErrorStripeMark(true); highlighter.setGreedyToLeft(true); highlighter.setGreedyToRight(true); highlighter.setErrorStripeTooltip(getTooltipText(range)); return highlighter; }