Java Code Examples for com.intellij.openapi.editor.markup.TextAttributes#setBackgroundColor()
The following examples show how to use
com.intellij.openapi.editor.markup.TextAttributes#setBackgroundColor() .
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: CommentsDiffTool.java From review-board-idea-plugin with Apache License 2.0 | 5 votes |
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); } }
Example 2
Source File: EditorDocOps.java From KodeBeagle with Apache License 2.0 | 5 votes |
public final void addHighlighting(final List<Integer> linesForHighlighting, final Document document) { TextAttributes attributes = new TextAttributes(); JBColor color = JBColor.GREEN; attributes.setEffectColor(color); attributes.setEffectType(EffectType.SEARCH_MATCH); attributes.setBackgroundColor(HIGHLIGHTING_COLOR); Editor projectEditor = FileEditorManager.getInstance(windowObjects.getProject()).getSelectedTextEditor(); if (projectEditor != null) { PsiFile psiFile = PsiDocumentManager.getInstance(windowObjects.getProject()). getPsiFile(projectEditor.getDocument()); MarkupModel markupModel = projectEditor.getMarkupModel(); if (markupModel != null) { markupModel.removeAllHighlighters(); for (int line : linesForHighlighting) { line = line - 1; if (line < document.getLineCount()) { int startOffset = document.getLineStartOffset(line); int endOffset = document.getLineEndOffset(line); String lineText = document.getCharsSequence(). subSequence(startOffset, endOffset).toString(); int lineStartOffset = startOffset + lineText.length() - lineText.trim().length(); markupModel.addRangeHighlighter(lineStartOffset, endOffset, HighlighterLayer.ERROR, attributes, HighlighterTargetArea.EXACT_RANGE); if (psiFile != null && psiFile.findElementAt(lineStartOffset) != null) { HighlightUsagesHandler.doHighlightElements(projectEditor, new PsiElement[]{psiFile.findElementAt(lineStartOffset)}, attributes, false); } } } } } }
Example 3
Source File: GeneratorDialog.java From idea-gitignore with MIT License | 5 votes |
/** * Highlights given text ranges in {@link #preview} content. * * @param pairs text ranges */ private void highlightWords(@NotNull List<Pair<Integer, Integer>> pairs) { final TextAttributes attr = new TextAttributes(); attr.setBackgroundColor(UIUtil.getTreeSelectionBackground(true)); attr.setForegroundColor(UIUtil.getTreeSelectionForeground(true)); for (Pair<Integer, Integer> pair : pairs) { preview.getMarkupModel().addRangeHighlighter(pair.first, pair.second, 0, attr, HighlighterTargetArea.EXACT_RANGE); } }
Example 4
Source File: TextDiffType.java From consulo with Apache License 2.0 | 5 votes |
@Nullable public TextAttributes getTextAttributes(@Nonnull Editor editor) { TextAttributes originalAttrs = getTextAttributes(editor.getColorsScheme()); if (originalAttrs == null) { return null; } TextAttributes overridingAttributes = new TextAttributes(); if (myApplied) { overridingAttributes.setBackgroundColor(((EditorEx)editor).getBackgroundColor()); } else if (myInlineWrapper) { overridingAttributes.setBackgroundColor(getBgColorForFragmentContainingInlines((EditorEx)editor)); } return TextAttributes.merge(originalAttrs, overridingAttributes); }
Example 5
Source File: DesktopCaretModelImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override @Nonnull public TextAttributes getTextAttributes() { TextAttributes textAttributes = myTextAttributes; if (textAttributes == null) { myTextAttributes = textAttributes = new TextAttributes(); if (myEditor.getSettings().isCaretRowShown()) { textAttributes.setBackgroundColor(myEditor.getColorsScheme().getColor(EditorColors.CARET_ROW_COLOR)); } } return textAttributes; }
Example 6
Source File: DesktopSelectionModelImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public TextAttributes getTextAttributes() { if (myTextAttributes == null) { TextAttributes textAttributes = new TextAttributes(); EditorColorsScheme scheme = myEditor.getColorsScheme(); textAttributes.setForegroundColor(scheme.getColor(EditorColors.SELECTION_FOREGROUND_COLOR)); textAttributes.setBackgroundColor(scheme.getColor(EditorColors.SELECTION_BACKGROUND_COLOR)); myTextAttributes = textAttributes; } return myTextAttributes; }
Example 7
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; }
Example 8
Source File: BreakpointItem.java From consulo with Apache License 2.0 | 5 votes |
protected static void showInEditor(DetailView panel, VirtualFile virtualFile, int line) { TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(DebuggerColors.BREAKPOINT_ATTRIBUTES); DetailView.PreviewEditorState state = DetailView.PreviewEditorState.create(virtualFile, line, attributes); if (state.equals(panel.getEditorState())) { return; } panel.navigateInPreviewEditor(state); TextAttributes softerAttributes = attributes.clone(); Color backgroundColor = softerAttributes.getBackgroundColor(); if (backgroundColor != null) { softerAttributes.setBackgroundColor(ColorUtil.softer(backgroundColor)); } final Editor editor = panel.getEditor(); final MarkupModel editorModel = editor.getMarkupModel(); final MarkupModel documentModel = DocumentMarkupModel.forDocument(editor.getDocument(), editor.getProject(), false); for (RangeHighlighter highlighter : documentModel.getAllHighlighters()) { if (highlighter.getUserData(DebuggerColors.BREAKPOINT_HIGHLIGHTER_KEY) == Boolean.TRUE) { final int line1 = editor.offsetToLogicalPosition(highlighter.getStartOffset()).line; if (line1 != line) { editorModel.addLineHighlighter(line1, DebuggerColors.BREAKPOINT_HIGHLIGHTER_LAYER + 1, softerAttributes); } } } }
Example 9
Source File: BreadcrumbsWrapper.java From consulo with Apache License 2.0 | 5 votes |
private void itemHovered(Crumb crumb, @SuppressWarnings("unused") InputEvent event) { if (!Registry.is("editor.breadcrumbs.highlight.on.hover")) { return; } HighlightManager hm = HighlightManager.getInstance(myProject); if (myHighlighed != null) { for (RangeHighlighter highlighter : myHighlighed) { hm.removeSegmentHighlighter(myEditor, highlighter); } myHighlighed = null; } if (crumb instanceof NavigatableCrumb) { final TextRange range = ((NavigatableCrumb)crumb).getHighlightRange(); if (range == null) return; final TextAttributes attributes = new TextAttributes(); final CrumbPresentation p = PsiCrumb.getPresentation(crumb); Color color = p == null ? null : p.getBackgroundColor(false, false, false); if (color == null) color = BreadcrumbsComponent.ButtonSettings.getBackgroundColor(false, false, false, false); if (color == null) color = UIUtil.getLabelBackground(); final Color background = EditorColorsManager.getInstance().getGlobalScheme().getColor(EditorColors.CARET_ROW_COLOR); attributes.setBackgroundColor(makeTransparent(color, background != null ? background : Gray._200, 0.3)); myHighlighed = new ArrayList<>(1); int flags = HighlightManager.HIDE_BY_ESCAPE | HighlightManager.HIDE_BY_TEXT_CHANGE | HighlightManager.HIDE_BY_ANY_KEY; hm.addOccurrenceHighlight(myEditor, range.getStartOffset(), range.getEndOffset(), attributes, flags, myHighlighed, null); } }
Example 10
Source File: CopyCutWithoutSelectAction.java From emacsIDEAs with Apache License 2.0 | 4 votes |
private RangeHighlighter addHighlighterOnCopiedRange(TextRange tr) { TextAttributes textAttributes = new TextAttributes(); textAttributes.setBackgroundColor(SelectorFactory.HIGHLIGHT_COLOR); return _editor.getMarkupModel().addRangeHighlighter(tr.getStartOffset(), tr.getEndOffset(), HighlighterLayer.LAST + 1, textAttributes, HighlighterTargetArea.EXACT_RANGE); }
Example 11
Source File: ColoredOutputTypeRegistry.java From consulo with Apache License 2.0 | 4 votes |
public Key getOutputKey(@NonNls String attribute) { final Key key = myRegisteredKeys.get(attribute); if (key != null) { return key; } final String completeAttribute = attribute; if (attribute.startsWith("\u001B[")) { attribute = attribute.substring(2); } else if (attribute.startsWith("[")) { attribute = attribute.substring(1); } if (attribute.endsWith("m")) { attribute = attribute.substring(0, attribute.length() - 1); } if (attribute.equals("0")) { return ProcessOutputTypes.STDOUT; } TextAttributes attrs = new TextAttributes(); final String[] strings = attribute.split(";"); for (String string : strings) { int value; try { value = Integer.parseInt(string); } catch (NumberFormatException e) { continue; } if (value == 1) { attrs.setFontType(Font.BOLD); } else if (value == 4) { attrs.setEffectType(EffectType.LINE_UNDERSCORE); } else if (value == 22) { attrs.setFontType(Font.PLAIN); } else if (value == 24) { //not underlined attrs.setEffectType(null); } else if (value >= 30 && value <= 37) { attrs.setForegroundColor(getAnsiColor(value - 30)); } else if (value == 38) { //TODO: 256 colors foreground } else if (value == 39) { attrs.setForegroundColor(getColorByKey(ConsoleViewContentType.NORMAL_OUTPUT_KEY)); } else if (value >= 40 && value <= 47) { attrs.setBackgroundColor(getAnsiColor(value - 40)); } else if (value == 48) { //TODO: 256 colors background } else if (value == 49) { attrs.setBackgroundColor(getColorByKey(ConsoleViewContentType.NORMAL_OUTPUT_KEY)); } else if (value >= 90 && value <= 97) { attrs.setForegroundColor( getAnsiColor(value - 82)); } else if (value >= 100 && value <= 107) { attrs.setBackgroundColor( getAnsiColor(value - 92)); } } if (attrs.getEffectType() == EffectType.LINE_UNDERSCORE) { attrs.setEffectColor(attrs.getForegroundColor()); } Key newKey = new Key(completeAttribute); ConsoleViewContentType contentType = new ConsoleViewContentType(completeAttribute, attrs); ConsoleViewContentType.registerNewConsoleViewType(newKey, contentType); myRegisteredKeys.put(completeAttribute, newKey); return newKey; }