public void hideCoverageData() { if (myEditor == null) return; final FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject); final List<RangeHighlighter> highlighters = myEditor.getUserData(COVERAGE_HIGHLIGHTERS); if (highlighters != null) { for (final RangeHighlighter highlighter : highlighters) { ApplicationManager.getApplication().invokeLater(() -> highlighter.dispose()); } myEditor.putUserData(COVERAGE_HIGHLIGHTERS, null); } final Map<FileEditor, EditorNotificationPanel> map = myFile.getCopyableUserData(NOTIFICATION_PANELS); if (map != null) { final VirtualFile vFile = myFile.getVirtualFile(); LOG.assertTrue(vFile != null); boolean freeAll = !fileEditorManager.isFileOpen(vFile); myFile.putCopyableUserData(NOTIFICATION_PANELS, null); for (FileEditor fileEditor : map.keySet()) { if (!freeAll && !isCurrentEditor(fileEditor)) { continue; } fileEditorManager.removeTopComponent(fileEditor, map.get(fileEditor)); } } final DocumentListener documentListener = myEditor.getUserData(COVERAGE_DOCUMENT_LISTENER); if (documentListener != null) { myDocument.removeDocumentListener(documentListener); myEditor.putUserData(COVERAGE_DOCUMENT_LISTENER, null); } }
@Nullable private RangeHighlighter addLine( final ChangeHighlighterHolder markup, int line, final TextDiffType type, SeparatorPlacement placement) { RangeHighlighter highlighter = markup.addLineHighlighter(line, LAYER, type, myApplied); if (highlighter == null) { return null; } highlighter.setLineSeparatorPlacement(placement); highlighter.setLineSeparatorRenderer( new LineSeparatorRenderer() { @Override public void drawLine(Graphics g, int x1, int x2, int y) { Graphics2D g2 = (Graphics2D) g; Color color = myDiffType.getPolygonColor(markup.getEditor()); if (color != null) { if (type.isApplied()) { UIUtil.drawBoldDottedLine(g2, x1, x2, y, null, color, false); } else { DiffUtil.drawDoubleShadowedLine(g2, x1, x2, y, color); } } } }); return highlighter; }
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(); } }
public void uninstall() { for (RangeHighlighter highlighter : myHighlighters) { highlighter.dispose(); } Component internalComponent = myHighlighterView.getContentComponent(); internalComponent.setCursor(myStoredCursor); internalComponent.removeKeyListener(myEditorKeyListener); myHighlighterView.getScrollingModel().removeVisibleAreaListener(myVisibleAreaListener); myFileEditorManager.removeFileEditorManagerListener(myFileEditorManagerListener); }
@Nullable public RelativePoint getHyperlinkLocation(HyperlinkInfo info) { Editor editor = myLogEditor.getValue(); Project project = editor.getProject(); RangeHighlighter range = myHyperlinkSupport.getValue().findHyperlinkRange(info); Window window = NotificationsManagerImpl.findWindowForBalloon(project); if (range != null && window != null) { Point point = editor.visualPositionToXY(editor.offsetToVisualPosition(range.getStartOffset())); return new RelativePoint( window, SwingUtilities.convertPoint(editor.getContentComponent(), point, window)); } return null; }
private static void duplicateHighlighters( MarkupModel to, MarkupModel from, int offset, TextRange textRange) { for (RangeHighlighter rangeHighlighter : from.getAllHighlighters()) { if (!rangeHighlighter.isValid()) continue; Object tooltip = rangeHighlighter.getErrorStripeTooltip(); HighlightInfo highlightInfo = tooltip instanceof HighlightInfo ? (HighlightInfo) tooltip : null; if (highlightInfo != null) { if (highlightInfo.getSeverity() != HighlightSeverity.INFORMATION) continue; if (highlightInfo.type.getAttributesKey() == EditorColors.IDENTIFIER_UNDER_CARET_ATTRIBUTES) continue; } final int localOffset = textRange.getStartOffset(); final int start = Math.max(rangeHighlighter.getStartOffset(), localOffset) - localOffset; final int end = Math.min(rangeHighlighter.getEndOffset(), textRange.getEndOffset()) - localOffset; if (start > end) continue; final RangeHighlighter h = to.addRangeHighlighter( start + offset, end + offset, rangeHighlighter.getLayer(), rangeHighlighter.getTextAttributes(), rangeHighlighter.getTargetArea()); ((RangeHighlighterEx) h) .setAfterEndOfLine(((RangeHighlighterEx) rangeHighlighter).isAfterEndOfLine()); } }
private static void clearLineMarkers(Editor editor) { final List<RangeHighlighter> oldHighlighters = editor.getUserData(TAG_TREE_HIGHLIGHTERS_IN_EDITOR_KEY); if (oldHighlighters != null) { final MarkupModelEx markupModel = (MarkupModelEx) editor.getMarkupModel(); for (RangeHighlighter highlighter : oldHighlighters) { if (markupModel.containsHighlighter(highlighter)) { highlighter.dispose(); } } editor.putUserData(TAG_TREE_HIGHLIGHTERS_IN_EDITOR_KEY, null); } }
@Override public void addOccurrenceHighlight( @NotNull Editor editor, int start, int end, TextAttributes attributes, int flags, Collection<RangeHighlighter> outHighlighters, Color scrollmarkColor) { RangeHighlighter highlighter = addSegmentHighlighter(editor, start, end, attributes, flags); if (outHighlighters != null) { outHighlighters.add(highlighter); } if (scrollmarkColor != null) { highlighter.setErrorStripeMarkColor(scrollmarkColor); } }
public static void clearHighlightingAndLineMarkers( final Editor editor, @NotNull Project project) { final MarkupModel markupModel = DocumentMarkupModel.forDocument(editor.getDocument(), project, true); for (RangeHighlighter highlighter : markupModel.getAllHighlighters()) { Object tooltip = highlighter.getErrorStripeTooltip(); if (!(tooltip instanceof HighlightInfo)) { continue; } if (((HighlightInfo) tooltip).type == TYPE) { highlighter.dispose(); } } clearLineMarkers(editor); }
@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; }
@NotNull private static RangeHighlighter createHighlighter( final MarkupModel mm, @NotNull final TextRange range, final Color color) { final RangeHighlighter highlighter = mm.addRangeHighlighter( range.getStartOffset(), range.getEndOffset(), 0, null, HighlighterTargetArea.LINES_IN_RANGE); highlighter.setLineMarkerRenderer( new LineMarkerRenderer() { @Override public void paint(Editor editor, Graphics g, Rectangle r) { g.setColor(color); g.fillRect(r.x, r.y, 2, r.height); } }); return highlighter; }
@Nullable private RangeHighlighter createHighlighter(@NotNull Range range) { myApplication.assertIsDispatchThread(); LOG.assertTrue(!myReleased, "Already released"); if (myMode == Mode.SILENT) return null; int first = range.getLine1() >= getLineCount(myDocument) ? myDocument.getTextLength() : myDocument.getLineStartOffset(range.getLine1()); int second = range.getLine2() >= getLineCount(myDocument) ? myDocument.getTextLength() : myDocument.getLineStartOffset(range.getLine2()); final TextAttributes attr = LineStatusTrackerDrawing.getAttributesFor(range); final RangeHighlighter highlighter = DocumentMarkupModel.forDocument(myDocument, myProject, true) .addRangeHighlighter( first, second, HighlighterLayer.FIRST - 1, attr, HighlighterTargetArea.LINES_IN_RANGE); highlighter.setThinErrorStripeMark(true); highlighter.setGreedyToLeft(true); highlighter.setGreedyToRight(true); highlighter.setLineMarkerRenderer(LineStatusTrackerDrawing.createRenderer(range, this)); highlighter.setEditorFilter(MarkupEditorFilterFactory.createIsNotDiffFilter()); final String tooltip; if (range.getLine1() == range.getLine2()) { if (range.getVcsLine1() + 1 == range.getVcsLine2()) { tooltip = VcsBundle.message("tooltip.text.line.before.deleted", range.getLine1() + 1); } else { tooltip = VcsBundle.message( "tooltip.text.lines.before.deleted", range.getLine1() + 1, range.getVcsLine2() - range.getVcsLine1()); } } else if (range.getLine1() + 1 == range.getLine2()) { tooltip = VcsBundle.message("tooltip.text.line.changed", range.getLine1() + 1); } else { tooltip = VcsBundle.message("tooltip.text.lines.changed", range.getLine1() + 1, range.getLine2()); } highlighter.setErrorStripeTooltip(tooltip); return highlighter; }
@Override public boolean removeSegmentHighlighter( @NotNull Editor editor, @NotNull RangeHighlighter highlighter) { Map<RangeHighlighter, HighlightInfo> map = getHighlightInfoMap(editor, false); if (map == null) return false; HighlightInfo info = map.get(highlighter); if (info == null) return false; MarkupModel markupModel = info.editor.getMarkupModel(); if (((MarkupModelEx) markupModel).containsHighlighter(highlighter)) { highlighter.dispose(); } map.remove(highlighter); return true; }
@Nullable private RangeHighlighter addBlock( String text, ChangeSide changeSide, final ChangeHighlighterHolder markup, TextDiffType diffType) { EditorColorsScheme colorScheme = markup.getEditor().getColorsScheme(); Color separatorColor = getSeparatorColor(diffType.getLegendColor(colorScheme)); int length = text.length(); int start = changeSide.getStart(); int end = start + length; RangeHighlighter highlighter = markup.addRangeHighlighter( start, end, LAYER, diffType, HighlighterTargetArea.EXACT_RANGE, myApplied); LineSeparatorRenderer lineSeparatorRenderer = new LineSeparatorRenderer() { @Override public void drawLine(Graphics g, int x1, int x2, int y) { Graphics2D g2 = (Graphics2D) g; Color color = myDiffType.getPolygonColor(markup.getEditor()); if (color != null) { if (myApplied) { UIUtil.drawBoldDottedLine(g2, x1, x2, y, null, color, false); } else { UIUtil.drawLine(g2, x1, y, x2, y, null, DiffUtil.getFramingColor(color)); } } } }; if (highlighter != null) { highlighter.setLineSeparatorPlacement(SeparatorPlacement.TOP); highlighter.setLineSeparatorColor(separatorColor); highlighter.setLineSeparatorRenderer(lineSeparatorRenderer); } if (text.charAt(length - 1) == '\n') { end--; } highlighter = markup.addRangeHighlighter( start, end, LAYER, TextDiffType.NONE, HighlighterTargetArea.EXACT_RANGE, myApplied); if (highlighter != null) { highlighter.setLineSeparatorPlacement(SeparatorPlacement.BOTTOM); highlighter.setLineSeparatorColor(separatorColor); highlighter.setLineSeparatorRenderer(lineSeparatorRenderer); } return highlighter; }
private void paintLineMarkerSeparator(RangeHighlighter marker, Rectangle clip, Graphics g) { Color separatorColor = marker.getLineSeparatorColor(); LineSeparatorRenderer lineSeparatorRenderer = marker.getLineSeparatorRenderer(); if (separatorColor == null && lineSeparatorRenderer == null) { return; } int line = myDocument.getLineNumber( marker.getLineSeparatorPlacement() == SeparatorPlacement.TOP ? marker.getStartOffset() : marker.getEndOffset()); int visualLine = myView.logicalToVisualPosition( new LogicalPosition( line + (marker.getLineSeparatorPlacement() == SeparatorPlacement.TOP ? 0 : 1), 0), false) .line; int y = myView.visualLineToY(visualLine) - 1; int endShift = clip.x + clip.width; EditorSettings settings = myEditor.getSettings(); if (settings.isRightMarginShown() && myEditor.getColorsScheme().getColor(EditorColors.RIGHT_MARGIN_COLOR) != null) { endShift = Math.min( endShift, settings.getRightMargin(myEditor.getProject()) * myView.getPlainSpaceWidth()); } g.setColor(separatorColor); if (lineSeparatorRenderer != null) { lineSeparatorRenderer.drawLine(g, 0, endShift, y); } else { UIUtil.drawLine(g, 0, y, endShift, y); } }
private RangeHighlighter createRangeHighlighter( final long date, final MarkupModel markupModel, final boolean coverageByTestApplicable, final TreeMap<Integer, LineData> executableLines, @Nullable final String className, final int line, final int lineNumberInCurrent, @NotNull final CoverageSuitesBundle coverageSuite, Object[] lines) { EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); final TextAttributes attributes = scheme.getAttributes(CoverageLineMarkerRenderer.getAttributesKey(line, executableLines)); TextAttributes textAttributes = null; if (attributes.getBackgroundColor() != null) { textAttributes = attributes; } final int startOffset = myDocument.getLineStartOffset(lineNumberInCurrent); final int endOffset = myDocument.getLineEndOffset(lineNumberInCurrent); final RangeHighlighter highlighter = markupModel.addRangeHighlighter( startOffset, endOffset, HighlighterLayer.SELECTION - 1, textAttributes, HighlighterTargetArea.LINES_IN_RANGE); final Function<Integer, Integer> newToOldConverter = newLine -> { if (myEditor == null) return -1; final TIntIntHashMap oldLineMapping = getNewToOldLineMapping(date); return oldLineMapping != null ? oldLineMapping.get(newLine.intValue()) : newLine.intValue(); }; final Function<Integer, Integer> oldToNewConverter = newLine -> { if (myEditor == null) return -1; final TIntIntHashMap newLineMapping = getOldToNewLineMapping(date); return newLineMapping != null ? newLineMapping.get(newLine.intValue()) : newLine.intValue(); }; final CoverageLineMarkerRenderer markerRenderer = coverageSuite .getCoverageEngine() .getLineMarkerRenderer( line, className, executableLines, coverageByTestApplicable, coverageSuite, newToOldConverter, oldToNewConverter, CoverageDataManager.getInstance(myProject).isSubCoverageActive()); highlighter.setLineMarkerRenderer(markerRenderer); final LineData lineData = className != null ? (LineData) lines[line + 1] : null; if (lineData != null && lineData.getStatus() == LineCoverage.NONE) { highlighter.setErrorStripeMarkColor(markerRenderer.getErrorStripeColor(myEditor)); highlighter.setThinErrorStripeMark(true); highlighter.setGreedyToLeft(true); highlighter.setGreedyToRight(true); } return highlighter; }