当前位置: 首页>>代码示例>>Java>>正文


Java LookupElementPresentation.setItemTextForeground方法代码示例

本文整理汇总了Java中com.intellij.codeInsight.lookup.LookupElementPresentation.setItemTextForeground方法的典型用法代码示例。如果您正苦于以下问题:Java LookupElementPresentation.setItemTextForeground方法的具体用法?Java LookupElementPresentation.setItemTextForeground怎么用?Java LookupElementPresentation.setItemTextForeground使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.codeInsight.lookup.LookupElementPresentation的用法示例。


在下文中一共展示了LookupElementPresentation.setItemTextForeground方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: renderElement

import com.intellij.codeInsight.lookup.LookupElementPresentation; //导入方法依赖的package包/类
public void renderElement(LookupElement element, LookupElementPresentation presentation) {
  Suggestion suggestion = (Suggestion) element.getObject();
  if (suggestion.icon != null) {
    presentation.setIcon(suggestion.icon);
  }

  presentation.setStrikeout(suggestion.deprecationLevel != null);
  if (suggestion.deprecationLevel != null) {
    if (suggestion.deprecationLevel == SpringConfigurationMetadataDeprecationLevel.error) {
      presentation.setItemTextForeground(RED);
    } else {
      presentation.setItemTextForeground(YELLOW);
    }
  }

  String lookupString = element.getLookupString();
  presentation.setItemText(lookupString);
  if (!lookupString.equals(suggestion.suggestion)) {
    presentation.setItemTextBold(true);
  }

  String shortDescription;
  if (suggestion.defaultValue != null) {
    shortDescription = shortenTextWithEllipsis(suggestion.defaultValue, 60, 0, true);
    TextAttributes attrs =
        EditorColorsManager.getInstance().getGlobalScheme().getAttributes(SCALAR_TEXT);
    presentation.setTailText("=" + shortDescription, attrs.getForegroundColor());
  }

  if (suggestion.description != null) {
    presentation.appendTailText(
        " (" + Util.getFirstSentenceWithoutDot(suggestion.description) + ")", true);
  }

  if (suggestion.shortType != null) {
    presentation.setTypeText(suggestion.shortType);
  }
}
 
开发者ID:1tontech,项目名称:intellij-spring-assistant,代码行数:39,代码来源:Suggestion.java

示例2: getListCellRendererComponent

import com.intellij.codeInsight.lookup.LookupElementPresentation; //导入方法依赖的package包/类
@Override
public Component getListCellRendererComponent(
    final JList list,
    Object value,
    int index,
    boolean isSelected,
    boolean hasFocus) {


  boolean nonFocusedSelection = isSelected && myLookup.getFocusDegree() == LookupImpl.FocusDegree.SEMI_FOCUSED;
  if (!myLookup.isFocused()) {
    isSelected = false;
  }

  myIsSelected = isSelected;
  final LookupElement item = (LookupElement)value;
  final Color foreground = getForegroundColor(isSelected);
  final Color background = nonFocusedSelection ? SELECTED_NON_FOCUSED_BACKGROUND_COLOR :
                           isSelected ? SELECTED_BACKGROUND_COLOR : BACKGROUND_COLOR;

  int allowedWidth = list.getWidth() - AFTER_TAIL - AFTER_TYPE - getIconIndent();
  final LookupElementPresentation presentation = new RealLookupElementPresentation(isSelected ? getMaxWidth() : allowedWidth, myNormalMetrics, myBoldMetrics, myLookup);
  if (item.isValid()) {
    item.renderElement(presentation);
  } else {
    presentation.setItemTextForeground(JBColor.RED);
    presentation.setItemText("Invalid");
  }

  myNameComponent.clear();
  myNameComponent.setIcon(augmentIcon(presentation.getIcon(), myEmptyIcon));
  myNameComponent.setBackground(background);
  allowedWidth -= setItemTextLabel(item, new JBColor(isSelected ? SELECTED_FOREGROUND_COLOR : presentation.getItemTextForeground(), foreground), isSelected, presentation, allowedWidth);

  myTypeLabel.clear();
  if (allowedWidth > 0) {
    allowedWidth -= setTypeTextLabel(item, background, foreground, presentation, isSelected ? getMaxWidth() : allowedWidth, isSelected);
  }

  myTailComponent.clear();
  myTailComponent.setBackground(background);
  if (isSelected || allowedWidth >= 0) {
    setTailTextLabel(isSelected, presentation, foreground, isSelected ? getMaxWidth() : allowedWidth, nonFocusedSelection);
  }

  if (mySelected.containsKey(index)) {
    if (!isSelected && mySelected.get(index)) {
      myPanel.setUpdateExtender(true);
    }
  }
  mySelected.put(index, isSelected);

  final double w = myNameComponent.getPreferredSize().getWidth() +
                   myTailComponent.getPreferredSize().getWidth() +
                   myTypeLabel.getPreferredSize().getWidth();

  myPanel.removeAll();
  if (isSelected && w > list.getWidth()) {
    myPanel.setLayout(new BoxLayout(myPanel, BoxLayout.X_AXIS));
    myPanel.add(myNameComponent);
    myPanel.add(myTailComponent);
    myPanel.add(myTypeLabel);
  } else {
    myPanel.setLayout(new BorderLayout());
    myPanel.add(myNameComponent, BorderLayout.WEST);
    myPanel.add(myTailComponent, BorderLayout.CENTER);
    myPanel.add(myTypeLabel, BorderLayout.EAST);
  }

  return myPanel;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:72,代码来源:LookupCellRenderer.java


注:本文中的com.intellij.codeInsight.lookup.LookupElementPresentation.setItemTextForeground方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。