use of com.intellij.codeInsight.lookup.LookupValueWithUIHint in project intellij-community by JetBrains.
the class CompletionData method objectToLookupItem.
public static LookupElement objectToLookupItem(@NotNull final Object object) {
if (object instanceof LookupElement)
return (LookupElement) object;
String s = null;
TailType tailType = TailType.NONE;
if (object instanceof PsiElement) {
s = PsiUtilCore.getName((PsiElement) object);
} else if (object instanceof PsiMetaData) {
s = ((PsiMetaData) object).getName();
} else if (object instanceof String) {
s = (String) object;
} else if (object instanceof Template) {
s = ((Template) object).getKey();
} else if (object instanceof PresentableLookupValue) {
s = ((PresentableLookupValue) object).getPresentation();
}
if (s == null) {
throw new AssertionError("Null string for object: " + object + " of class " + object.getClass());
}
LookupItem item = new LookupItem(object, s);
if (object instanceof LookupValueWithUIHint && ((LookupValueWithUIHint) object).isBold()) {
item.setBold();
}
item.setAttribute(LookupItem.TAIL_TYPE_ATTR, tailType);
return item;
}
use of com.intellij.codeInsight.lookup.LookupValueWithUIHint in project intellij-community by JetBrains.
the class LookupCellRenderer method setTypeTextLabel.
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;
}
Aggregations