Search in sources :

Example 1 with UsageNode

use of com.intellij.usages.impl.UsageNode 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;
}
Also used : Usage(com.intellij.usages.Usage) TextChunk(com.intellij.usages.TextChunk) UsagePresentation(com.intellij.usages.UsagePresentation) UsageNode(com.intellij.usages.impl.UsageNode) EmptyIcon(com.intellij.util.ui.EmptyIcon) SimpleColoredComponent(com.intellij.ui.SimpleColoredComponent) SimpleColoredComponent(com.intellij.ui.SimpleColoredComponent)

Aggregations

SimpleColoredComponent (com.intellij.ui.SimpleColoredComponent)1 TextChunk (com.intellij.usages.TextChunk)1 Usage (com.intellij.usages.Usage)1 UsagePresentation (com.intellij.usages.UsagePresentation)1 UsageNode (com.intellij.usages.impl.UsageNode)1 EmptyIcon (com.intellij.util.ui.EmptyIcon)1