Java Code Examples for com.intellij.openapi.editor.markup.TextAttributes#getForegroundColor()
The following examples show how to use
com.intellij.openapi.editor.markup.TextAttributes#getForegroundColor() .
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: 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 2
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 3
Source File: NavigationUtil.java From consulo with Apache License 2.0 | 6 votes |
/** * Patches attributes to be visible under debugger active line */ @SuppressWarnings("UseJBColor") public static TextAttributes patchAttributesColor(TextAttributes attributes, @Nonnull TextRange range, @Nonnull Editor editor) { if (attributes.getForegroundColor() == null && attributes.getEffectColor() == null) return attributes; MarkupModel model = DocumentMarkupModel.forDocument(editor.getDocument(), editor.getProject(), false); if (model != null) { if (!((MarkupModelEx)model).processRangeHighlightersOverlappingWith(range.getStartOffset(), range.getEndOffset(), highlighter -> { if (highlighter.isValid() && highlighter.getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE) { TextAttributes textAttributes = highlighter.getTextAttributes(); if (textAttributes != null) { Color color = textAttributes.getBackgroundColor(); return !(color != null && color.getBlue() > 128 && color.getRed() < 128 && color.getGreen() < 128); } } return true; })) { TextAttributes clone = attributes.clone(); clone.setForegroundColor(Color.orange); clone.setEffectColor(Color.orange); return clone; } } return attributes; }
Example 4
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 5
Source File: SyntaxInfoBuilder.java From consulo with Apache License 2.0 | 5 votes |
private void findNextSuitableRange() { myNextAttributes = null; while (myIterator.hasNext()) { RangeHighlighterEx highlighter = myIterator.next(); if (highlighter == null || !highlighter.isValid() || !isInterestedInLayer(highlighter.getLayer())) { continue; } // LINES_IN_RANGE highlighters are not supported currently myNextStart = Math.max(highlighter.getStartOffset(), myStartOffset); myNextEnd = Math.min(highlighter.getEndOffset(), myEndOffset); if (myNextStart >= myEndOffset) { break; } if (myNextStart < myCurrentEnd) { continue; // overlapping ranges withing document markup model are not supported currently } TextAttributes attributes = null; HighlightInfo info = HighlightInfo.fromRangeHighlighter(highlighter); if (info != null) { TextAttributesKey key = info.forcedTextAttributesKey; if (key == null) { HighlightInfoType type = info.type; key = type.getAttributesKey(); } if (key != null) { attributes = myColorsScheme.getAttributes(key); } } if (attributes == null) { continue; } Color foreground = attributes.getForegroundColor(); Color background = attributes.getBackgroundColor(); if ((foreground == null || myDefaultForeground.equals(foreground)) && (background == null || myDefaultBackground.equals(background)) && attributes.getFontType() == Font.PLAIN) { continue; } myNextAttributes = attributes; break; } }
Example 6
Source File: SyntaxInfoBuilder.java From consulo with Apache License 2.0 | 5 votes |
public void advance() { if (mySegmentIterator.atEnd()) { myRangeIterator.advance(); TextAttributes textAttributes = myRangeIterator.getTextAttributes(); myCurrentFontStyle = textAttributes == null ? Font.PLAIN : textAttributes.getFontType(); myCurrentForegroundColor = textAttributes == null ? null : textAttributes.getForegroundColor(); myCurrentBackgroundColor = textAttributes == null ? null : textAttributes.getBackgroundColor(); mySegmentIterator.reset(myRangeIterator.getRangeStart(), myRangeIterator.getRangeEnd(), myCurrentFontStyle); } mySegmentIterator.advance(); }
Example 7
Source File: ParameterHintsPresentationManager.java From consulo with Apache License 2.0 | 5 votes |
@Override public void paint(@Nonnull Editor editor, @Nonnull Graphics g, @Nonnull Rectangle r, @Nonnull TextAttributes textAttributes) { if (myText != null && (step > steps || startWidth != 0)) { TextAttributes attributes = editor.getColorsScheme().getAttributes(DefaultLanguageHighlighterColors.INLINE_PARAMETER_HINT); if (attributes != null) { MyFontMetrics fontMetrics = getFontMetrics(editor); Color backgroundColor = attributes.getBackgroundColor(); if (backgroundColor != null) { GraphicsConfig config = GraphicsUtil.setupAAPainting(g); GraphicsUtil.paintWithAlpha(g, BACKGROUND_ALPHA); g.setColor(backgroundColor); int gap = r.height < (fontMetrics.lineHeight + 2) ? 1 : 2; g.fillRoundRect(r.x + 2, r.y + gap, r.width - 4, r.height - gap * 2, 8, 8); config.restore(); } Color foregroundColor = attributes.getForegroundColor(); if (foregroundColor != null) { g.setColor(foregroundColor); g.setFont(getFont(editor)); Shape savedClip = g.getClip(); g.clipRect(r.x + 3, r.y + 2, r.width - 6, r.height - 4); int editorAscent = editor.getAscent(); FontMetrics metrics = fontMetrics.metrics; g.drawString(myText, r.x + 7, r.y + Math.max(editorAscent, (r.height + metrics.getAscent() - metrics.getDescent()) / 2) - 1); g.setClip(savedClip); } } } }
Example 8
Source File: XDebuggerEditorLinePainter.java From consulo with Apache License 2.0 | 5 votes |
private static TextAttributes getTopFrameSelectedAttributes() { TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(DebuggerColors.INLINED_VALUES_EXECUTION_LINE); if (attributes == null || attributes.getForegroundColor() == null) { //noinspection UseJBColor return new TextAttributes(isDarkEditor() ? new Color(255, 235, 9) : new Color(0, 255, 86), null, null, null, Font.ITALIC); } return attributes; }
Example 9
Source File: XDebuggerEditorLinePainter.java From consulo with Apache License 2.0 | 5 votes |
public static TextAttributes getChangedAttributes() { TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(DebuggerColors.INLINED_VALUES_MODIFIED); if (attributes == null || attributes.getForegroundColor() == null) { return new TextAttributes(new JBColor(() -> isDarkEditor() ? new Color(0xa1830a) : new Color(0xca8021)), null, null, null, Font.ITALIC); } return attributes; }
Example 10
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 11
Source File: RecentLocationsRenderer.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private static SimpleTextAttributes createBreadcrumbsTextAttributes(@Nonnull EditorColorsScheme colorsScheme, boolean selected) { Color backgroundColor = getBackgroundColor(colorsScheme, selected); TextAttributes attributes = colorsScheme.getAttributes(CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES); if (attributes != null) { Color unusedForeground = attributes.getForegroundColor(); if (unusedForeground != null) { return SimpleTextAttributes.fromTextAttributes(new TextAttributes(unusedForeground, backgroundColor, null, null, Font.PLAIN)); } } return SimpleTextAttributes.fromTextAttributes(createDefaultTextAttributesWithBackground(colorsScheme, backgroundColor)); }
Example 12
Source File: LineExtensionInfo.java From consulo with Apache License 2.0 | 5 votes |
public LineExtensionInfo(@Nonnull String text, @Nonnull TextAttributes attr) { myText = text; myColor = attr.getForegroundColor(); myEffectType = attr.getEffectType(); myEffectColor = attr.getEffectColor(); myFontType = attr.getFontType(); myBgColor = attr.getBackgroundColor(); }
Example 13
Source File: SimpleTextAttributes.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public static SimpleTextAttributes fromTextAttributes(TextAttributes attributes) { if (attributes == null) return REGULAR_ATTRIBUTES; Color foregroundColor = attributes.getForegroundColor(); if (foregroundColor == null) foregroundColor = REGULAR_ATTRIBUTES.getFgColor(); int style = attributes.getFontType(); if (attributes.getEffectColor() != null) { EffectType effectType = attributes.getEffectType(); if (effectType == EffectType.STRIKEOUT) { style |= STYLE_STRIKEOUT; } else if (effectType == EffectType.WAVE_UNDERSCORE) { style |= STYLE_WAVED; } else if (effectType == EffectType.LINE_UNDERSCORE || effectType == EffectType.BOLD_LINE_UNDERSCORE || effectType == EffectType.BOLD_DOTTED_LINE) { style |= STYLE_UNDERLINE; } else if (effectType == EffectType.SEARCH_MATCH) { style |= STYLE_SEARCH_MATCH; } else { // not supported } } return new SimpleTextAttributes(attributes.getBackgroundColor(), foregroundColor, attributes.getEffectColor(), style); }
Example 14
Source File: FlutterLogView.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void computeTextAttributesByLogLevelCache() { final EditorColorsScheme globalEditorColorsScheme = EditorColorsManager.getInstance().getGlobalScheme(); textAttributesByLogLevelCache.clear(); for (Level level : FlutterLog.Level.values()) { try { final TextAttributesKey key = LOG_LEVEL_TEXT_ATTRIBUTES_KEY_MAP.get(level); final TextAttributes attributes = globalEditorColorsScheme.getAttributes(key); int fontType = attributes.getFontType(); final Color effectColor = attributes.getEffectColor(); final Integer textStyle = EFFECT_TYPE_TEXT_STYLE_MAP.get(attributes.getEffectType()); // TextStyle can exist even when unchecked in settings page. // only effectColor is null when setting effect is unchecked in setting page. // So, we have to check that both effectColor & textStyle are not null. if (effectColor != null && textStyle != null) { fontType = fontType | textStyle; } final SimpleTextAttributes textAttributes = new SimpleTextAttributes( attributes.getBackgroundColor(), attributes.getForegroundColor(), effectColor, fontType ); textAttributesByLogLevelCache.put(level, textAttributes); } catch (Exception e) { // Should never go here. FlutterUtils.warn(LOG, "Error when get text attributes by log level", e); } } }
Example 15
Source File: FlutterLogView.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void computeTextAttributesByLogLevelCache() { final EditorColorsScheme globalEditorColorsScheme = EditorColorsManager.getInstance().getGlobalScheme(); textAttributesByLogLevelCache.clear(); for (Level level : FlutterLog.Level.values()) { try { final TextAttributesKey key = LOG_LEVEL_TEXT_ATTRIBUTES_KEY_MAP.get(level); final TextAttributes attributes = globalEditorColorsScheme.getAttributes(key); int fontType = attributes.getFontType(); final Color effectColor = attributes.getEffectColor(); final Integer textStyle = EFFECT_TYPE_TEXT_STYLE_MAP.get(attributes.getEffectType()); // TextStyle can exist even when unchecked in settings page. // only effectColor is null when setting effect is unchecked in setting page. // So, we have to check that both effectColor & textStyle are not null. if (effectColor != null && textStyle != null) { fontType = fontType | textStyle; } final SimpleTextAttributes textAttributes = new SimpleTextAttributes( attributes.getBackgroundColor(), attributes.getForegroundColor(), effectColor, fontType ); textAttributesByLogLevelCache.put(level, textAttributes); } catch (Exception e) { // Should never go here. FlutterUtils.warn(LOG, "Error when get text attributes by log level", e); } } }
Example 16
Source File: MultiLineCellRenderer.java From intellij-csv-validator with Apache License 2.0 | 4 votes |
private Color getColumnForegroundColor(int column, Color fallback) { TextAttributes textAttributes = getColumnTextAttributes(column); return textAttributes == null || textAttributes.getForegroundColor() == null ? fallback : textAttributes.getForegroundColor(); }
Example 17
Source File: EditorUtil.java From consulo with Apache License 2.0 | 4 votes |
public static boolean attributesImpactFontStyleOrColor(@Nullable TextAttributes attributes) { return attributes == TextAttributes.ERASE_MARKER || (attributes != null && (attributes.getFontType() != Font.PLAIN || attributes.getForegroundColor() != null)); }
Example 18
Source File: Breadcrumbs.java From consulo with Apache License 2.0 | 4 votes |
protected Color getForeground(Crumb crumb) { TextAttributes attributes = getAttributes(crumb); Color foreground = attributes == null ? null : attributes.getForegroundColor(); return foreground != null ? foreground : getForeground(); }