Search in sources :

Example 36 with SimpleTextAttributes

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

the class InspectionListCellRenderer method getListCellRendererComponent.

@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean sel, boolean focus) {
    final BorderLayout layout = new BorderLayout();
    layout.setHgap(5);
    final JPanel panel = new JPanel(layout);
    panel.setOpaque(true);
    final Color bg = sel ? UIUtil.getListSelectionBackground() : UIUtil.getListBackground();
    final Color fg = sel ? UIUtil.getListSelectionForeground() : UIUtil.getListForeground();
    panel.setBackground(bg);
    panel.setForeground(fg);
    if (value instanceof InspectionToolWrapper) {
        final InspectionToolWrapper toolWrapper = (InspectionToolWrapper) value;
        final String inspectionName = "  " + toolWrapper.getDisplayName();
        final String groupName = StringUtil.join(toolWrapper.getGroupPath(), " | ");
        final String matchingText = inspectionName + "|" + groupName;
        Matcher matcher = MatcherHolder.getAssociatedMatcher(list);
        List<TextRange> fragments = matcher == null ? null : ((MinusculeMatcher) matcher).matchingFragments(matchingText);
        List<TextRange> adjustedFragments = new ArrayList<>();
        if (fragments != null) {
            adjustedFragments.addAll(fragments);
        }
        final int splitPoint = adjustRanges(adjustedFragments, inspectionName.length() + 1);
        final SimpleColoredComponent c = new SimpleColoredComponent();
        final boolean matchHighlighting = Registry.is("ide.highlight.match.in.selected.only") && !sel;
        if (matchHighlighting) {
            c.append(inspectionName, myPlain);
        } else {
            final List<TextRange> ranges = adjustedFragments.subList(0, splitPoint);
            SpeedSearchUtil.appendColoredFragments(c, inspectionName, ranges, sel ? mySelected : myPlain, myHighlighted);
        }
        panel.add(c, BorderLayout.WEST);
        final SimpleColoredComponent group = new SimpleColoredComponent();
        if (matchHighlighting) {
            group.append(groupName, SimpleTextAttributes.GRAYED_ATTRIBUTES);
        } else {
            final SimpleTextAttributes attributes = sel ? mySelected : SimpleTextAttributes.GRAYED_ATTRIBUTES;
            final List<TextRange> ranges = adjustedFragments.subList(splitPoint, adjustedFragments.size());
            SpeedSearchUtil.appendColoredFragments(group, groupName, ranges, attributes, myHighlighted);
        }
        final JPanel right = new JPanel(new BorderLayout());
        right.setBackground(bg);
        right.setForeground(fg);
        right.add(group, BorderLayout.CENTER);
        final JLabel icon = new JLabel(getIcon(toolWrapper));
        icon.setBackground(bg);
        icon.setForeground(fg);
        right.add(icon, BorderLayout.EAST);
        panel.add(right, BorderLayout.EAST);
    } else {
        // E.g. "..." item
        return value == ChooseByNameBase.NON_PREFIX_SEPARATOR ? ChooseByNameBase.renderNonPrefixSeparatorComponent(UIUtil.getListBackground()) : super.getListCellRendererComponent(list, value, index, sel, focus);
    }
    return panel;
}
Also used : MinusculeMatcher(com.intellij.psi.codeStyle.MinusculeMatcher) Matcher(com.intellij.util.text.Matcher) JBColor(com.intellij.ui.JBColor) ArrayList(java.util.ArrayList) TextRange(com.intellij.openapi.util.TextRange) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) InspectionToolWrapper(com.intellij.codeInspection.ex.InspectionToolWrapper) SimpleColoredComponent(com.intellij.ui.SimpleColoredComponent)

Example 37 with SimpleTextAttributes

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

the class PackagingElementNode method addErrorHighlighting.

private static SimpleTextAttributes addErrorHighlighting(boolean error, SimpleTextAttributes attributes) {
    final TextAttributes textAttributes = attributes.toTextAttributes();
    textAttributes.setEffectType(EffectType.WAVE_UNDERSCORE);
    textAttributes.setEffectColor(error ? JBColor.RED : JBColor.GRAY);
    return SimpleTextAttributes.fromTextAttributes(textAttributes);
}
Also used : TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes)

Example 38 with SimpleTextAttributes

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

the class LibraryTreeRenderer method customizeCellRenderer.

@Override
public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
    Object userObject = node.getUserObject();
    if (userObject instanceof NodeDescriptor) {
        final NodeDescriptor descriptor = (NodeDescriptor) userObject;
        setIcon(descriptor.getIcon());
        append(descriptor.toString(), new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, descriptor.getColor()));
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) NodeDescriptor(com.intellij.ide.util.treeView.NodeDescriptor)

Example 39 with SimpleTextAttributes

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

the class NavBarPresentation method getTextAttributes.

protected SimpleTextAttributes getTextAttributes(final Object object, final boolean selected) {
    if (!NavBarModel.isValid(object))
        return SimpleTextAttributes.REGULAR_ATTRIBUTES;
    if (object instanceof PsiElement) {
        if (!ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {

            @Override
            public Boolean compute() {
                return ((PsiElement) object).isValid();
            }
        }).booleanValue())
            return SimpleTextAttributes.GRAYED_ATTRIBUTES;
        PsiFile psiFile = ((PsiElement) object).getContainingFile();
        if (psiFile != null) {
            final VirtualFile virtualFile = psiFile.getVirtualFile();
            return new SimpleTextAttributes(null, selected ? null : FileStatusManager.getInstance(myProject).getStatus(virtualFile).getColor(), JBColor.red, WolfTheProblemSolver.getInstance(myProject).isProblemFile(virtualFile) ? SimpleTextAttributes.STYLE_WAVED : SimpleTextAttributes.STYLE_PLAIN);
        } else {
            if (object instanceof PsiDirectory) {
                VirtualFile vDir = ((PsiDirectory) object).getVirtualFile();
                if (vDir.getParent() == null || ProjectRootsUtil.isModuleContentRoot(vDir, myProject)) {
                    return SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES;
                }
            }
            if (wolfHasProblemFilesBeneath((PsiElement) object)) {
                return WOLFED;
            }
        }
    } else if (object instanceof Module) {
        if (WolfTheProblemSolver.getInstance(myProject).hasProblemFilesBeneath((Module) object)) {
            return WOLFED;
        }
    } else if (object instanceof Project) {
        final Project project = (Project) object;
        final Module[] modules = ApplicationManager.getApplication().runReadAction(new Computable<Module[]>() {

            @Override
            public Module[] compute() {
                return ModuleManager.getInstance(project).getModules();
            }
        });
        for (Module module : modules) {
            if (WolfTheProblemSolver.getInstance(project).hasProblemFilesBeneath(module)) {
                return WOLFED;
            }
        }
    }
    return SimpleTextAttributes.REGULAR_ATTRIBUTES;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) PsiDirectory(com.intellij.psi.PsiDirectory) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) PsiElement(com.intellij.psi.PsiElement)

Example 40 with SimpleTextAttributes

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

the class BlockTreeNode method update.

@Override
protected void update(PresentationData presentation) {
    String name = myBlock.getClass().getSimpleName();
    if (myBlock instanceof DataLanguageBlockWrapper) {
        name += " (" + ((DataLanguageBlockWrapper) myBlock).getOriginal().getClass().getSimpleName() + ")";
    }
    presentation.addText(name, SimpleTextAttributes.REGULAR_ATTRIBUTES);
    if (myBlock.getIndent() != null) {
        presentation.addText(" " + String.valueOf(myBlock.getIndent()).replaceAll("[<>]", " "), SimpleTextAttributes.GRAY_ATTRIBUTES);
    } else {
        presentation.addText(" Indent: null", SimpleTextAttributes.GRAY_ATTRIBUTES);
    }
    if (myBlock.getAlignment() != null) {
        float d = 1.f * System.identityHashCode(myBlock.getAlignment()) / Integer.MAX_VALUE;
        Color color = new JBColor(Color.HSBtoRGB(1.0f * d, .3f, .7f), Color.HSBtoRGB(1.0f * d, .3f, .8f));
        presentation.addText(" " + String.valueOf(myBlock.getAlignment()), new SimpleTextAttributes(SimpleTextAttributes.STYLE_BOLD, color));
    }
    if (myBlock.getWrap() != null) {
        presentation.addText(" " + String.valueOf(myBlock.getWrap()), new SimpleTextAttributes(SimpleTextAttributes.STYLE_ITALIC, PlatformColors.BLUE));
    }
}
Also used : JBColor(com.intellij.ui.JBColor) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) JBColor(com.intellij.ui.JBColor) DataLanguageBlockWrapper(com.intellij.formatting.templateLanguages.DataLanguageBlockWrapper)

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