com.intellij.openapi.editor.markup.TextAttributes Java Examples
The following examples show how to use
com.intellij.openapi.editor.markup.TextAttributes.
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: RecentLocationsDataModel.java From consulo with Apache License 2.0 | 6 votes |
private void applyHighlightingPasses(Project project, final EditorEx editor, Document document, final EditorColorsScheme colorsScheme, final TextRange rangeMarker) { final int startOffset = rangeMarker.getStartOffset(); final int endOffset = rangeMarker.getEndOffset(); DaemonCodeAnalyzerEx.processHighlights(document, project, null, startOffset, endOffset, info -> { if (info.getStartOffset() >= startOffset && info.getEndOffset() <= endOffset) { HighlightSeverity highlightSeverity = info.getSeverity(); if (highlightSeverity == HighlightSeverity.ERROR || highlightSeverity == HighlightSeverity.WARNING || highlightSeverity == HighlightSeverity.WEAK_WARNING || highlightSeverity == HighlightSeverity.GENERIC_SERVER_ERROR_OR_WARNING) { return true; } TextAttributes textAttributes = info.forcedTextAttributes != null ? info.forcedTextAttributes : colorsScheme.getAttributes(info.forcedTextAttributesKey); editor.getMarkupModel().addRangeHighlighter(info.getActualStartOffset() - rangeMarker.getStartOffset(), info.getActualEndOffset() - rangeMarker.getStartOffset(), 1000, textAttributes, HighlighterTargetArea.EXACT_RANGE); return true; } else { return true; } }); }
Example #2
Source File: AbstractColorsScheme.java From consulo with Apache License 2.0 | 6 votes |
public void copyTo(AbstractColorsScheme newScheme) { myFontPreferences.copyTo(newScheme.myFontPreferences); newScheme.myLineSpacing = myLineSpacing; newScheme.myQuickDocFontSize = myQuickDocFontSize; myConsoleFontPreferences.copyTo(newScheme.myConsoleFontPreferences); newScheme.myConsoleLineSpacing = myConsoleLineSpacing; final Set<EditorFontType> types = myFonts.keySet(); for (EditorFontType type : types) { Font font = myFonts.get(type); newScheme.setFont(type, font); } newScheme.myAttributesMap = new HashMap<TextAttributesKey, TextAttributes>(myAttributesMap); newScheme.myColorsMap = new HashMap<ColorKey, Color>(myColorsMap); newScheme.myVersion = myVersion; }
Example #3
Source File: HighlightingUtil.java From needsmoredojo with Apache License 2.0 | 6 votes |
public static void highlightElement(Editor editor, @NotNull com.intellij.openapi.project.Project project, @NotNull PsiElement[] elements) { final HighlightManager highlightManager = HighlightManager.getInstance(project); final EditorColorsManager editorColorsManager = EditorColorsManager.getInstance(); final EditorColorsScheme globalScheme = editorColorsManager.getGlobalScheme(); final TextAttributes textattributes = globalScheme.getAttributes( EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES); highlightManager.addOccurrenceHighlights( editor, elements, textattributes, true, null); final WindowManager windowManager = WindowManager.getInstance(); final StatusBar statusBar = windowManager.getStatusBar(project); statusBar.setInfo("Press Esc to remove highlighting"); }
Example #4
Source File: CoverageLineMarkerRenderer.java From consulo with Apache License 2.0 | 6 votes |
public void paint(Editor editor, Graphics g, Rectangle r) { final TextAttributes color = editor.getColorsScheme().getAttributes(myKey); Color bgColor = color.getBackgroundColor(); if (bgColor == null) { bgColor = color.getForegroundColor(); } if (editor.getSettings().isLineNumbersShown() || ((EditorGutterComponentEx)editor.getGutter()).isAnnotationsShown()) { if (bgColor != null) { bgColor = ColorUtil.toAlpha(bgColor, 150); } } if (bgColor != null) { g.setColor(bgColor); } g.fillRect(r.x, r.y, r.width, r.height); final LineData lineData = getLineData(editor.xyToLogicalPosition(new Point(0, r.y)).line); if (lineData != null && lineData.isCoveredByOneTest()) { AllIcons.Gutter.Unique.paintIcon(editor.getComponent(), g, r.x, r.y); } }
Example #5
Source File: EditorHyperlinkSupport.java From consulo with Apache License 2.0 | 6 votes |
void highlightHyperlinks(@Nonnull Filter.Result result, int offsetDelta) { Document document = myEditor.getDocument(); for (Filter.ResultItem resultItem : result.getResultItems()) { int start = resultItem.getHighlightStartOffset() + offsetDelta; int end = resultItem.getHighlightEndOffset() + offsetDelta; if (start < 0 || end < start || end > document.getTextLength()) { continue; } TextAttributes attributes = resultItem.getHighlightAttributes(); if (resultItem.getHyperlinkInfo() != null) { createHyperlink(start, end, attributes, resultItem.getHyperlinkInfo(), resultItem.getFollowedHyperlinkAttributes(), resultItem.getHighlighterLayer()); } else if (attributes != null) { addHighlighter(start, end, attributes, resultItem.getHighlighterLayer()); } } }
Example #6
Source File: HTMLTextPainter.java From consulo with Apache License 2.0 | 6 votes |
private void writeStyles(@NonNls final Writer writer) throws IOException { writer.write("<style type=\"text/css\">\n"); writer.write(".ln { color: rgb(0,0,0); font-weight: normal; font-style: normal; }\n"); HighlighterIterator hIterator = myHighlighter.createIterator(myOffset); while(!hIterator.atEnd()) { TextAttributes textAttributes = hIterator.getTextAttributes(); if (!myStyleMap.containsKey(textAttributes)) { @NonNls String styleName = "s" + myStyleMap.size(); myStyleMap.put(textAttributes, styleName); writer.write("." + styleName + " { "); final Color foreColor = textAttributes.getForegroundColor(); if (foreColor != null) { writer.write("color: rgb(" + foreColor.getRed() + "," + foreColor.getGreen() + "," + foreColor.getBlue() + "); "); } if ((textAttributes.getFontType() & Font.BOLD) != 0) { writer.write("font-weight: bold; "); } if ((textAttributes.getFontType() & Font.ITALIC) != 0) { writer.write("font-style: italic; "); } writer.write("}\n"); } hIterator.advance(); } writer.write("</style>\n"); }
Example #7
Source File: FlowInPlaceRenamer.java From mule-intellij-plugins with Apache License 2.0 | 6 votes |
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 #8
Source File: EditorHyperlinkSupport.java From consulo with Apache License 2.0 | 6 votes |
private static void linkFollowed(Editor editor, Collection<? extends RangeHighlighter> ranges, final RangeHighlighter link) { MarkupModelEx markupModel = (MarkupModelEx)editor.getMarkupModel(); for (RangeHighlighter range : ranges) { TextAttributes oldAttr = range.getUserData(OLD_HYPERLINK_TEXT_ATTRIBUTES); if (oldAttr != null) { markupModel.setRangeHighlighterAttributes(range, oldAttr); range.putUserData(OLD_HYPERLINK_TEXT_ATTRIBUTES, null); } if (range == link) { range.putUserData(OLD_HYPERLINK_TEXT_ATTRIBUTES, range.getTextAttributes()); markupModel.setRangeHighlighterAttributes(range, getFollowedHyperlinkAttributes(range)); } } //refresh highlighter text attributes markupModel.addRangeHighlighter(0, 0, link.getLayer(), getHyperlinkAttributes(), HighlighterTargetArea.EXACT_RANGE).dispose(); }
Example #9
Source File: LexerEditorHighlighter.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull TextAttributes convertAttributes(@Nonnull TextAttributesKey[] keys) { TextAttributes resultAttributes = new TextAttributes(); boolean firstPass = true; for (TextAttributesKey key : keys) { TextAttributes attributesByKey = myScheme.getAttributes(key); if (attributesByKey == null) { continue; } if (firstPass) { resultAttributes.copyFrom(attributesByKey); firstPass = false; } else { resultAttributes = TextAttributes.merge(resultAttributes, attributesByKey); } } return resultAttributes; }
Example #10
Source File: MarkupModelImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override @Nullable public RangeHighlighterEx addPersistentLineHighlighter(int lineNumber, int layer, TextAttributes textAttributes) { if (isNotValidLine(lineNumber)) { return null; } int offset = DocumentUtil.getFirstNonSpaceCharOffset(getDocument(), lineNumber); return addRangeHighlighter(PersistentRangeHighlighterImpl.create(this, offset, layer, HighlighterTargetArea.LINES_IN_RANGE, textAttributes, false), null); }
Example #11
Source File: PsiElementListCellRenderer.java From consulo with Apache License 2.0 | 5 votes |
@Nullable protected TextAttributes getNavigationItemAttributes(Object value) { TextAttributes attributes = null; if (value instanceof NavigationItem) { TextAttributesKey attributesKey = null; final ItemPresentation presentation = ((NavigationItem)value).getPresentation(); if (presentation instanceof ColoredItemPresentation) attributesKey = ((ColoredItemPresentation)presentation).getTextAttributesKey(); if (attributesKey != null) { attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(attributesKey); } } return attributes; }
Example #12
Source File: SelectionAnnotation.java From saros with GNU General Public License v2.0 | 5 votes |
/** * Returns the text attributes used for selection annotation range highlighters. * * @param editor the editor to which the annotation belongs * @param user the user to whom the annotation belongs * @return the text attributes used for selection annotation range highlighters */ private static TextAttributes getSelectionTextAttributes( @NotNull Editor editor, @NotNull User user) { // Retrieve color keys based on the color ID selected by this user. This will automatically // fall back to default colors, if no colors for the given ID are available. ColorKeys colorKeys = ColorManager.getColorKeys(user.getColorID()); TextAttributesKey highlightColorKey = colorKeys.getSelectionColorKey(); // Resolve the correct text attributes based on the currently configured IDE scheme. return editor.getColorsScheme().getAttributes(highlightColorKey); }
Example #13
Source File: LivePreview.java From consulo with Apache License 2.0 | 5 votes |
private RangeHighlighter addHighlighter(int startOffset, int endOffset, @Nonnull TextAttributes attributes) { Project project = mySearchResults.getProject(); if (project == null || project.isDisposed()) return null; List<RangeHighlighter> sink = new ArrayList<>(); HighlightManager.getInstance(project).addRangeHighlight(mySearchResults.getEditor(), startOffset, endOffset, attributes, false, sink); RangeHighlighter result = ContainerUtil.getFirstItem(sink); if (result instanceof RangeHighlighterEx) ((RangeHighlighterEx)result).setVisibleIfFolded(true); return result; }
Example #14
Source File: ExtractIncludeFileBase.java From consulo with Apache License 2.0 | 5 votes |
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); }
Example #15
Source File: IntentionUsagePanel.java From consulo with Apache License 2.0 | 5 votes |
public IntentionUsagePanel() { myEditor = (EditorEx)createEditor("", 10, 3, -1); setLayout(new BorderLayout()); add(myEditor.getComponent(), BorderLayout.CENTER); TextAttributes blinkAttributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.BLINKING_HIGHLIGHTS_ATTRIBUTES); myRangeBlinker = new RangeBlinker(myEditor, blinkAttributes, Integer.MAX_VALUE); }
Example #16
Source File: HippieWordCompletionHandler.java From consulo with Apache License 2.0 | 5 votes |
private static void highlightWord(final CompletionVariant variant, final Project project, CompletionData data) { int delta = data.startOffset < variant.offset ? variant.variant.length() - data.myWordUnderCursor.length() : 0; HighlightManager highlightManager = HighlightManager.getInstance(project); EditorColorsManager colorManager = EditorColorsManager.getInstance(); TextAttributes attributes = colorManager.getGlobalScheme().getAttributes(EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES); highlightManager.addOccurrenceHighlight(variant.editor, variant.offset + delta, variant.offset + variant.variant.length() + delta, attributes, HighlightManager.HIDE_BY_ANY_KEY, null, null); }
Example #17
Source File: HighlightCommand.java From CppTools with Apache License 2.0 | 5 votes |
private static RangeHighlighter processHighlighter(int hFrom, int hTo, int colorIndex, TextAttributes attrs, Editor editor, TIntObjectHashMap<RangeHighlighter> lastOffsetToMarkersMap, THashSet<RangeHighlighter> highlightersSet, THashSet<RangeHighlighter> invalidMarkersSet ) { RangeHighlighter rangeHighlighter = lastOffsetToMarkersMap.get(hFrom); if (rangeHighlighter == null || rangeHighlighter.getEndOffset() != hTo || rangeHighlighter.getTextAttributes() != attrs ) { highlightersSet.add( rangeHighlighter = HighlightUtils.createRangeMarker( editor, hFrom, hTo, colorIndex, attrs ) ); lastOffsetToMarkersMap.put(hFrom, rangeHighlighter); } else { highlightersSet.add(rangeHighlighter); invalidMarkersSet.remove(rangeHighlighter); } return rangeHighlighter; }
Example #18
Source File: HighlightData.java From consulo with Apache License 2.0 | 5 votes |
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); } }); } }
Example #19
Source File: XDebuggerEditorLinePainter.java From consulo with Apache License 2.0 | 5 votes |
public static TextAttributes getNormalAttributes() { TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(DebuggerColors.INLINED_VALUES); if (attributes == null || attributes.getForegroundColor() == null) { return new TextAttributes(new JBColor(() -> isDarkEditor() ? new Color(0x3d8065) : Gray._135), null, null, null, Font.ITALIC); } return attributes; }
Example #20
Source File: HighlightUsagesHandler.java From consulo with Apache License 2.0 | 5 votes |
private static void doHighlightRefs(HighlightManager highlightManager, @Nonnull Editor editor, @Nonnull List<PsiReference> refs, TextAttributes attributes, boolean clearHighlights) { List<TextRange> textRanges = new ArrayList<>(refs.size()); for (PsiReference ref : refs) { collectRangesToHighlight(ref, textRanges); } highlightRanges(highlightManager, editor, attributes, clearHighlights, textRanges); }
Example #21
Source File: XDebuggerInlayUtil.java From consulo with Apache License 2.0 | 5 votes |
@Override public void paint(@Nonnull Inlay inlay, @Nonnull Graphics g, @Nonnull Rectangle r, @Nonnull TextAttributes textAttributes) { Editor editor = inlay.getEditor(); TextAttributes attributes = editor.getColorsScheme().getAttributes(DebuggerColors.INLINED_VALUES_EXECUTION_LINE); if (attributes == null) return; Color fgColor = attributes.getForegroundColor(); if (fgColor == null) return; g.setColor(fgColor); FontInfo fontInfo = getFontInfo(editor); g.setFont(fontInfo.getFont()); FontMetrics metrics = fontInfo.fontMetrics(); g.drawString(myText, r.x, r.y + metrics.getAscent()); }
Example #22
Source File: EditorColorsManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
public TextAttributes getDefaultAttributes(TextAttributesKey key) { final boolean dark = UIUtil.isUnderDarkTheme() && getScheme("Darcula") != null; // It is reasonable to fetch attributes from Default color scheme. Otherwise if we launch IDE and then // try switch from custom colors scheme (e.g. with dark background) to default one. Editor will show // incorrect highlighting with "traces" of color scheme which was active during IDE startup. return getScheme(dark ? "Darcula" : EditorColorsScheme.DEFAULT_SCHEME_NAME).getAttributes(key); }
Example #23
Source File: TextDiffTypeFactory.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public TextAttributes getAttributes(@Nullable Editor editor) { if (editor == null) { return EditorColorsManager.getInstance().getGlobalScheme().getAttributes(myKey); } else { return editor.getColorsScheme().getAttributes(myKey); } }
Example #24
Source File: ArrangementColorsProviderImpl.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @Override public TextAttributes getTextAttributes(@Nonnull ArrangementSettingsToken token, boolean selected) { final TextAttributes cached; if (selected) { cached = mySelectedAttributesCache.get(token); } else { cached = myNormalAttributesCache.get(token); } if (cached != null) { return cached; } TextAttributes result = null; if (myColorsAware != null) { result = myColorsAware.getTextAttributes(EditorColorsManager.getInstance().getGlobalScheme(), token, selected); } if (result == null) { result = selected ? myDefaultSelectedAttributes : myDefaultNormalAttributes; } if (selected) { mySelectedAttributesCache.put(token, result); } else { myNormalAttributesCache.put(token, result); } return result; }
Example #25
Source File: Filter.java From consulo with Apache License 2.0 | 5 votes |
@Nullable private static TextAttributes getGrayedHyperlinkAttributes(@Nonnull TextAttributesKey normalHyperlinkAttrsKey) { EditorColorsScheme globalScheme = EditorColorsManager.getInstance().getGlobalScheme(); TextAttributes grayedHyperlinkAttrs = GRAYED_BY_NORMAL_CACHE.get(normalHyperlinkAttrsKey); if (grayedHyperlinkAttrs == null) { TextAttributes normalHyperlinkAttrs = globalScheme.getAttributes(normalHyperlinkAttrsKey); if (normalHyperlinkAttrs != null) { grayedHyperlinkAttrs = normalHyperlinkAttrs.clone(); grayedHyperlinkAttrs.setForegroundColor(UIUtil.getInactiveTextColor()); grayedHyperlinkAttrs.setEffectColor(UIUtil.getInactiveTextColor()); GRAYED_BY_NORMAL_CACHE.put(normalHyperlinkAttrsKey, grayedHyperlinkAttrs); } } return grayedHyperlinkAttrs; }
Example #26
Source File: MarkupModelImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override @Nonnull public RangeHighlighter addLineHighlighter(int lineNumber, int layer, TextAttributes textAttributes) { if (isNotValidLine(lineNumber)) { throw new IndexOutOfBoundsException("lineNumber:" + lineNumber + ". Must be in [0, " + (getDocument().getLineCount() - 1) + "]"); } int offset = DocumentUtil.getFirstNonSpaceCharOffset(getDocument(), lineNumber); return addRangeHighlighter(offset, offset, layer, textAttributes, HighlighterTargetArea.LINES_IN_RANGE); }
Example #27
Source File: LexerEditorHighlighter.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private TextAttributes getAttributes(@Nonnull IElementType tokenType) { TextAttributes attrs = myAttributesMap.get(tokenType); if (attrs == null) { // let's fetch syntax highlighter attributes for token and merge them with "TEXT" attribute of current color scheme attrs = convertAttributes(myHighlighter.getTokenHighlights(tokenType)); myAttributesMap.put(tokenType, attrs); } return attrs; }
Example #28
Source File: HighlightedText.java From consulo with Apache License 2.0 | 5 votes |
public void appendText(String text, TextAttributes attributes) { int startOffset = myBuffer.length(); myBuffer.append(text); if (attributes != null) { myHighlightedRegions.add(new HighlightedRegion(startOffset, myBuffer.length(), attributes)); } }
Example #29
Source File: LayeredLexerEditorHighlighter.java From consulo with Apache License 2.0 | 5 votes |
@Override public TextAttributes getTextAttributes() { if (myCurrentMapper != null) { return myCurrentMapper.getAttributes(getTokenType()); } return myBaseIterator.getTextAttributes(); }
Example #30
Source File: RecentLocationsRenderer.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private static TextAttributes createDefaultTextAttributesWithBackground(@Nonnull EditorColorsScheme colorsScheme, @Nonnull Color backgroundColor) { TextAttributes defaultTextAttributes = new TextAttributes(); TextAttributes textAttributes = colorsScheme.getAttributes(HighlighterColors.TEXT); if (textAttributes != null) { defaultTextAttributes = textAttributes.clone(); defaultTextAttributes.setBackgroundColor(backgroundColor); } return defaultTextAttributes; }