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

The following examples show how to use com.intellij.openapi.editor.markup.TextAttributes#setFontType() . 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: 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 2
Source File: ChunkExtractor.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void processIntersectingRange(@Nonnull UsageInfo2UsageAdapter usageInfo2UsageAdapter,
                                      @Nonnull final CharSequence chars,
                                      int hiStart,
                                      final int hiEnd,
                                      @Nonnull final TextAttributesKey[] tokenHighlights,
                                      final boolean selectUsageWithBold,
                                      @Nonnull final List<TextChunk> result) {
  final TextAttributes originalAttrs = convertAttributes(tokenHighlights);
  if (selectUsageWithBold) {
    originalAttrs.setFontType(Font.PLAIN);
  }

  final int[] lastOffset = {hiStart};
  usageInfo2UsageAdapter.processRangeMarkers(new Processor<Segment>() {
    @Override
    public boolean process(Segment segment) {
      int usageStart = segment.getStartOffset();
      int usageEnd = segment.getEndOffset();
      if (rangeIntersect(lastOffset[0], hiEnd, usageStart, usageEnd)) {
        addChunk(chars, lastOffset[0], Math.max(lastOffset[0], usageStart), originalAttrs, false, null, result);

        UsageType usageType = isHighlightedAsString(tokenHighlights) ? UsageType.LITERAL_USAGE : isHighlightedAsComment(tokenHighlights) ? UsageType.COMMENT_USAGE : null;
        addChunk(chars, Math.max(lastOffset[0], usageStart), Math.min(hiEnd, usageEnd), originalAttrs, selectUsageWithBold, usageType, result);
        lastOffset[0] = usageEnd;
        if (usageEnd > hiEnd) {
          return false;
        }
      }
      return true;
    }
  });
  if (lastOffset[0] < hiEnd) {
    addChunk(chars, lastOffset[0], hiEnd, originalAttrs, false, null, result);
  }
}
 
Example 3
Source File: RecentLocationsRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static SimpleTextAttributes createFileNameTextAttributes(@Nonnull EditorColorsScheme colorsScheme, boolean selected) {
  TextAttributes textAttributes = createDefaultTextAttributesWithBackground(colorsScheme, getBackgroundColor(colorsScheme, selected));
  textAttributes.setFontType(Font.BOLD);

  return SimpleTextAttributes.fromTextAttributes(textAttributes);
}
 
Example 4
Source File: CppHighlighter.java    From CppTools with Apache License 2.0 5 votes vote down vote up
private static TextAttributes createConstantAttributes() {
  TextAttributes attrs = new TextAttributes();

  attrs.setForegroundColor(Color.pink.darker().darker());
  attrs.setFontType(Font.ITALIC);
  return attrs;
}
 
Example 5
Source File: ColoredOutputTypeRegistry.java    From consulo with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 6
Source File: CppHighlighter.java    From CppTools with Apache License 2.0 4 votes vote down vote up
private static TextAttributes createPPSkippedAttributes() {
  TextAttributes attrs = new TextAttributes();
  attrs.setForegroundColor(new Color(0x80, 0x80, 0x80));
  attrs.setFontType(Font.ITALIC);
  return attrs;
}
 
Example 7
Source File: CppHighlighter.java    From CppTools with Apache License 2.0 4 votes vote down vote up
private static TextAttributes createStaticFunctionAttributes() {
  TextAttributes attrs = createFunctionAttributes();
  attrs.setFontType(Font.BOLD | Font.ITALIC);
  return attrs;
}
 
Example 8
Source File: CppHighlighter.java    From CppTools with Apache License 2.0 4 votes vote down vote up
private static TextAttributes createMethodAttributes() {
  TextAttributes attrs = createFunctionAttributes();
  attrs.setFontType(Font.ITALIC);
  return attrs;
}
 
Example 9
Source File: CppHighlighter.java    From CppTools with Apache License 2.0 4 votes vote down vote up
private static TextAttributes createStaticAttributes() {
  TextAttributes attrs = new TextAttributes();
  attrs.setForegroundColor(Color.black.darker().darker());
  attrs.setFontType(Font.BOLD | Font.ITALIC);
  return attrs;
}
 
Example 10
Source File: CppHighlighter.java    From CppTools with Apache License 2.0 4 votes vote down vote up
private static TextAttributes createFieldAttributes() {
  TextAttributes attrs = new TextAttributes();
  attrs.setFontType(Font.ITALIC);
  return attrs;
}
 
Example 11
Source File: CppHighlighter.java    From CppTools with Apache License 2.0 4 votes vote down vote up
private static TextAttributes createNamespaceAttributes() {
  TextAttributes attrs = new TextAttributes();
  attrs.setForegroundColor(new Color(0x90, 0, 0x90));
  attrs.setFontType(Font.BOLD);
  return attrs;
}