Search in sources :

Example 41 with TextAttributesKey

use of com.intellij.openapi.editor.colors.TextAttributesKey in project intellij-community by JetBrains.

the class ChunkExtractor method createTextChunks.

@NotNull
public TextChunk[] createTextChunks(@NotNull UsageInfo2UsageAdapter usageInfo2UsageAdapter, @NotNull CharSequence chars, int start, int end, boolean selectUsageWithBold, @NotNull List<TextChunk> result) {
    final Lexer lexer = myHighlighter.getHighlightingLexer();
    final SyntaxHighlighterOverEditorHighlighter highlighter = myHighlighter;
    LOG.assertTrue(start <= end);
    int i = StringUtil.indexOf(chars, '\n', start, end);
    if (i != -1)
        end = i;
    if (myDocumentStamp != myDocument.getModificationStamp()) {
        highlighter.restart(chars);
        myDocumentStamp = myDocument.getModificationStamp();
    } else if (lexer.getTokenType() == null || lexer.getTokenStart() > start) {
        // todo restart from nearest position with initial state
        highlighter.resetPosition(0);
    }
    boolean isBeginning = true;
    for (; lexer.getTokenType() != null; lexer.advance()) {
        int hiStart = lexer.getTokenStart();
        int hiEnd = lexer.getTokenEnd();
        if (hiStart >= end)
            break;
        hiStart = Math.max(hiStart, start);
        hiEnd = Math.min(hiEnd, end);
        if (hiStart >= hiEnd) {
            continue;
        }
        if (isBeginning) {
            String text = chars.subSequence(hiStart, hiEnd).toString();
            if (text.trim().isEmpty())
                continue;
        }
        isBeginning = false;
        IElementType tokenType = lexer.getTokenType();
        TextAttributesKey[] tokenHighlights = highlighter.getTokenHighlights(tokenType);
        processIntersectingRange(usageInfo2UsageAdapter, chars, hiStart, hiEnd, tokenHighlights, selectUsageWithBold, result);
    }
    return result.toArray(new TextChunk[result.size()]);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) Lexer(com.intellij.lexer.Lexer) SyntaxHighlighterOverEditorHighlighter(com.intellij.usages.impl.SyntaxHighlighterOverEditorHighlighter) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) NotNull(org.jetbrains.annotations.NotNull)

Example 42 with TextAttributesKey

use of com.intellij.openapi.editor.colors.TextAttributesKey in project intellij-community by JetBrains.

the class ResourceBundlePropertyStructureViewElement method getPresentation.

@Override
@NotNull
public ItemPresentation getPresentation() {
    return new ResourceBundleEditorRenderer.TextAttributesPresentation() {

        @Override
        public String getPresentableText() {
            return myPresentableName == null ? getProperty().getName() : myPresentableName.isEmpty() ? PROPERTY_GROUP_KEY_TEXT : myPresentableName;
        }

        @Override
        public String getLocationString() {
            return null;
        }

        @Override
        public Icon getIcon(boolean open) {
            return PlatformIcons.PROPERTY_ICON;
        }

        @Override
        public TextAttributes getTextAttributes(EditorColorsScheme colorsScheme) {
            final TextAttributesKey baseAttrKey = (myPresentableName != null && myPresentableName.isEmpty()) ? GROUP_KEY : PropertiesHighlighter.PROPERTY_KEY;
            final TextAttributes baseAttrs = colorsScheme.getAttributes(baseAttrKey);
            if (getProperty().getPsiElement().isValid()) {
                if (myInspectedPropertyProblems != null) {
                    TextAttributes highlightingAttributes = myInspectedPropertyProblems.getTextAttributes(colorsScheme);
                    if (highlightingAttributes != null) {
                        return TextAttributes.merge(baseAttrs, highlightingAttributes);
                    }
                }
            }
            return baseAttrs;
        }
    };
}
Also used : TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) NotNull(org.jetbrains.annotations.NotNull)

Example 43 with TextAttributesKey

use of com.intellij.openapi.editor.colors.TextAttributesKey in project intellij-community by JetBrains.

the class ComponentTree method getAttribute.

private SimpleTextAttributes getAttribute(@NotNull final SimpleTextAttributes attrs, @Nullable HighlightDisplayLevel level) {
    if (level == null) {
        return attrs;
    }
    Map<SimpleTextAttributes, SimpleTextAttributes> highlightMap = myHighlightAttributes.get(level.getSeverity());
    if (highlightMap == null) {
        highlightMap = new HashMap<>();
        myHighlightAttributes.put(level.getSeverity(), highlightMap);
    }
    SimpleTextAttributes result = highlightMap.get(attrs);
    if (result == null) {
        final TextAttributesKey attrKey = SeverityRegistrar.getSeverityRegistrar(myProject).getHighlightInfoTypeBySeverity(level.getSeverity()).getAttributesKey();
        TextAttributes textAttrs = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(attrKey);
        textAttrs = TextAttributes.merge(attrs.toTextAttributes(), textAttrs);
        result = SimpleTextAttributes.fromTextAttributes(textAttrs);
        highlightMap.put(attrs, result);
    }
    return result;
}
Also used : SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey)

Example 44 with TextAttributesKey

use of com.intellij.openapi.editor.colors.TextAttributesKey in project intellij-community by JetBrains.

the class ColoredCommanderRenderer method customizeCellRenderer.

@Override
protected void customizeCellRenderer(@NotNull final JList list, final Object value, final int index, final boolean selected, final boolean hasFocus) {
    // Fix GTK background
    if (UIUtil.isUnderGTKLookAndFeel()) {
        final Color background = selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground();
        UIUtil.changeBackGround(this, background);
    }
    Color color = UIUtil.getListForeground();
    SimpleTextAttributes attributes = null;
    String locationString = null;
    // for separator, see below
    setBorder(BorderFactory.createEmptyBorder(1, 0, 1, 0));
    if (value instanceof NodeDescriptor) {
        final NodeDescriptor descriptor = (NodeDescriptor) value;
        setIcon(descriptor.getIcon());
        final Color elementColor = descriptor.getColor();
        if (elementColor != null) {
            color = elementColor;
        }
        if (descriptor instanceof AbstractTreeNode) {
            final AbstractTreeNode treeNode = (AbstractTreeNode) descriptor;
            final TextAttributesKey attributesKey = treeNode.getAttributesKey();
            if (attributesKey != null) {
                final TextAttributes textAttributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(attributesKey);
                if (textAttributes != null)
                    attributes = SimpleTextAttributes.fromTextAttributes(textAttributes);
            }
            locationString = treeNode.getLocationString();
            final PresentationData presentation = treeNode.getPresentation();
            if (presentation.hasSeparatorAbove() && !selected) {
                setBorder(BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, GroupedElementsRenderer.POPUP_SEPARATOR_FOREGROUND), BorderFactory.createEmptyBorder(0, 0, 1, 0)));
            }
        }
    }
    if (attributes == null)
        attributes = new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, color);
    final String text = value.toString();
    if (myCommanderPanel.isEnableSearchHighlighting()) {
        JList list1 = myCommanderPanel.getList();
        if (list1 != null) {
            SpeedSearchUtil.appendFragmentsForSpeedSearch(list1, text, attributes, selected, this);
        }
    } else {
        append(text != null ? text : "", attributes);
    }
    if (locationString != null && locationString.length() > 0) {
        append(" (" + locationString + ")", SimpleTextAttributes.GRAY_ATTRIBUTES);
    }
}
Also used : PresentationData(com.intellij.ide.projectView.PresentationData) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) NodeDescriptor(com.intellij.ide.util.treeView.NodeDescriptor) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey)

Example 45 with TextAttributesKey

use of com.intellij.openapi.editor.colors.TextAttributesKey in project intellij-community by JetBrains.

the class InjectedGeneralHighlightingPass method highlightInjectedSyntax.

private void highlightInjectedSyntax(@NotNull PsiFile injectedPsi, @NotNull HighlightInfoHolder holder) {
    List<Trinity<IElementType, SmartPsiElementPointer<PsiLanguageInjectionHost>, TextRange>> tokens = InjectedLanguageUtil.getHighlightTokens(injectedPsi);
    if (tokens == null)
        return;
    final Language injectedLanguage = injectedPsi.getLanguage();
    Project project = injectedPsi.getProject();
    SyntaxHighlighter syntaxHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(injectedLanguage, project, injectedPsi.getVirtualFile());
    final TextAttributes defaultAttrs = myGlobalScheme.getAttributes(HighlighterColors.TEXT);
    for (Trinity<IElementType, SmartPsiElementPointer<PsiLanguageInjectionHost>, TextRange> token : tokens) {
        ProgressManager.checkCanceled();
        IElementType tokenType = token.getFirst();
        PsiLanguageInjectionHost injectionHost = token.getSecond().getElement();
        if (injectionHost == null)
            continue;
        TextRange textRange = token.getThird();
        TextAttributesKey[] keys = syntaxHighlighter.getTokenHighlights(tokenType);
        if (textRange.getLength() == 0)
            continue;
        TextRange annRange = textRange.shiftRight(injectionHost.getTextRange().getStartOffset());
        // force attribute colors to override host' ones
        TextAttributes attributes = null;
        for (TextAttributesKey key : keys) {
            TextAttributes attrs2 = myGlobalScheme.getAttributes(key);
            if (attrs2 != null) {
                attributes = attributes == null ? attrs2 : TextAttributes.merge(attributes, attrs2);
            }
        }
        TextAttributes forcedAttributes;
        if (attributes == null || attributes.isEmpty() || attributes.equals(defaultAttrs)) {
            forcedAttributes = TextAttributes.ERASE_MARKER;
        } else {
            HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.INJECTED_LANGUAGE_FRAGMENT).range(annRange).textAttributes(TextAttributes.ERASE_MARKER).createUnconditionally();
            holder.add(info);
            forcedAttributes = new TextAttributes(attributes.getForegroundColor(), attributes.getBackgroundColor(), attributes.getEffectColor(), attributes.getEffectType(), attributes.getFontType());
        }
        HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.INJECTED_LANGUAGE_FRAGMENT).range(annRange).textAttributes(forcedAttributes).createUnconditionally();
        holder.add(info);
    }
}
Also used : SyntaxHighlighter(com.intellij.openapi.fileTypes.SyntaxHighlighter) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) IElementType(com.intellij.psi.tree.IElementType) Project(com.intellij.openapi.project.Project) Language(com.intellij.lang.Language) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes)

Aggregations

TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)49 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)28 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)12 NotNull (org.jetbrains.annotations.NotNull)9 IElementType (com.intellij.psi.tree.IElementType)8 HighlightInfoType (com.intellij.codeInsight.daemon.impl.HighlightInfoType)7 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)6 SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)6 TextRange (com.intellij.openapi.util.TextRange)5 HighlightSeverity (com.intellij.lang.annotation.HighlightSeverity)4 HighlightData (com.intellij.application.options.colors.highlighting.HighlightData)3 PresentationData (com.intellij.ide.projectView.PresentationData)3 Language (com.intellij.lang.Language)3 Lexer (com.intellij.lexer.Lexer)3 SyntaxHighlighter (com.intellij.openapi.fileTypes.SyntaxHighlighter)3 AttributesDescriptor (com.intellij.openapi.options.colors.AttributesDescriptor)3 Project (com.intellij.openapi.project.Project)3 Pair (com.intellij.openapi.util.Pair)3 PsiElement (com.intellij.psi.PsiElement)3 NamedScope (com.intellij.psi.search.scope.packageSet.NamedScope)3