Search in sources :

Example 6 with SimpleTextAttributes

use of com.intellij.ui.SimpleTextAttributes in project intellij-community by JetBrains.

the class ShowUsagesTableCellRenderer method textComponentSpanningWholeRow.

@NotNull
private static Component textComponentSpanningWholeRow(@NotNull SimpleColoredComponent chunks, Color panelBackground, Color panelForeground, final int column, @NotNull final JTable table) {
    final SimpleColoredComponent component = new SimpleColoredComponent() {

        @Override
        protected void doPaint(Graphics2D g) {
            int offset = 0;
            int i = 0;
            final TableColumnModel columnModel = table.getColumnModel();
            while (i < column) {
                offset += columnModel.getColumn(i).getWidth();
                i++;
            }
            g.translate(-offset, 0);
            //if (column == columnModel.getColumnCount()-1) {
            //}
            // should increase the column width so that selection background will be visible even after offset translation
            setSize(getWidth() + offset, getHeight());
            super.doPaint(g);
            g.translate(+offset, 0);
        }

        @NotNull
        @Override
        public Dimension getPreferredSize() {
            //return super.getPreferredSize();
            return column == table.getColumnModel().getColumnCount() - 1 ? super.getPreferredSize() : new Dimension(0, 0);
        // it should span the whole row, so we can't return any specific value here,
        // because otherwise it would be used in the "max width" calculation in com.intellij.find.actions.ShowUsagesAction.calcMaxWidth
        }
    };
    component.setBackground(panelBackground);
    component.setForeground(panelForeground);
    for (SimpleColoredComponent.ColoredIterator iterator = chunks.iterator(); iterator.hasNext(); ) {
        iterator.next();
        String fragment = iterator.getFragment();
        SimpleTextAttributes attributes = iterator.getTextAttributes();
        attributes = attributes.derive(attributes.getStyle(), panelForeground, panelBackground, attributes.getWaveColor());
        component.append(fragment, attributes);
    }
    return component;
}
Also used : SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) TableColumnModel(javax.swing.table.TableColumnModel) SimpleColoredComponent(com.intellij.ui.SimpleColoredComponent) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with SimpleTextAttributes

use of com.intellij.ui.SimpleTextAttributes 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);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Usage(com.intellij.usages.Usage) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) PsiFile(com.intellij.psi.PsiFile) TextChunk(com.intellij.usages.TextChunk) UsagePresentation(com.intellij.usages.UsagePresentation)

Example 8 with SimpleTextAttributes

use of com.intellij.ui.SimpleTextAttributes in project intellij-community by JetBrains.

the class SearchEverywherePsiRenderer method customizeNonPsiElementLeftRenderer.

@Override
protected boolean customizeNonPsiElementLeftRenderer(ColoredListCellRenderer renderer, JList list, Object value, int index, boolean selected, boolean hasFocus) {
    if (!(value instanceof NavigationItem))
        return false;
    NavigationItem item = (NavigationItem) value;
    TextAttributes attributes = getNavigationItemAttributes(item);
    SimpleTextAttributes nameAttributes = attributes != null ? SimpleTextAttributes.fromTextAttributes(attributes) : null;
    Color color = list.getForeground();
    if (nameAttributes == null)
        nameAttributes = new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, color);
    renderer.append(item + " ", nameAttributes);
    ItemPresentation itemPresentation = item.getPresentation();
    assert itemPresentation != null;
    renderer.setIcon(itemPresentation.getIcon(true));
    String locationString = itemPresentation.getLocationString();
    if (!StringUtil.isEmpty(locationString)) {
        renderer.append(locationString, new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, JBColor.GRAY));
    }
    return true;
}
Also used : NavigationItem(com.intellij.navigation.NavigationItem) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) JBColor(com.intellij.ui.JBColor) ItemPresentation(com.intellij.navigation.ItemPresentation) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes)

Example 9 with SimpleTextAttributes

use of com.intellij.ui.SimpleTextAttributes in project intellij-community by JetBrains.

the class NodeRenderer method customizeCellRenderer.

@Override
public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    Color color = null;
    NodeDescriptor descriptor = null;
    if (value instanceof DefaultMutableTreeNode) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
        Object userObject = node.getUserObject();
        if (userObject instanceof NodeDescriptor) {
            descriptor = (NodeDescriptor) userObject;
            color = descriptor.getColor();
            setIcon(descriptor.getIcon());
        }
    }
    if (descriptor instanceof PresentableNodeDescriptor) {
        final PresentableNodeDescriptor node = (PresentableNodeDescriptor) descriptor;
        final PresentationData presentation = node.getPresentation();
        final List<PresentableNodeDescriptor.ColoredFragment> coloredText = presentation.getColoredText();
        if (coloredText.isEmpty()) {
            String text = tree.convertValueToText(value.toString(), selected, expanded, leaf, row, hasFocus);
            SimpleTextAttributes simpleTextAttributes = getSimpleTextAttributes(node, presentation.getForcedTextForeground() != null ? presentation.getForcedTextForeground() : color);
            append(text, simpleTextAttributes);
            String location = presentation.getLocationString();
            if (!StringUtil.isEmpty(location)) {
                SimpleTextAttributes attributes = SimpleTextAttributes.merge(simpleTextAttributes, SimpleTextAttributes.GRAYED_ATTRIBUTES);
                append(presentation.getLocationPrefix() + location + presentation.getLocationSuffix(), attributes, false);
            }
        } else {
            boolean first = true;
            for (PresentableNodeDescriptor.ColoredFragment each : coloredText) {
                SimpleTextAttributes simpleTextAttributes = each.getAttributes();
                if (each.getAttributes().getFgColor() == null && presentation.getForcedTextForeground() != null) {
                    simpleTextAttributes = addColorToSimpleTextAttributes(each.getAttributes(), presentation.getForcedTextForeground() != null ? presentation.getForcedTextForeground() : color);
                }
                if (first) {
                    final TextAttributesKey textAttributesKey = presentation.getTextAttributesKey();
                    if (textAttributesKey != null) {
                        final TextAttributes forcedAttributes = getColorsScheme().getAttributes(textAttributesKey);
                        if (forcedAttributes != null) {
                            simpleTextAttributes = SimpleTextAttributes.merge(simpleTextAttributes, SimpleTextAttributes.fromTextAttributes(forcedAttributes));
                        }
                    }
                    first = false;
                }
                // treat grayed text as non-main
                boolean isMain = simpleTextAttributes != SimpleTextAttributes.GRAYED_ATTRIBUTES;
                append(each.getText(), simpleTextAttributes, isMain);
            }
            String location = presentation.getLocationString();
            if (!StringUtil.isEmpty(location)) {
                append(presentation.getLocationPrefix() + location + presentation.getLocationSuffix(), SimpleTextAttributes.GRAY_ATTRIBUTES, false);
            }
        }
        setToolTipText(presentation.getTooltip());
    } else if (value != null) {
        String text = value.toString();
        if (descriptor != null) {
            text = descriptor.myName;
        }
        text = tree.convertValueToText(text, selected, expanded, leaf, row, hasFocus);
        if (text == null) {
            text = "";
        }
        append(text);
        setToolTipText(null);
    }
    if (!AbstractTreeUi.isLoadingNode(value)) {
        SpeedSearchUtil.applySpeedSearchHighlighting(tree, this, true, selected);
    }
}
Also used : PresentationData(com.intellij.ide.projectView.PresentationData) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes)

Example 10 with SimpleTextAttributes

use of com.intellij.ui.SimpleTextAttributes in project intellij-community by JetBrains.

the class NodeRenderer method addColorToSimpleTextAttributes.

private static SimpleTextAttributes addColorToSimpleTextAttributes(SimpleTextAttributes simpleTextAttributes, Color color) {
    if (color != null) {
        final TextAttributes textAttributes = simpleTextAttributes.toTextAttributes();
        textAttributes.setForegroundColor(color);
        simpleTextAttributes = SimpleTextAttributes.fromTextAttributes(textAttributes);
    }
    return simpleTextAttributes;
}
Also used : TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes)

Aggregations

SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)87 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)15 JBColor (com.intellij.ui.JBColor)11 NotNull (org.jetbrains.annotations.NotNull)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)7 SimpleColoredComponent (com.intellij.ui.SimpleColoredComponent)7 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)7 TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)6 TextRange (com.intellij.openapi.util.TextRange)6 NodeDescriptor (com.intellij.ide.util.treeView.NodeDescriptor)5 ItemPresentation (com.intellij.navigation.ItemPresentation)4 FileStatus (com.intellij.openapi.vcs.FileStatus)4 PresentationData (com.intellij.ide.projectView.PresentationData)3 PsiElement (com.intellij.psi.PsiElement)3 SimpleColoredText (com.intellij.ui.SimpleColoredText)3 List (java.util.List)3 PsIssue (com.android.tools.idea.gradle.structure.model.PsIssue)2 PTableItem (com.android.tools.idea.uibuilder.property.ptable.PTableItem)2 HighlightDisplayLevel (com.intellij.codeHighlighting.HighlightDisplayLevel)2 RefEntity (com.intellij.codeInspection.reference.RefEntity)2