Java Code Examples for com.intellij.ui.SimpleTextAttributes#getStyle()

The following examples show how to use com.intellij.ui.SimpleTextAttributes#getStyle() . 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: DiagnosticsTreeCellRenderer.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void appendFragmentsForSpeedSearch(@NotNull JComponent speedSearchEnabledComponent,
                                          @NotNull String text,
                                          @NotNull SimpleTextAttributes attributes,
                                          boolean selected,
                                          @NotNull MultiIconSimpleColoredComponent simpleColoredComponent) {
  final SpeedSearchSupply speedSearch = SpeedSearchSupply.getSupply(speedSearchEnabledComponent);
  if (speedSearch != null) {
    final Iterable<TextRange> fragments = speedSearch.matchingFragments(text);
    if (fragments != null) {
      final Color fg = attributes.getFgColor();
      final Color bg = selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground();
      final int style = attributes.getStyle();
      final SimpleTextAttributes plain = new SimpleTextAttributes(style, fg);
      final SimpleTextAttributes highlighted = new SimpleTextAttributes(bg, fg, null, style | SimpleTextAttributes.STYLE_SEARCH_MATCH);
      appendColoredFragments(simpleColoredComponent, text, fragments, plain, highlighted);
      return;
    }
  }
  simpleColoredComponent.append(text, attributes);
}
 
Example 2
Source File: DiagnosticsTreeCellRenderer.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void appendFragmentsForSpeedSearch(@NotNull JComponent speedSearchEnabledComponent,
                                          @NotNull String text,
                                          @NotNull SimpleTextAttributes attributes,
                                          boolean selected,
                                          @NotNull MultiIconSimpleColoredComponent simpleColoredComponent) {
  final SpeedSearchSupply speedSearch = SpeedSearchSupply.getSupply(speedSearchEnabledComponent);
  if (speedSearch != null) {
    final Iterable<TextRange> fragments = speedSearch.matchingFragments(text);
    if (fragments != null) {
      final Color fg = attributes.getFgColor();
      final Color bg = selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground();
      final int style = attributes.getStyle();
      final SimpleTextAttributes plain = new SimpleTextAttributes(style, fg);
      final SimpleTextAttributes highlighted = new SimpleTextAttributes(bg, fg, null, style | SimpleTextAttributes.STYLE_SEARCH_MATCH);
      appendColoredFragments(simpleColoredComponent, text, fragments, plain, highlighted);
      return;
    }
  }
  simpleColoredComponent.append(text, attributes);
}
 
Example 3
Source File: SpeedSearchUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void appendFragmentsForSpeedSearch(@Nonnull JComponent speedSearchEnabledComponent,
                                                 @Nonnull String text,
                                                 @Nonnull SimpleTextAttributes attributes,
                                                 boolean selected,
                                                 @Nonnull SimpleColoredComponent simpleColoredComponent) {
  final SpeedSearchSupply speedSearch = SpeedSearchSupply.getSupply(speedSearchEnabledComponent);
  if (speedSearch != null) {
    final Iterable<TextRange> fragments = speedSearch.matchingFragments(text);
    if (fragments != null) {
      final Color fg = attributes.getFgColor();
      final Color bg = selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground();
      final int style = attributes.getStyle();
      final SimpleTextAttributes plain = new SimpleTextAttributes(style, fg);
      final SimpleTextAttributes highlighted = new SimpleTextAttributes(bg, fg, null, style | SimpleTextAttributes.STYLE_SEARCH_MATCH);
      appendColoredFragments(simpleColoredComponent, text, fragments, plain, highlighted);
      return;
    }
  }
  simpleColoredComponent.append(text, attributes);
}
 
Example 4
Source File: SpeedSearchUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void appendColoredFragmentForMatcher(@Nonnull String text,
                                                   SimpleColoredComponent component,
                                                   @Nonnull final SimpleTextAttributes attributes,
                                                   Matcher matcher,
                                                   Color selectedBg,
                                                   boolean selected) {
  if (!(matcher instanceof MinusculeMatcher) || (Registry.is("ide.highlight.match.in.selected.only") && !selected)) {
    component.append(text, attributes);
    return;
  }

  final Iterable<TextRange> iterable = ((MinusculeMatcher)matcher).matchingFragments(text);
  if (iterable != null) {
    final Color fg = attributes.getFgColor();
    final int style = attributes.getStyle();
    final SimpleTextAttributes plain = new SimpleTextAttributes(style, fg);
    final SimpleTextAttributes highlighted = new SimpleTextAttributes(selectedBg, fg, null, style | SimpleTextAttributes.STYLE_SEARCH_MATCH);
    appendColoredFragments(component, text, iterable, plain, highlighted);
  }
  else {
    component.append(text, attributes);
  }
}
 
Example 5
Source File: PushLogTreeUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static SimpleTextAttributes addTransparencyIfNeeded(@Nonnull final SimpleTextAttributes baseStyle, boolean isActive) {
  if (isActive) return baseStyle;
  Color color = baseStyle.getFgColor();
  if (color == null) {
    color = JBColor.black;
  }
  //noinspection UseJBColor
  return new SimpleTextAttributes(baseStyle.getStyle(),
                                  new Color(color.getRed(), color.getGreen(), color.getBlue(), 85));
}
 
Example 6
Source File: SpeedSearchUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static void applySpeedSearchHighlighting(@Nonnull JComponent speedSearchEnabledComponent,
                                                @Nonnull SimpleColoredComponent coloredComponent,
                                                boolean mainTextOnly,
                                                boolean selected) {
  SpeedSearchSupply speedSearch = SpeedSearchSupply.getSupply(speedSearchEnabledComponent);
  // The bad thing is that SpeedSearch model is decoupled from UI presentation so we don't know the real matched text.
  // Our best guess is to get strgin from the ColoredComponent. We can only provide main-text-only option.
  Iterable<TextRange> ranges = speedSearch == null ? null : speedSearch.matchingFragments(coloredComponent.getCharSequence(mainTextOnly).toString());
  Iterator<TextRange> rangesIterator = ranges != null ? ranges.iterator() : null;
  if (rangesIterator == null || !rangesIterator.hasNext()) return;
  Color bg = selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground();

  SimpleColoredComponent.ColoredIterator coloredIterator = coloredComponent.iterator();
  TextRange range = rangesIterator.next();
  main: while (coloredIterator.hasNext()) {
    coloredIterator.next();
    int offset = coloredIterator.getOffset();
    int endOffset = coloredIterator.getEndOffset();
    if (!range.intersectsStrict(offset, endOffset)) continue;
    SimpleTextAttributes attributes = coloredIterator.getTextAttributes();
    SimpleTextAttributes highlighted = new SimpleTextAttributes(bg, attributes.getFgColor(), null, attributes.getStyle() | SimpleTextAttributes.STYLE_SEARCH_MATCH);
    if (range.getStartOffset() > offset) {
      offset = coloredIterator.split(range.getStartOffset() - offset, attributes);
    }
    do {
      if (range.getEndOffset() <= endOffset) {
        offset = coloredIterator.split(range.getEndOffset() - offset, highlighted);
        if (rangesIterator.hasNext()) {
          range = rangesIterator.next();
        }
        else {
          break main;
        }
      }
      else {
        coloredIterator.split(endOffset - offset, highlighted);
        continue main;
      }
    }
    while (range.intersectsStrict(offset, endOffset));
  }
}
 
Example 7
Source File: IssueLinkRenderer.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static SimpleTextAttributes getLinkAttributes(final SimpleTextAttributes baseStyle) {
  return (baseStyle.getStyle() & SimpleTextAttributes.STYLE_BOLD) != 0 ?
         SimpleTextAttributes.LINK_BOLD_ATTRIBUTES : SimpleTextAttributes.LINK_ATTRIBUTES;
}
 
Example 8
Source File: InspectionTree.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static SimpleTextAttributes patchAttr(InspectionTreeNode node, SimpleTextAttributes attributes) {
  if (node.isResolved()) {
    return new SimpleTextAttributes(attributes.getBgColor(), attributes.getFgColor(), attributes.getWaveColor(), attributes.getStyle() | SimpleTextAttributes.STYLE_STRIKEOUT);
  }
  return attributes;
}