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


Java RealLookupElementPresentation类代码示例

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


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

示例1: setTailTextLabel

import com.intellij.codeInsight.lookup.RealLookupElementPresentation; //导入依赖的package包/类
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);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:LookupCellRenderer.java

示例2: renderElement

import com.intellij.codeInsight.lookup.RealLookupElementPresentation; //导入依赖的package包/类
@Override
public void renderElement(LookupElementPresentation presentation) {
  super.renderElement(presentation);
  if (sudden) {
    presentation.setItemTextBold(true);
    if (!presentation.isReal() || !((RealLookupElementPresentation)presentation).isLookupSelectionTouched()) {
      char shortcutChar = myTemplate.getShortcutChar();
      if (shortcutChar == TemplateSettings.DEFAULT_CHAR) {
        shortcutChar = TemplateSettings.getInstance().getDefaultShortcutChar();
      }
      presentation.setTypeText("  [" + KeyEvent.getKeyText(shortcutChar) + "] ");
    }
    presentation.setTailText(" (" + myTemplate.getDescription() + ")", true);
  } else {
    presentation.setTypeText(myTemplate.getDescription());

  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:19,代码来源:LiveTemplateLookupElement.java

示例3: renderElement

import com.intellij.codeInsight.lookup.RealLookupElementPresentation; //导入依赖的package包/类
@Override
public void renderElement(LookupElementPresentation presentation) {
  super.renderElement(presentation);
  char shortcut = getTemplateShortcut();
  presentation.setItemText(getItemText());
  if (sudden) {
    presentation.setItemTextBold(true);
    if (!presentation.isReal() || !((RealLookupElementPresentation)presentation).isLookupSelectionTouched()) {
      if (shortcut == TemplateSettings.DEFAULT_CHAR) {
        shortcut = TemplateSettings.getInstance().getDefaultShortcutChar();
      }
      presentation.setTypeText("  [" + KeyEvent.getKeyText(shortcut) + "] ");
    }
    if (StringUtil.isNotEmpty(myDescription)) {
      presentation.setTailText(" (" + myDescription + ")", true);
    }
  }
  else {
    presentation.setTypeText(myDescription);
  }
}
 
开发者ID:consulo,项目名称:consulo,代码行数:22,代码来源:LiveTemplateLookupElement.java

示例4: setTailTextLabel

import com.intellij.codeInsight.lookup.RealLookupElementPresentation; //导入依赖的package包/类
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);
    int fragmentStyle = fragment.isItalic() ? style | SimpleTextAttributes.STYLE_ITALIC : style;
    myTailComponent.append(trimmed, new SimpleTextAttributes(fragmentStyle, getTailTextColor(isSelected, fragment, foreground, nonFocusedSelection)));
    allowedWidth -= RealLookupElementPresentation.getStringWidth(trimmed, fontMetrics);
  }
}
 
开发者ID:consulo,项目名称:consulo,代码行数:19,代码来源:LookupCellRenderer.java

示例5: renderElement

import com.intellij.codeInsight.lookup.RealLookupElementPresentation; //导入依赖的package包/类
@Override
public void renderElement(LookupElementPresentation presentation) {
  super.renderElement(presentation);
  char shortcut = getTemplateShortcut();
  presentation.setItemText(getItemText());
  if (sudden) {
    presentation.setItemTextBold(true);
    if (!presentation.isReal() || !((RealLookupElementPresentation)presentation).isLookupSelectionTouched()) {
      if (shortcut == TemplateSettings.DEFAULT_CHAR) {
        shortcut = TemplateSettings.getInstance().getDefaultShortcutChar();
      }
      if (shortcut != TemplateSettings.CUSTOM_CHAR) {
        presentation.setTypeText("  [" + KeyEvent.getKeyText(shortcut) + "] ");
      } else {
        String shortcutText =
          KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_EXPAND_LIVE_TEMPLATE_CUSTOM));
        if (StringUtil.isNotEmpty(shortcutText)) {
          presentation.setTypeText("  [" + shortcutText + "] ");
        }
      }
    }
    if (StringUtil.isNotEmpty(myDescription)) {
      presentation.setTailText(" (" + myDescription + ")", true);
    }
  }
  else {
    presentation.setTypeText(myDescription);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:30,代码来源:LiveTemplateLookupElement.java

示例6: trimLabelText

import com.intellij.codeInsight.lookup.RealLookupElementPresentation; //导入依赖的package包/类
private String trimLabelText(@Nullable String text, int maxWidth, FontMetrics metrics) {
  if (text == null || StringUtil.isEmpty(text)) {
    return "";
  }

  final int strWidth = RealLookupElementPresentation.getStringWidth(text, metrics);
  if (strWidth <= maxWidth || myIsSelected) {
    return text;
  }

  if (RealLookupElementPresentation.getStringWidth(ELLIPSIS, metrics) > maxWidth) {
    return "";
  }

  int i = 0;
  int j = text.length();
  while (i + 1 < j) {
    int mid = (i + j) / 2;
    final String candidate = text.substring(0, mid) + ELLIPSIS;
    final int width = RealLookupElementPresentation.getStringWidth(candidate, metrics);
    if (width <= maxWidth) {
      i = mid;
    } else {
      j = mid;
    }
  }

  return text.substring(0, i) + ELLIPSIS;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:30,代码来源:LookupCellRenderer.java

示例7: setItemTextLabel

import com.intellij.codeInsight.lookup.RealLookupElementPresentation; //导入依赖的package包/类
private int setItemTextLabel(LookupElement item, final Color foreground, final boolean selected, LookupElementPresentation presentation, int allowedWidth) {
  boolean bold = presentation.isItemTextBold();

  Font customItemFont = myLookup.getCustomFont(item, bold);
  myNameComponent.setFont(customItemFont != null ? customItemFont : bold ? myBoldFont : myNormalFont);
  int style = getStyle(bold, presentation.isStrikeout(), presentation.isItemTextUnderlined());

  final FontMetrics metrics = getRealFontMetrics(item, bold);
  final String name = trimLabelText(presentation.getItemText(), allowedWidth, metrics);
  int used = RealLookupElementPresentation.getStringWidth(name, metrics);

  renderItemName(item, foreground, selected, style, name, myNameComponent);
  return used;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:LookupCellRenderer.java

示例8: setTypeTextLabel

import com.intellij.codeInsight.lookup.RealLookupElementPresentation; //导入依赖的package包/类
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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:38,代码来源:LookupCellRenderer.java

示例9: setTailTextLabel

import com.intellij.codeInsight.lookup.RealLookupElementPresentation; //导入依赖的package包/类
private void setTailTextLabel(boolean isSelected, LookupElementPresentation presentation, Color foreground, int allowedWidth, boolean nonFocusedSelection) {
  int style = getStyle(false, presentation.isStrikeout(), false);

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

    String trimmed = trimLabelText(fragment.text, allowedWidth, myNormalMetrics);
    myTailComponent.append(trimmed, new SimpleTextAttributes(style, getTailTextColor(isSelected, fragment, foreground, nonFocusedSelection)));
    allowedWidth -= RealLookupElementPresentation.getStringWidth(trimmed, myNormalMetrics);
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:14,代码来源:LookupCellRenderer.java

示例10: setItemTextLabel

import com.intellij.codeInsight.lookup.RealLookupElementPresentation; //导入依赖的package包/类
private int setItemTextLabel(LookupElement item, final Color foreground, final boolean selected, LookupElementPresentation presentation, int allowedWidth) {
  boolean bold = presentation.isItemTextBold();

  myNameComponent.setFont(bold ? myBoldFont : myNormalFont);

  int style = getStyle(bold, presentation.isStrikeout(), presentation.isItemTextUnderlined());

  final FontMetrics metrics = bold ? myBoldMetrics : myNormalMetrics;
  final String name = trimLabelText(presentation.getItemText(), allowedWidth, metrics);
  int used = RealLookupElementPresentation.getStringWidth(name, metrics);

  renderItemName(item, foreground, selected, style, name, myNameComponent);
  return used;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:15,代码来源:LookupCellRenderer.java

示例11: setTypeTextLabel

import com.intellij.codeInsight.lookup.RealLookupElementPresentation; //导入依赖的package包/类
private int setTypeTextLabel(LookupElement item,
                             final Color background,
                             Color foreground,
                             final LookupElementPresentation presentation,
                             int allowedWidth,
                             boolean selected) {
  final String givenText = presentation.getTypeText();
  final String labelText = trimLabelText(StringUtil.isEmpty(givenText) ? "" : " " + givenText, allowedWidth, myNormalMetrics);

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

  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 += myNormalMetrics.stringWidth("WW");
  } else {
    myTypeLabel.append(labelText);
  }

  myTypeLabel.setBackground(sampleBackground);
  myTypeLabel.setForeground(presentation.isTypeGrayed() ? getGrayedForeground(selected) : item instanceof EmptyLookupItem ? JBColor.foreground() : foreground);
  return used;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:38,代码来源:LookupCellRenderer.java

示例12: updateMaximumWidth

import com.intellij.codeInsight.lookup.RealLookupElementPresentation; //导入依赖的package包/类
int updateMaximumWidth(final LookupElementPresentation p, LookupElement item) {
  final Icon icon = p.getIcon();
  if (icon != null && (icon.getIconWidth() > myEmptyIcon.getIconWidth() || icon.getIconHeight() > myEmptyIcon.getIconHeight())) {
    myEmptyIcon = EmptyIcon.create(Math.max(icon.getIconWidth(), myEmptyIcon.getIconWidth()), Math.max(icon.getIconHeight(), myEmptyIcon.getIconHeight()));
  }

  return RealLookupElementPresentation.calculateWidth(p, getRealFontMetrics(item, false), getRealFontMetrics(item, true)) +
         calcSpacing(myTailComponent, null) + calcSpacing(myTypeLabel, null);
}
 
开发者ID:consulo,项目名称:consulo,代码行数:10,代码来源:LookupCellRenderer.java

示例13: getListCellRendererComponent

import com.intellij.codeInsight.lookup.RealLookupElementPresentation; //导入依赖的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.RealLookupElementPresentation类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。