Java Code Examples for com.intellij.openapi.editor.markup.TextAttributes#clone()

The following examples show how to use com.intellij.openapi.editor.markup.TextAttributes#clone() . 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: NavigationUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * 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 2
Source File: TodoItemNode.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void collectHighlights(@Nonnull List<? super HighlightedRegion> highlights, @Nonnull EditorHighlighter highlighter, int startOffset, int endOffset, int highlightOffsetShift) {
  HighlighterIterator iterator = highlighter.createIterator(startOffset);
  while (!iterator.atEnd()) {
    int start = Math.max(iterator.getStart(), startOffset);
    int end = Math.min(iterator.getEnd(), endOffset);
    if (start >= endOffset) break;

    TextAttributes attributes = iterator.getTextAttributes();
    int fontType = attributes.getFontType();
    if ((fontType & Font.BOLD) != 0) { // suppress bold attribute
      attributes = attributes.clone();
      attributes.setFontType(fontType & ~Font.BOLD);
    }
    HighlightedRegion region = new HighlightedRegion(highlightOffsetShift + start - startOffset, highlightOffsetShift + end - startOffset, attributes);
    highlights.add(region);
    iterator.advance();
  }
}
 
Example 3
Source File: ChunkExtractor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private TextAttributes convertAttributes(@Nonnull TextAttributesKey[] keys) {
  TextAttributes attrs = myColorsScheme.getAttributes(HighlighterColors.TEXT);

  for (TextAttributesKey key : keys) {
    TextAttributes attrs2 = myColorsScheme.getAttributes(key);
    if (attrs2 != null) {
      attrs = TextAttributes.merge(attrs, attrs2);
    }
  }

  attrs = attrs.clone();
  return attrs;
}
 
Example 4
Source File: RecentLocationsRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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 5
Source File: Filter.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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 6
Source File: BreakpointItem.java    From consulo with Apache License 2.0 5 votes vote down vote up
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 7
Source File: LivePreview.java    From consulo with Apache License 2.0 5 votes vote down vote up
private TextAttributes createAttributes(FindResult range) {
  EditorColorsScheme colorsScheme = mySearchResults.getEditor().getColorsScheme();
  if (mySearchResults.isExcluded(range)) {
    return new TextAttributes(null, null, colorsScheme.getDefaultForeground(), EffectType.STRIKEOUT, Font.PLAIN);
  }
  TextAttributes attributes = colorsScheme.getAttributes(EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES);
  if (range.getLength() == 0) {
    attributes = attributes.clone();
    attributes.setEffectType(EffectType.BOXED);
    attributes.setEffectColor(attributes.getBackgroundColor());
  }
  return attributes;
}