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

The following examples show how to use com.intellij.openapi.editor.markup.TextAttributes#setForegroundColor() . 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: CppHighlighter.java    From CppTools with Apache License 2.0 5 votes vote down vote up
private static TextAttributes createUnusedAttributes() {
  TextAttributes attrs = new TextAttributes();
  attrs.setForegroundColor(Color.darkGray);
  attrs.setEffectType(EffectType.STRIKEOUT);

  return attrs;
}
 
Example 3
Source File: NodeRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
private SimpleTextAttributes addColorToSimpleTextAttributes(SimpleTextAttributes simpleTextAttributes, Color color) {
  if (color != null) {
    final TextAttributes textAttributes = simpleTextAttributes.toTextAttributes();
    textAttributes.setForegroundColor(color);
    simpleTextAttributes = SimpleTextAttributes.fromTextAttributes(textAttributes);
  }
  return simpleTextAttributes;
}
 
Example 4
Source File: DesktopSelectionModelImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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 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: ScopeTreeViewPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
  Font font = UIUtil.getTreeFont();
  setFont(font.deriveFont(font.getSize() + JBUI.scale(1f)));

  if (value instanceof PackageDependenciesNode) {
    PackageDependenciesNode node = (PackageDependenciesNode)value;
    try {
      setIcon(node.getIcon());
    }
    catch (IndexNotReadyException ignore) {
    }
    final SimpleTextAttributes regularAttributes = SimpleTextAttributes.REGULAR_ATTRIBUTES;
    TextAttributes textAttributes = regularAttributes.toTextAttributes();
    if (node instanceof BasePsiNode && ((BasePsiNode)node).isDeprecated()) {
      textAttributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.DEPRECATED_ATTRIBUTES).clone();
    }
    final PsiElement psiElement = node.getPsiElement();
    textAttributes.setForegroundColor(CopyPasteManager.getInstance().isCutElement(psiElement) ? CopyPasteManager.CUT_COLOR : node.getColor());
    append(node.toString(), SimpleTextAttributes.fromTextAttributes(textAttributes));

    String oldToString = toString();
    if (!myProject.isDisposed()) {
      for (ProjectViewNodeDecorator decorator : Extensions.getExtensions(ProjectViewNodeDecorator.EP_NAME, myProject)) {
        decorator.decorate(node, this);
      }
    }
    if (toString().equals(oldToString)) {   // nothing was decorated
      final String locationString = node.getComment();
      if (locationString != null && locationString.length() > 0) {
        append(" (" + locationString + ")", SimpleTextAttributes.GRAY_ATTRIBUTES);
      }
    }
  }
}
 
Example 7
Source File: GeneratorDialog.java    From idea-gitignore with MIT License 5 votes vote down vote up
/**
 * 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 8
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 9
Source File: CppHighlighter.java    From CppTools with Apache License 2.0 4 votes vote down vote up
private static TextAttributes createPPArgAttributes() {
  TextAttributes attrs = new TextAttributes();
  attrs.setForegroundColor(new Color(0x80, 0, 0));
  return attrs;
}
 
Example 10
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;
}
 
Example 11
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 12
Source File: CppHighlighter.java    From CppTools with Apache License 2.0 4 votes vote down vote up
private static TextAttributes createFunctionAttributes() {
  TextAttributes attrs = new TextAttributes();
  attrs.setForegroundColor(Color.blue);
  return attrs;
}
 
Example 13
Source File: CppHighlighter.java    From CppTools with Apache License 2.0 4 votes vote down vote up
private static TextAttributes createMacrosAttributes() {
  TextAttributes attrs = new TextAttributes();
  attrs.setForegroundColor(new Color(0xa5, 0x2a, 0x2a));
  return attrs;
}
 
Example 14
Source File: CppHighlighter.java    From CppTools with Apache License 2.0 4 votes vote down vote up
private static TextAttributes createTypeAttributes() {
  TextAttributes attrs = new TextAttributes();
  attrs.setForegroundColor(Color.green.darker().darker());
  return attrs;
}
 
Example 15
Source File: CppHighlighter.java    From CppTools with Apache License 2.0 4 votes vote down vote up
private static TextAttributes createLabelAttributes() {
  TextAttributes attrs = new TextAttributes();
  attrs.setForegroundColor(Color.magenta);
  return attrs;
}
 
Example 16
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 17
Source File: TodoPackageNode.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected void update(PresentationData data) {
  super.update(data);
  final PackageElement packageElement = getValue();

  try {
    if (packageElement == null || !packageElement.getPackage().isValid()) {
      setValue(null);
      return;
    }

    int fileCount = getFileCount(packageElement);
    if (fileCount == 0){
      setValue(null);
      return;
    }

    PsiPackage aPackage = packageElement.getPackage();
    String newName;
    if (getStructure().areFlattenPackages()) {
      newName = aPackage.getQualifiedName();
    }
    else {
      newName = myPresentationName != null ? myPresentationName : "";
    }

    int nameEndOffset = newName.length();
    int todoItemCount = getTodoItemCount(packageElement);
    newName = IdeBundle.message("node.todo.group", todoItemCount);

    myHighlightedRegions.clear();

    TextAttributes textAttributes = new TextAttributes();
    Color newColor = null;

    if (CopyPasteManager.getInstance().isCutElement(packageElement)) {
      newColor = CopyPasteManager.CUT_COLOR;
    }
    textAttributes.setForegroundColor(newColor);
    myHighlightedRegions.add(new HighlightedRegion(0, nameEndOffset, textAttributes));

    EditorColorsScheme colorsScheme = UsageTreeColorsScheme.getInstance().getScheme();
    myHighlightedRegions.add(
      new HighlightedRegion(nameEndOffset, newName.length(), colorsScheme.getAttributes(UsageTreeColors.NUMBER_OF_USAGES)));

    data.setPresentableText(newName);
  }
  catch (IndexNotReadyException e) {
    LOG.info(e);
    data.setPresentableText("N/A");
  }
}
 
Example 18
Source File: RainbowHighlighter.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static  TextAttributes createRainbowAttribute(@Nullable Color color) {
  TextAttributes ret = new TextAttributes();
  ret.setForegroundColor(color);
  return ret;
}
 
Example 19
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;
}