com.intellij.ui.speedSearch.SpeedSearchUtil Java Examples

The following examples show how to use com.intellij.ui.speedSearch.SpeedSearchUtil. 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: StringElementListCellRenderer.java    From android-strings-search-plugin with Apache License 2.0 6 votes vote down vote up
@Override
protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) {
    Color bgColor = UIUtil.getListBackground();
    setPaintFocusBorder(hasFocus && UIUtil.isToUseDottedCellBorder());

    if (value instanceof StringElement) {
        StringElement element = (StringElement) value;
        String stringKeyText = "(" + element.getName() + ")";
        String text = new StringEllipsisPolicy().ellipsizeText(element.getValue(), matcher);

        SimpleTextAttributes nameAttributes = new SimpleTextAttributes(Font.PLAIN, list.getForeground());
        SpeedSearchUtil.appendColoredFragmentForMatcher(text, this, nameAttributes, matcher, bgColor, selected);
        // TODO Change icon
        setIcon(AndroidIcons.EmptyFlag);

        append(" " + stringKeyText, new SimpleTextAttributes(Font.PLAIN, JBColor.GRAY));
    }

    setBackground(selected ? UIUtil.getListSelectionBackground() : bgColor);
}
 
Example #2
Source File: PsiElementListCellRenderer.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void appendLocationText(boolean selected, Color bgColor, boolean isProblemFile, String containerText) {
  SimpleTextAttributes locationAttrs = SimpleTextAttributes.GRAYED_ATTRIBUTES;
  if (isProblemFile) {
    SimpleTextAttributes wavedAttributes = SimpleTextAttributes.merge(new SimpleTextAttributes(SimpleTextAttributes.STYLE_WAVED, UIUtil.getInactiveTextColor(), JBColor.RED), locationAttrs);
    java.util.regex.Matcher matcher = CONTAINER_PATTERN.matcher(containerText);
    if (matcher.matches()) {
      String prefix = matcher.group(1);
      SpeedSearchUtil.appendColoredFragmentForMatcher(" " + ObjectUtils.notNull(prefix, ""), this, locationAttrs, myMatchers.locationMatcher, bgColor, selected);

      String strippedContainerText = matcher.group(2);
      SpeedSearchUtil.appendColoredFragmentForMatcher(ObjectUtils.notNull(strippedContainerText, ""), this, wavedAttributes, myMatchers.locationMatcher, bgColor, selected);

      String suffix = matcher.group(3);
      if (suffix != null) {
        SpeedSearchUtil.appendColoredFragmentForMatcher(suffix, this, locationAttrs, myMatchers.locationMatcher, bgColor, selected);
      }
      return;
    }
    locationAttrs = wavedAttributes;
  }
  SpeedSearchUtil.appendColoredFragmentForMatcher(" " + containerText, this, locationAttrs, myMatchers.locationMatcher, bgColor, selected);
}
 
Example #3
Source File: RunAnythingItemBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public Component createComponent(@Nullable String pattern, boolean isSelected, boolean hasFocus) {
  Component oldComponent = createComponent(isSelected);
  if (oldComponent != null) {
    return oldComponent;
  }

  JPanel component = new JPanel(new BorderLayout());
  Color background = UIUtil.getListBackground(isSelected, true);
  component.setBackground(background);

  SimpleColoredComponent textComponent = new SimpleColoredComponent();
  SpeedSearchUtil
          .appendColoredFragmentForMatcher(StringUtil.notNullize(getCommand()), textComponent, REGULAR_ATTRIBUTES, RunAnythingGroup.RUN_ANYTHING_MATCHER_BUILDER.fun(pattern).build(), background,
                                           isSelected);
  component.add(textComponent, BorderLayout.WEST);
  textComponent.appendTextPadding(20);
  setupIcon(textComponent, myIcon);
  addDescription(component, isSelected);

  return component;
}
 
Example #4
Source File: Switcher.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void customizeCellRenderer(@Nonnull JList<? extends FileInfo> list, FileInfo value, int index, boolean selected, boolean hasFocus) {
  Project project = mySwitcherPanel.project;
  VirtualFile virtualFile = value.getFirst();
  String renderedName = value.getNameForRendering();
  setIcon(VfsIconUtil.getIcon(virtualFile, Iconable.ICON_FLAG_READ_STATUS, project));

  FileStatus fileStatus = FileStatusManager.getInstance(project).getStatus(virtualFile);
  open = FileEditorManager.getInstance(project).isFileOpen(virtualFile);

  boolean hasProblem = WolfTheProblemSolver.getInstance(project).isProblemFile(virtualFile);
  TextAttributes attributes = new TextAttributes(fileStatus.getColor(), null, hasProblem ? JBColor.red : null, EffectType.WAVE_UNDERSCORE, Font.PLAIN);
  append(renderedName, SimpleTextAttributes.fromTextAttributes(attributes));

  // calc color the same way editor tabs do this, i.e. including EPs
  Color color = EditorTabPresentationUtil.getFileBackgroundColor(project, virtualFile);

  if (!selected && color != null) {
    setBackground(color);
  }
  SpeedSearchUtil.applySpeedSearchHighlighting(mySwitcherPanel, this, false, selected);

  IdeDocumentHistoryImpl.appendTimestamp(project, this, virtualFile);
}
 
Example #5
Source File: GotoActionModel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void appendWithColoredMatches(SimpleColoredComponent nameComponent, @Nonnull String name, @Nonnull String pattern, Color fg, boolean selected) {
  SimpleTextAttributes plain = new SimpleTextAttributes(STYLE_PLAIN, fg);
  SimpleTextAttributes highlighted = new SimpleTextAttributes(null, fg, null, STYLE_SEARCH_MATCH);
  List<TextRange> fragments = new ArrayList<>();
  if (selected) {
    int matchStart = StringUtil.indexOfIgnoreCase(name, pattern, 0);
    if (matchStart >= 0) {
      fragments.add(TextRange.from(matchStart, pattern.length()));
    }
  }
  SpeedSearchUtil.appendColoredFragments(nameComponent, name, fragments, plain, highlighted);
}
 
Example #6
Source File: ConnectionTreeCellRenderer.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
@Override
public void customizeCellRenderer(@NotNull JTree tree, Object value,
        boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    if (value instanceof DefaultMutableTreeNode) {
        Object other = ((DefaultMutableTreeNode) value).getUserObject();
        if (other != null) {
            value = other;
        }
    }
    if (value instanceof ClientConfigRoot) {
        renderClientConfigRoot((ClientConfigRoot) value);
    } else if (value instanceof P4ServerName) {
        renderP4ServerName((P4ServerName) value);
    } else if (value instanceof ClientServerRef) {
        renderClientServerRef((ClientServerRef) value);
    } else if (value instanceof PendingParentNode) {
        renderPendingParentNode((PendingParentNode) value);
    } else if (value instanceof ActionChoice) {
        renderActionChoice((ActionChoice) value);
    } else if (value instanceof FilePath) {
        renderFilePath((FilePath) value);
    } else if (value instanceof P4CommandRunner.ResultError) {
        renderResultError((P4CommandRunner.ResultError) value);
    } else {
        renderError(value);
    }

    SpeedSearchUtil.applySpeedSearchHighlighting(tree, this, true, selected);
}
 
Example #7
Source File: VcsLogGraphTable.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void customizeCellRenderer(JTable table, Object value, boolean selected, boolean hasFocus, int row, int column) {
  setBorder(null);
  if (value == null) {
    return;
  }
  append(value.toString(), applyHighlighters(this, row, column, hasFocus, selected));
  SpeedSearchUtil.applySpeedSearchHighlighting(table, this, false, selected);
}
 
Example #8
Source File: LookupCellRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void renderItemName(LookupElement item, Color foreground, boolean selected, @SimpleTextAttributes.StyleAttributeConstant int style, String name, final SimpleColoredComponent nameComponent) {
  final SimpleTextAttributes base = new SimpleTextAttributes(style, foreground);

  final String prefix = item instanceof EmptyLookupItem ? "" : myLookup.itemPattern(item);
  if (prefix.length() > 0) {
    Iterable<TextRange> ranges = getMatchingFragments(prefix, name);
    if (ranges != null) {
      SimpleTextAttributes highlighted = new SimpleTextAttributes(style, selected ? SELECTED_PREFIX_FOREGROUND_COLOR : PREFIX_FOREGROUND_COLOR);
      SpeedSearchUtil.appendColoredFragments(nameComponent, name, ranges, base, highlighted);
      return;
    }
  }
  nameComponent.append(name, base);
}
 
Example #9
Source File: ChangesBrowserNodeRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void customizeCellRenderer(@Nonnull JTree tree,
                                  Object value,
                                  boolean selected,
                                  boolean expanded,
                                  boolean leaf,
                                  int row,
                                  boolean hasFocus) {
  ChangesBrowserNode node = (ChangesBrowserNode)value;
  node.render(this, selected, expanded, hasFocus);
  SpeedSearchUtil.applySpeedSearchHighlighting(tree, this, true, selected);
}
 
Example #10
Source File: InspectionListCellRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean sel, boolean focus) {
  final JPanel panel = new JPanel(new BorderLayout());
  panel.setOpaque(true);

  final Color bg = sel ? UIUtil.getListSelectionBackground() : UIUtil.getListBackground();
  final Color fg = sel ? UIUtil.getListSelectionForeground() : UIUtil.getListForeground();
  panel.setBackground(bg);
  panel.setForeground(fg);

  SimpleTextAttributes attr = sel ? SELECTED : PLAIN;
  if (value instanceof InspectionToolWrapper) {
    final InspectionToolWrapper toolWrapper = (InspectionToolWrapper)value;
    final SimpleColoredComponent c = new SimpleColoredComponent();
    SpeedSearchUtil.appendColoredFragmentForMatcher("  " + toolWrapper.getDisplayName(), c, attr, myMatcher, bg, sel);
    panel.add(c, BorderLayout.WEST);

    final SimpleColoredComponent group = new SimpleColoredComponent();
    SpeedSearchUtil.appendColoredFragmentForMatcher(toolWrapper.getGroupDisplayName() + "  ", group, attr, myMatcher, bg, sel);
    final JPanel right = new JPanel(new BorderLayout());
    right.setBackground(bg);
    right.setForeground(fg);
    right.add(group, BorderLayout.CENTER);
    final JLabel icon = new JLabel(TargetAWT.to(getIcon(toolWrapper)));
    icon.setBackground(bg);
    icon.setForeground(fg);
    right.add(icon, BorderLayout.EAST);
    panel.add(right, BorderLayout.EAST);
  }
  else {
    // E.g. "..." item
    return super.getListCellRendererComponent(list, value, index, sel, focus);
  }

  return panel;
}
 
Example #11
Source File: UiInspectorAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
@RequiredUIAccess
@Override
public void customizeCellRenderer(@Nonnull JTree tree,
                                  Object value,
                                  boolean selected,
                                  boolean expanded,
                                  boolean leaf,
                                  int row,
                                  boolean hasFocus) {
  Color foreground = selected ? UIUtil.getTreeSelectionForeground() : UIUtil.getTreeForeground();
  Color background = selected ? UIUtil.getTreeSelectionBackground() : null;
  if (value instanceof HierarchyTree.ComponentNode) {
    HierarchyTree.ComponentNode componentNode = (HierarchyTree.ComponentNode)value;
    Component component = componentNode.getComponent();

    if (!selected) {
      if (!component.isVisible()) {
        foreground = JBColor.GRAY;
      }
      else if (component.getWidth() == 0 || component.getHeight() == 0) {
        foreground = new JBColor(new Color(128, 10, 0), JBColor.BLUE);
      }
      else if (component.getPreferredSize() != null &&
               (component.getSize().width < component.getPreferredSize().width
                || component.getSize().height < component.getPreferredSize().height)) {
        foreground = JBColor.BLUE;
      }

      if (myInitialSelection == componentNode.getComponent()) {
        background = new Color(31, 128, 8, 58);
      }
    }
    append(getComponentName(component));
    append(": " + RectangleRenderer.toString(component.getBounds()), SimpleTextAttributes.GRAYED_ATTRIBUTES);
    if (component.isOpaque()) {
      append(", opaque", SimpleTextAttributes.GRAYED_ATTRIBUTES);
    }
    if (component.isDoubleBuffered()) {
      append(", double-buffered", SimpleTextAttributes.GRAYED_ATTRIBUTES);
    }
    componentNode.setText(toString());
    setIcon(createColorIcon(component.getForeground(), component.getBackground()));
  }
  if (value instanceof HierarchyTree.ClickInfoNode) {
    append(value.toString());
    setIcon(AllIcons.Ide.Rating);
  }

  setForeground(foreground);
  setBackground(background);

  SpeedSearchUtil.applySpeedSearchHighlighting(tree, this, false, selected);
}
 
Example #12
Source File: PreviewView.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
void appendSearch(@NotNull String text, @NotNull SimpleTextAttributes attributes) {
  SpeedSearchUtil.appendFragmentsForSpeedSearch(tree, text, attributes, selected, this);
}
 
Example #13
Source File: MemberChooserObjectBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void renderTreeNode(SimpleColoredComponent component, JTree tree) {
  SpeedSearchUtil.appendFragmentsForSpeedSearch(tree, getText(), getTextAttributes(tree), false, component);
  component.setIcon(myIcon);
}
 
Example #14
Source File: RecentLocationsRenderer.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
private static SimpleColoredComponent createTitleTextComponent(@Nonnull Project project,
                                                               @Nonnull JList<? extends RecentLocationItem> list,
                                                               @Nonnull SpeedSearch speedSearch,
                                                               @Nonnull IdeDocumentHistoryImpl.PlaceInfo placeInfo,
                                                               @Nonnull EditorColorsScheme colorsScheme,
                                                               @Nullable String breadcrumbText,
                                                               boolean selected) {
  SimpleColoredComponent titleTextComponent = new SimpleColoredComponent();

  String fileName = placeInfo.getFile().getName();
  String text = fileName;
  titleTextComponent.append(fileName, createFileNameTextAttributes(colorsScheme, selected));

  if (StringUtil.isNotEmpty(breadcrumbText) && !StringUtil.equals(breadcrumbText, fileName)) {
    text += " " + breadcrumbText;
    titleTextComponent.append("  ");
    titleTextComponent.append(breadcrumbText, createBreadcrumbsTextAttributes(colorsScheme, selected));
  }

  Image icon = fetchIcon(project, placeInfo);

  if (icon != null) {
    titleTextComponent.setIcon(icon);
    titleTextComponent.setIconTextGap(4);
  }

  titleTextComponent.setBorder(JBUI.Borders.empty());

  if (!SystemInfo.isWindows) {
    titleTextComponent.setFont(FontUtil.minusOne(UIUtil.getLabelFont()));
  }

  if (speedSearch.matchingFragments(text) != null) {
    SpeedSearchUtil.applySpeedSearchHighlighting(list, titleTextComponent, false, selected);
  }

  long timeStamp = placeInfo.getTimeStamp();
  if (UISettings.getInstance().getShowInplaceComments() && Registry.is("show.last.visited.timestamps") && timeStamp != -1) {
    titleTextComponent.append(" " + DateFormatUtil.formatPrettyDateTime(timeStamp), SimpleTextAttributes.GRAYED_SMALL_ATTRIBUTES);
  }

  return titleTextComponent;
}
 
Example #15
Source File: GraphCommitCellRenderer.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void appendText(@Nonnull GraphCommitCell cell, @Nonnull SimpleTextAttributes style, boolean isSelected) {
  myIssueLinkRenderer.appendTextWithLinks(StringUtil.replace(cell.getText(), "\t", " ").trim(), style);
  SpeedSearchUtil.applySpeedSearchHighlighting(myGraphTable, this, false, isSelected);
}
 
Example #16
Source File: P4HistoryProvider.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
protected void customizeCellRenderer(JTable table, Object value, boolean selected, boolean hasFocus, int row, int column) {
    this.setOpaque(selected);
    this.append(value == null ? "?" : value.toString());
    SpeedSearchUtil.applySpeedSearchHighlighting(table, this, false, selected);
}
 
Example #17
Source File: PreviewView.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
void appendSearch(@NotNull String text, @NotNull SimpleTextAttributes attributes) {
  SpeedSearchUtil.appendFragmentsForSpeedSearch(tree, text, attributes, selected, this);
}