use of com.intellij.usages.UsagePresentation in project intellij-community by JetBrains.
the class NameUsage method getPresentation.
@NotNull
public UsagePresentation getPresentation() {
return new UsagePresentation() {
@Nullable
public Icon getIcon() {
PyPsiUtils.assertValid(myElement);
return myElement.isValid() ? myElement.getIcon(0) : null;
}
@NotNull
public TextChunk[] getText() {
PyPsiUtils.assertValid(myElement);
if (myElement.isValid()) {
TextChunk[] chunks = new TextChunk[3];
PsiFile file = myElement.getContainingFile();
String line_id = "...";
final Document document = file.getViewProvider().getDocument();
if (document != null) {
line_id = String.valueOf(document.getLineNumber(myElement.getTextOffset()));
}
chunks[0] = new TextChunk(SLANTED, "(" + line_id + ") ");
chunks[1] = new TextChunk(TextAttributes.ERASE_MARKER, myElement.getText());
StringBuilder sb = new StringBuilder(" would become ").append(myName);
if (myIsPrefix)
sb.append(".").append(myElement.getText());
chunks[2] = new TextChunk(SLANTED, sb.toString());
return chunks;
} else
return new TextChunk[] { new TextChunk(SLANTED, "?") };
}
@NotNull
public String getPlainText() {
return myElement.getText();
}
public String getTooltipText() {
return myElement.getText();
}
};
}
use of com.intellij.usages.UsagePresentation in project intellij-community by JetBrains.
the class UsageListCellRenderer method customizeCellRenderer.
@Override
protected void customizeCellRenderer(@NotNull final JList list, final Object value, final int index, final boolean selected, final boolean hasFocus) {
Usage usage = (Usage) value;
UsagePresentation presentation = usage.getPresentation();
setIcon(presentation.getIcon());
VirtualFile virtualFile = getVirtualFile(usage);
if (virtualFile != null) {
append(virtualFile.getName() + ": ", SimpleTextAttributes.REGULAR_ATTRIBUTES);
setIcon(virtualFile.getFileType().getIcon());
PsiFile psiFile = PsiManager.getInstance(myProject).findFile(virtualFile);
if (psiFile != null) {
setIcon(psiFile.getIcon(0));
}
}
TextChunk[] text = presentation.getText();
for (TextChunk textChunk : text) {
SimpleTextAttributes simples = textChunk.getSimpleAttributesIgnoreBackground();
append(textChunk.getText(), simples);
}
}
use of com.intellij.usages.UsagePresentation in project intellij-community by JetBrains.
the class ShowUsagesTableCellRenderer method getTableCellRendererComponent.
@Override
public Component getTableCellRendererComponent(JTable list, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
UsageNode usageNode = value instanceof UsageNode ? (UsageNode) value : null;
Usage usage = usageNode == null ? null : usageNode.getUsage();
Color fileBgColor = getBackgroundColor(isSelected, usage);
Color bg = UIUtil.getListSelectionBackground();
Color fg = UIUtil.getListSelectionForeground();
Color panelBackground = isSelected ? bg : fileBgColor == null ? list.getBackground() : fileBgColor;
Color panelForeground = isSelected ? fg : list.getForeground();
SimpleColoredComponent textChunks = new SimpleColoredComponent();
if (usageNode == null || usageNode instanceof ShowUsagesAction.StringNode) {
textChunks.append(ObjectUtils.notNull(value, "").toString(), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
return textComponentSpanningWholeRow(textChunks, panelBackground, panelForeground, column, list);
}
if (usage == ShowUsagesAction.MORE_USAGES_SEPARATOR) {
textChunks.append("...<");
textChunks.append("more usages", SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
textChunks.append(">...");
return textComponentSpanningWholeRow(textChunks, panelBackground, panelForeground, column, list);
}
if (usage == ShowUsagesAction.USAGES_OUTSIDE_SCOPE_SEPARATOR) {
textChunks.append("...<");
textChunks.append(UsageViewManagerImpl.outOfScopeMessage(myOutOfScopeUsages.get(), mySearchScope), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
textChunks.append(">...");
return textComponentSpanningWholeRow(textChunks, panelBackground, panelForeground, column, list);
}
boolean lineNumberColumn = column == 1;
JPanel panel = new JPanel(new FlowLayout(lineNumberColumn ? FlowLayout.RIGHT : FlowLayout.LEFT, 0, 0) {
@Override
public void layoutContainer(Container container) {
super.layoutContainer(container);
for (Component component : container.getComponents()) {
// align inner components
Rectangle b = component.getBounds();
Insets insets = container.getInsets();
component.setBounds(b.x, b.y, b.width, container.getSize().height - insets.top - insets.bottom);
}
}
});
panel.setFont(null);
panel.setBackground(panelBackground);
panel.setForeground(panelForeground);
// greying the current usage you originated your "find usages" from is turned off by @nik orders
//!myUsageView.isOriginUsage(usage);
boolean isEnabled = true;
if (!isEnabled) {
fg = UIUtil.getLabelDisabledForeground();
}
if (column == 0) {
appendGroupText(list, (GroupNode) usageNode.getParent(), panel, fileBgColor, isSelected);
} else {
if (usage != ShowUsagesAction.MORE_USAGES_SEPARATOR && usage != ShowUsagesAction.USAGES_OUTSIDE_SCOPE_SEPARATOR) {
UsagePresentation presentation = usage.getPresentation();
TextChunk[] text = presentation.getText();
if (lineNumberColumn) {
// line number
if (text.length != 0) {
TextChunk chunk = text[0];
textChunks.append(chunk.getText(), getAttributes(isSelected, fileBgColor, bg, fg, chunk));
}
} else if (column == 2) {
Icon icon = presentation.getIcon();
textChunks.setIcon(icon == null ? EmptyIcon.ICON_16 : icon);
textChunks.append("").appendTextPadding(JBUI.scale(16 + 5));
for (int i = 1; i < text.length; i++) {
TextChunk chunk = text[i];
textChunks.append(chunk.getText(), getAttributes(isSelected, fileBgColor, bg, fg, chunk));
}
} else {
assert false : column;
}
}
SpeedSearchUtil.applySpeedSearchHighlighting(list, textChunks, false, isSelected);
panel.add(textChunks);
}
if (!isEnabled) {
GuiUtils.enableChildren(panel, false);
}
return panel;
}
Aggregations