Java Code Examples for com.intellij.openapi.editor.colors.EditorColorsScheme#getAttributes()

The following examples show how to use com.intellij.openapi.editor.colors.EditorColorsScheme#getAttributes() . 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: CsvColorSettings.java    From intellij-csv-validator with Apache License 2.0 6 votes vote down vote up
public static TextAttributes getTextAttributesOfColumn(int columnIndex, UserDataHolder userDataHolder) {
    List<TextAttributes> textAttributeList = userDataHolder.getUserData(COLUMN_HIGHLIGHT_TEXT_ATTRIBUTES_KEY);
    if (textAttributeList == null) {
        EditorColorsScheme editorColorsScheme = EditorColorsManager.getInstance().getGlobalScheme();
        textAttributeList = new ArrayList<>();
        int maxIndex = 0;
        for (int colorDescriptorIndex = 0; colorDescriptorIndex < MAX_COLUMN_HIGHLIGHT_COLORS; ++colorDescriptorIndex) {
            TextAttributesKey textAttributesKey = COLUMN_HIGHLIGHT_ATTRIBUTES.get(colorDescriptorIndex);
            TextAttributes textAttributes = editorColorsScheme.getAttributes(textAttributesKey);
            textAttributeList.add(textAttributes);
            if (!textAttributesKey.getDefaultAttributes().equals(textAttributes)) {
                maxIndex = colorDescriptorIndex;
            }
        }
        textAttributeList = textAttributeList.subList(0, maxIndex + 1);
        userDataHolder.putUserData(COLUMN_HIGHLIGHT_TEXT_ATTRIBUTES_KEY, textAttributeList);
    }
    return textAttributeList.isEmpty() ? null : textAttributeList.get(columnIndex % textAttributeList.size());
}
 
Example 2
Source File: HighlightingUtil.java    From needsmoredojo with Apache License 2.0 6 votes vote down vote up
public static void highlightElement(Editor editor, @NotNull com.intellij.openapi.project.Project project, @NotNull PsiElement[] elements)
{
    final HighlightManager highlightManager =
            HighlightManager.getInstance(project);
    final EditorColorsManager editorColorsManager =
            EditorColorsManager.getInstance();
    final EditorColorsScheme globalScheme =
            editorColorsManager.getGlobalScheme();
    final TextAttributes textattributes =
            globalScheme.getAttributes(
                    EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES);

    highlightManager.addOccurrenceHighlights(
            editor, elements, textattributes, true, null);
    final WindowManager windowManager = WindowManager.getInstance();
    final StatusBar statusBar = windowManager.getStatusBar(project);
    statusBar.setInfo("Press Esc to remove highlighting");
}
 
Example 3
Source File: HighlightData.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void addHighlToView(final Editor view, EditorColorsScheme scheme, final Map<TextAttributesKey,String> displayText) {

    // XXX: Hack
    if (HighlighterColors.BAD_CHARACTER.equals(myHighlightType)) {
      return;
    }

    final TextAttributes attr = scheme.getAttributes(myHighlightType);
    if (attr != null) {
      UIUtil.invokeAndWaitIfNeeded((Runnable)() -> {
        try {
          // IDEA-53203: add ERASE_MARKER for manually defined attributes
          view.getMarkupModel().addRangeHighlighter(myStartOffset, myEndOffset, HighlighterLayer.ADDITIONAL_SYNTAX,
                                                    TextAttributes.ERASE_MARKER, HighlighterTargetArea.EXACT_RANGE);
          RangeHighlighter highlighter = view.getMarkupModel()
                  .addRangeHighlighter(myStartOffset, myEndOffset, HighlighterLayer.ADDITIONAL_SYNTAX, attr,
                                       HighlighterTargetArea.EXACT_RANGE);
          final Color errorStripeColor = attr.getErrorStripeColor();
          highlighter.setErrorStripeMarkColor(errorStripeColor);
          final String tooltip = displayText.get(myHighlightType);
          highlighter.setErrorStripeTooltip(tooltip);
        }
        catch (Exception e) {
          throw new RuntimeException(e);
        }
      });
    }
  }
 
Example 4
Source File: OREditorLinePainter.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
@Nullable
@Override
public Collection<LineExtensionInfo> getLineExtensions(@NotNull Project project, @NotNull VirtualFile file, int lineNumber) {
    //long start = System.currentTimeMillis();

    CodeLensView.CodeLensInfo data = project.getUserData(CodeLensView.CODE_LENS);
    if (data == null) {
        return null;
    }

    if (ServiceManager.getService(project, ErrorsManager.class).hasErrors(file.getName(), lineNumber + 1)) {
        return null;
    }

    Collection<LineExtensionInfo> info = null;

    String signature = data.get(file, lineNumber);
    if (signature != null) {
        EditorColorsScheme globalScheme = EditorColorsManager.getInstance().getGlobalScheme();
        TextAttributes codeLens = globalScheme.getAttributes(ORSyntaxHighlighter.CODE_LENS_);
        info = Collections.singletonList(new LineExtensionInfo("  " + signature, codeLens));
    }

    //long end = System.currentTimeMillis();
    //System.out.println("line extensions in " + (end - start) + "ms");
    return info;
}
 
Example 5
Source File: SeverityUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static SeverityRegistrar.SeverityBasedTextAttributes getSeverityBasedTextAttributes(@Nonnull SeverityRegistrar registrar, @Nonnull HighlightInfoType type) {
  final EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
  final TextAttributes textAttributes = scheme.getAttributes(type.getAttributesKey());
  if (textAttributes != null) {
    return new SeverityRegistrar.SeverityBasedTextAttributes(textAttributes, (HighlightInfoType.HighlightInfoTypeImpl)type);
  }
  return new SeverityRegistrar.SeverityBasedTextAttributes(registrar.getTextAttributesBySeverity(type.getSeverity(null)), (HighlightInfoType.HighlightInfoTypeImpl)type);
}
 
Example 6
Source File: BraceHighlightingHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void highlightBrace(@Nonnull TextRange braceRange, boolean matched) {
  EditorColorsScheme scheme = myEditor.getColorsScheme();
  final TextAttributes attributes =
          matched ? scheme.getAttributes(CodeInsightColors.MATCHED_BRACE_ATTRIBUTES)
                  : scheme.getAttributes(CodeInsightColors.UNMATCHED_BRACE_ATTRIBUTES);


  RangeHighlighter rbraceHighlighter =
          myEditor.getMarkupModel().addRangeHighlighter(
                  braceRange.getStartOffset(), braceRange.getEndOffset(), HighlighterLayer.LAST + 1, attributes, HighlighterTargetArea.EXACT_RANGE);
  rbraceHighlighter.setGreedyToLeft(false);
  rbraceHighlighter.setGreedyToRight(false);
  registerHighlighter(rbraceHighlighter);
}
 
Example 7
Source File: ExecutionPointHighlighter.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void addHighlighter() {
  disableMouseHoverPopups(myEditor, true);
  int line = mySourcePosition.getLine();
  Document document = myEditor.getDocument();
  if (line < 0 || line >= document.getLineCount()) return;

  //if (myNotTopFrame) {
  //  myEditor.getSelectionModel().setSelection(document.getLineStartOffset(line), document.getLineEndOffset(line) + document.getLineSeparatorLength(line));
  //  return;
  //}

  if (myRangeHighlighter != null) return;

  EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
  TextAttributes attributes = myNotTopFrame ? scheme.getAttributes(DebuggerColors.NOT_TOP_FRAME_ATTRIBUTES) : scheme.getAttributes(DebuggerColors.EXECUTIONPOINT_ATTRIBUTES);
  MarkupModel markupModel = DocumentMarkupModel.forDocument(document, myProject, true);
  if (mySourcePosition instanceof HighlighterProvider) {
    TextRange range = ((HighlighterProvider)mySourcePosition).getHighlightRange();
    if (range != null) {
      TextRange lineRange = DocumentUtil.getLineTextRange(document, line);
      if (!range.equals(lineRange)) {
        myRangeHighlighter = markupModel.addRangeHighlighter(range.getStartOffset(), range.getEndOffset(), DebuggerColors.EXECUTION_LINE_HIGHLIGHTERLAYER, attributes, HighlighterTargetArea.EXACT_RANGE);
      }
    }
  }
  if (myRangeHighlighter == null) {
    myRangeHighlighter = markupModel.addLineHighlighter(line, DebuggerColors.EXECUTION_LINE_HIGHLIGHTERLAYER, attributes);
  }
  myRangeHighlighter.putUserData(EXECUTION_POINT_HIGHLIGHTER_TOP_FRAME_KEY, !myNotTopFrame);
  myRangeHighlighter.setEditorFilter(MarkupEditorFilterFactory.createIsNotDiffFilter());
  myRangeHighlighter.setGutterIconRenderer(myGutterIconRenderer);
}
 
Example 8
Source File: AbstractValueHint.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void invokeHint(Runnable hideRunnable) {
  myHideRunnable = hideRunnable;

  if (!canShowHint()) {
    hideHint();
    return;
  }

  if (myType == ValueHintType.MOUSE_ALT_OVER_HINT) {
    EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
    TextAttributes attributes = scheme.getAttributes(EditorColors.REFERENCE_HYPERLINK_COLOR);
    attributes = NavigationUtil.patchAttributesColor(attributes, myCurrentRange, myEditor);

    myHighlighter = myEditor.getMarkupModel().addRangeHighlighter(myCurrentRange.getStartOffset(), myCurrentRange.getEndOffset(),
                                                                  HighlighterLayer.SELECTION + 1, attributes,
                                                                  HighlighterTargetArea.EXACT_RANGE);
    Component internalComponent = myEditor.getContentComponent();
    myStoredCursor = internalComponent.getCursor();
    internalComponent.addKeyListener(myEditorKeyListener);
    internalComponent.setCursor(hintCursor());
    if (LOG.isDebugEnabled()) {
      LOG.debug("internalComponent.setCursor(hintCursor())");
    }
  }
  else {
    evaluateAndShowHint();
  }
}
 
Example 9
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 10
Source File: RecentLocationsRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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 11
Source File: NodeRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static SimpleTextAttributes getSimpleTextAttributes(@Nullable final ItemPresentation presentation,
                                                           @Nonnull EditorColorsScheme colorsScheme)
{
  if (presentation instanceof ColoredItemPresentation) {
    final TextAttributesKey textAttributesKey = ((ColoredItemPresentation) presentation).getTextAttributesKey();
    if (textAttributesKey == null) return SimpleTextAttributes.REGULAR_ATTRIBUTES;
    final TextAttributes textAttributes = colorsScheme.getAttributes(textAttributesKey);
    return textAttributes == null ? SimpleTextAttributes.REGULAR_ATTRIBUTES : SimpleTextAttributes.fromTextAttributes(textAttributes);
  }
  return SimpleTextAttributes.REGULAR_ATTRIBUTES;
}
 
Example 12
Source File: FragmentedEditorHighlighter.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean isUsualAttributes(final TextAttributes ta) {
  if (myUsualAttributes == null) {
    final EditorColorsManager manager = EditorColorsManager.getInstance();
    final EditorColorsScheme[] schemes = manager.getAllSchemes();
    EditorColorsScheme defaultScheme = schemes[0];
    for (EditorColorsScheme scheme : schemes) {
      if (manager.isDefaultScheme(scheme)) {
        defaultScheme = scheme;
        break;
      }
    }
    myUsualAttributes = defaultScheme.getAttributes(HighlighterColors.TEXT);
  }
  return myUsualAttributes.equals(ta);
}
 
Example 13
Source File: FlutterLogView.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 14
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;
}
 
Example 15
Source File: HighlightHelper.java    From PackageTemplates with Apache License 2.0 5 votes vote down vote up
public static void applyHighlightRange(ArrayList<TextRange> ranges, Project project, Editor editor) {
    if (project == null) {
        return;
    }

    EditorColorsScheme scheme = editor.getColorsScheme();
    TextAttributes attributes = scheme.getAttributes(TemplateColors.TEMPLATE_VARIABLE_ATTRIBUTES);

    for (TextRange textRange : ranges) {
        HighlightManager.getInstance(project).addRangeHighlight(
                editor, textRange.getBegin(), textRange.getEnd(), attributes, true, null);
    }
}
 
Example 16
Source File: TextDiffType.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
public TextAttributes getTextAttributes(EditorColorsScheme scheme) {
  return scheme.getAttributes(myAttributesKey);
}
 
Example 17
Source File: TextDiffType.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
public Color getLegendColor(EditorColorsScheme colorScheme) {
  TextAttributes attributes = colorScheme.getAttributes(myAttributesKey);
  return attributes != null ? attributes.getBackgroundColor() : null;
}
 
Example 18
Source File: RecentLocationsRenderer.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
private static TextAttributes createEmptyTextForegroundTextAttributes(@Nonnull EditorColorsScheme colorsScheme) {
  TextAttributes unusedAttributes = colorsScheme.getAttributes(CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES);
  return unusedAttributes != null ? unusedAttributes : SimpleTextAttributes.GRAYED_ATTRIBUTES.toTextAttributes();
}
 
Example 19
Source File: BlameUiServiceImpl.java    From GitToolBox with Apache License 2.0 4 votes vote down vote up
@Override
public void colorsSchemeChanged(@NotNull EditorColorsScheme colorsScheme) {
  blameTextAttributes = colorsScheme.getAttributes(ATTRIBUTES_KEY);
  log.debug("Color scheme updated");
}
 
Example 20
Source File: BraceHighlightingHandler.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void highlightBraces(@Nullable TextRange lBrace, @Nullable TextRange rBrace, boolean matched, boolean scopeHighlighting, @Nonnull FileType fileType) {
  if (!matched && fileType == PlainTextFileType.INSTANCE) {
    return;
  }

  EditorColorsScheme scheme = myEditor.getColorsScheme();
  final TextAttributes attributes =
          matched ? scheme.getAttributes(CodeInsightColors.MATCHED_BRACE_ATTRIBUTES)
                  : scheme.getAttributes(CodeInsightColors.UNMATCHED_BRACE_ATTRIBUTES);

  if (rBrace != null && !scopeHighlighting) {
    highlightBrace(rBrace, matched);
  }

  if (lBrace != null && !scopeHighlighting) {
    highlightBrace(lBrace, matched);
  }

  FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject); // null in default project
  if (fileEditorManager == null || !myEditor.equals(fileEditorManager.getSelectedTextEditor())) {
    return;
  }

  if (lBrace != null && rBrace !=null) {
    final int startLine = myEditor.offsetToLogicalPosition(lBrace.getStartOffset()).line;
    final int endLine = myEditor.offsetToLogicalPosition(rBrace.getEndOffset()).line;
    if (endLine - startLine > 0) {
      final Runnable runnable = () -> {
        if (myProject.isDisposed() || myEditor.isDisposed()) return;
        Color color = attributes.getBackgroundColor();
        if (color == null) return;
        color = ColorUtil.isDark(EditorColorsManager.getInstance().getGlobalScheme().getDefaultBackground()) ? ColorUtil.shift(color, 1.5d) : color.darker();
        lineMarkFragment(startLine, endLine, color);
      };

      if (!scopeHighlighting) {
        myAlarm.addRequest(runnable, 300);
      }
      else {
        runnable.run();
      }
    }
    else {
      removeLineMarkers();
    }

    if (!scopeHighlighting) {
      showScopeHint(lBrace.getStartOffset(), lBrace.getEndOffset());
    }
  }
  else {
    if (!myCodeInsightSettings.HIGHLIGHT_SCOPE) {
      removeLineMarkers();
    }
  }
}