Search in sources :

Example 56 with SimpleTextAttributes

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

the class NodeRenderer method getSimpleTextAttributes.

public static SimpleTextAttributes getSimpleTextAttributes(@Nullable final ItemPresentation presentation, @NotNull EditorColorsScheme colorsScheme) {
    if (presentation instanceof ColoredItemPresentation) {
        final TextAttributesKey textAttributesKey = ((ColoredItemPresentation) presentation).getTextAttributesKey();
        if (textAttributesKey == null)
            return SimpleTextAttributes.REGULAR_ATTRIBUTES;
        final TextAttributes textAttributes = colorsScheme.getAttributes(textAttributesKey);
        return textAttributes == null ? SimpleTextAttributes.REGULAR_ATTRIBUTES : SimpleTextAttributes.fromTextAttributes(textAttributes);
    }
    return SimpleTextAttributes.REGULAR_ATTRIBUTES;
}
Also used : ColoredItemPresentation(com.intellij.navigation.ColoredItemPresentation) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey)

Example 57 with SimpleTextAttributes

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

the class SwitcherToolWindowsListRenderer method customizeCellRenderer.

protected void customizeCellRenderer(@NotNull JList list, Object value, int index, boolean selected, boolean hasFocus) {
    hide = false;
    setPaintFocusBorder(false);
    if (value instanceof ToolWindow) {
        final ToolWindow tw = (ToolWindow) value;
        setIcon(getIcon(tw));
        final String name;
        String stripeTitle = tw.getStripeTitle();
        String shortcut = shortcuts.get(tw);
        if (myPinned || shortcut == null) {
            name = stripeTitle;
        } else {
            append(shortcut, new SimpleTextAttributes(SimpleTextAttributes.STYLE_UNDERLINE, null));
            name = ": " + stripeTitle;
        }
        append(name);
        if (mySpeedSearch != null && mySpeedSearch.isPopupActive()) {
            hide = mySpeedSearch.matchingFragments(stripeTitle) == null && !StringUtil.isEmpty(mySpeedSearch.getEnteredPrefix());
        }
    }
}
Also used : ToolWindow(com.intellij.openapi.wm.ToolWindow) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes)

Example 58 with SimpleTextAttributes

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

the class IssueLinkRenderer method appendTextWithLinks.

public List<String> appendTextWithLinks(final String text, final SimpleTextAttributes baseStyle, final Consumer<String> consumer) {
    final List<String> pieces = new ArrayList<>();
    final List<IssueNavigationConfiguration.LinkMatch> list = myIssueNavigationConfiguration.findIssueLinks(text);
    int pos = 0;
    final SimpleTextAttributes linkAttributes = getLinkAttributes(baseStyle);
    for (IssueNavigationConfiguration.LinkMatch match : list) {
        final TextRange textRange = match.getRange();
        if (textRange.getStartOffset() > pos) {
            final String piece = text.substring(pos, textRange.getStartOffset());
            pieces.add(piece);
            consumer.consume(piece);
        }
        final String piece = textRange.substring(text);
        pieces.add(piece);
        append(piece, linkAttributes, match);
        pos = textRange.getEndOffset();
    }
    if (pos < text.length()) {
        final String piece = text.substring(pos);
        pieces.add(piece);
        consumer.consume(piece);
    }
    return pieces;
}
Also used : SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) ArrayList(java.util.ArrayList) IssueNavigationConfiguration(com.intellij.openapi.vcs.IssueNavigationConfiguration) TextRange(com.intellij.openapi.util.TextRange)

Example 59 with SimpleTextAttributes

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

the class InspectionsConfigTreeRenderer method getTreeCellRendererComponent.

@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    final SimpleColoredComponent component = new SimpleColoredComponent();
    if (!(value instanceof InspectionConfigTreeNode))
        return component;
    InspectionConfigTreeNode node = (InspectionConfigTreeNode) value;
    Object object = node.getUserObject();
    boolean reallyHasFocus = ((TreeTableTree) tree).getTreeTable().hasFocus();
    final Color background = selected ? (reallyHasFocus ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeUnfocusedSelectionBackground()) : UIUtil.getTreeTextBackground();
    UIUtil.changeBackGround(component, background);
    Color foreground = selected ? UIUtil.getTreeSelectionForeground() : node.isProperSetting() ? PlatformColors.BLUE : UIUtil.getTreeTextForeground();
    @NonNls String text;
    int style = SimpleTextAttributes.STYLE_PLAIN;
    String hint = null;
    if (object instanceof String) {
        text = (String) object;
        style = SimpleTextAttributes.STYLE_BOLD;
    } else {
        final ToolDescriptors descriptors = node.getDescriptors();
        assert descriptors != null;
        final Descriptor defaultDescriptor = descriptors.getDefaultDescriptor();
        text = defaultDescriptor.getText();
        hint = getHint(defaultDescriptor);
    }
    if (text != null) {
        SearchUtil.appendFragments(getFilter(), text, style, foreground, background, component);
    }
    if (hint != null) {
        component.append(" " + hint, selected ? new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, foreground) : SimpleTextAttributes.GRAYED_ATTRIBUTES);
    }
    component.setForeground(foreground);
    return component;
}
Also used : NonNls(org.jetbrains.annotations.NonNls) ToolDescriptors(com.intellij.profile.codeInspection.ui.ToolDescriptors) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) Descriptor(com.intellij.codeInspection.ex.Descriptor) SimpleColoredComponent(com.intellij.ui.SimpleColoredComponent)

Example 60 with SimpleTextAttributes

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

the class SpeedSearchUtil method applySpeedSearchHighlighting.

public static void applySpeedSearchHighlighting(@NotNull JComponent speedSearchEnabledComponent, @NotNull SimpleColoredComponent coloredComponent, boolean mainTextOnly, boolean selected) {
    SpeedSearchSupply speedSearch = SpeedSearchSupply.getSupply(speedSearchEnabledComponent);
    // The bad thing is that SpeedSearch model is decoupled from UI presentation so we don't know the real matched text.
    // Our best guess is to get string from the ColoredComponent. We can only provide main-text-only option.
    Iterable<TextRange> ranges = speedSearch == null ? null : speedSearch.matchingFragments(coloredComponent.getCharSequence(mainTextOnly).toString());
    Iterator<TextRange> rangesIterator = ranges != null ? ranges.iterator() : null;
    if (rangesIterator == null || !rangesIterator.hasNext())
        return;
    Color bg = selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground();
    SimpleColoredComponent.ColoredIterator coloredIterator = coloredComponent.iterator();
    TextRange range = rangesIterator.next();
    main: while (coloredIterator.hasNext()) {
        coloredIterator.next();
        int offset = coloredIterator.getOffset();
        int endOffset = coloredIterator.getEndOffset();
        if (!range.intersectsStrict(offset, endOffset))
            continue;
        SimpleTextAttributes attributes = coloredIterator.getTextAttributes();
        SimpleTextAttributes highlighted = new SimpleTextAttributes(bg, attributes.getFgColor(), null, attributes.getStyle() | SimpleTextAttributes.STYLE_SEARCH_MATCH);
        do {
            if (range.getStartOffset() > offset) {
                offset = coloredIterator.split(range.getStartOffset() - offset, attributes);
            }
            if (range.getEndOffset() <= endOffset) {
                offset = coloredIterator.split(range.getEndOffset() - offset, highlighted);
                if (rangesIterator.hasNext()) {
                    range = rangesIterator.next();
                } else {
                    break main;
                }
            } else {
                coloredIterator.split(endOffset - offset, highlighted);
                continue main;
            }
        } while (range.intersectsStrict(offset, endOffset));
    }
}
Also used : SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) TextRange(com.intellij.openapi.util.TextRange) SimpleColoredComponent(com.intellij.ui.SimpleColoredComponent)

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