Java Code Examples for com.intellij.codeInsight.lookup.LookupElementPresentation#getTypeText()

The following examples show how to use com.intellij.codeInsight.lookup.LookupElementPresentation#getTypeText() . 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: LookupCellRenderer.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
Font getFontAbleToDisplay(LookupElementPresentation p) {
  String sampleString = p.getItemText() + p.getTailText() + p.getTypeText();

  // assume a single font can display all lookup item chars
  Set<Font> fonts = ContainerUtil.newHashSet();
  FontPreferences fontPreferences = myLookup.getFontPreferences();
  for (int i = 0; i < sampleString.length(); i++) {
    fonts.add(ComplementaryFontsRegistry.getFontAbleToDisplay(sampleString.charAt(i), Font.PLAIN, fontPreferences, null).getFont());
  }

  eachFont:
  for (Font font : fonts) {
    if (font.equals(myNormalFont)) continue;

    for (int i = 0; i < sampleString.length(); i++) {
      if (!font.canDisplay(sampleString.charAt(i))) {
        continue eachFont;
      }
    }
    return font;
  }
  return null;
}
 
Example 2
Source File: AbstractTestCase.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
protected void assertContainsLookupElementWithText(LookupElement[] lookupElements, @NotNull String title, @NotNull String tailText, @NotNull String typeText) {
    for (LookupElement lookupElement : lookupElements) {
        LookupElementPresentation presentation = new LookupElementPresentation();
        lookupElement.renderElement(presentation);

        final String actualItemText = presentation.getItemText();
        final String actualTailText = presentation.getTailText();
        final String actualTypeText = presentation.getTypeText();
        if (actualItemText.equals(title) && actualTailText.equals(tailText) && actualTypeText.contains(typeText)) {
            return;
        }
    }

    fail("No such element");
}
 
Example 3
Source File: LookupCellRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
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;
}