/**
  * When the item is selected then we use default tree's selection foreground. It guaranties
  * readability of selected text in any LAF.
  */
 @Override
 public void append(
     @NotNull @Nls String fragment, @NotNull SimpleTextAttributes attributes, boolean isMainText) {
   if (mySelected && isFocused()) {
     super.append(
         fragment,
         new SimpleTextAttributes(attributes.getStyle(), UIUtil.getTreeSelectionForeground()),
         isMainText);
   } else if (mySelected && UIUtil.isUnderAquaBasedLookAndFeel()) {
     super.append(
         fragment,
         new SimpleTextAttributes(attributes.getStyle(), UIUtil.getTreeForeground()),
         isMainText);
   } else {
     super.append(fragment, attributes, isMainText);
   }
 }
예제 #2
0
  private int setTypeTextLabel(
      LookupElement item,
      final Color background,
      Color foreground,
      final LookupElementPresentation presentation,
      int allowedWidth,
      boolean selected,
      boolean nonFocusedSelection,
      FontMetrics normalMetrics) {
    final String givenText = presentation.getTypeText();
    final String labelText =
        trimLabelText(
            StringUtil.isEmpty(givenText) ? "" : " " + givenText, allowedWidth, normalMetrics);

    int used = RealLookupElementPresentation.getStringWidth(labelText, normalMetrics);

    final Icon icon = presentation.getTypeIcon();
    if (icon != null) {
      myTypeLabel.setIcon(icon);
      used += icon.getIconWidth();
    }

    Color sampleBackground = background;

    Object o = item.isValid() ? item.getObject() : null;
    //noinspection deprecation
    if (o instanceof LookupValueWithUIHint && StringUtil.isEmpty(labelText)) {
      //noinspection deprecation
      Color proposedBackground = ((LookupValueWithUIHint) o).getColorHint();
      if (proposedBackground != null) {
        sampleBackground = proposedBackground;
      }
      myTypeLabel.append("  ");
      used += normalMetrics.stringWidth("WW");
    } else {
      myTypeLabel.append(labelText);
    }

    myTypeLabel.setBackground(sampleBackground);
    myTypeLabel.setForeground(
        getTypeTextColor(item, foreground, presentation, selected, nonFocusedSelection));
    return used;
  }
예제 #3
0
  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);
  }
예제 #4
0
  private void setTailTextLabel(
      boolean isSelected,
      LookupElementPresentation presentation,
      Color foreground,
      int allowedWidth,
      boolean nonFocusedSelection,
      FontMetrics fontMetrics) {
    int style = getStyle(false, presentation.isStrikeout(), false);

    for (LookupElementPresentation.TextFragment fragment : presentation.getTailFragments()) {
      if (allowedWidth < 0) {
        return;
      }

      String trimmed = trimLabelText(fragment.text, allowedWidth, fontMetrics);
      myTailComponent.append(
          trimmed,
          new SimpleTextAttributes(
              style, getTailTextColor(isSelected, fragment, foreground, nonFocusedSelection)));
      allowedWidth -= RealLookupElementPresentation.getStringWidth(trimmed, fontMetrics);
    }
  }