Search in sources :

Example 31 with TextAttributesKey

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

the class EventLogConsole method doPrintNotification.

void doPrintNotification(final Notification notification) {
    Editor editor = getConsoleEditor();
    if (editor.isDisposed()) {
        return;
    }
    Document document = editor.getDocument();
    boolean scroll = document.getTextLength() == editor.getCaretModel().getOffset() || !editor.getContentComponent().hasFocus();
    if (document.getTextLength() > 0) {
        append(document, "\n");
    }
    String lastDate = DateFormatUtil.formatDate(notification.getTimestamp());
    if (document.getTextLength() == 0 || !lastDate.equals(myLastDate)) {
        myLastDate = lastDate;
        append(document, lastDate + "\n");
    }
    int startDateOffset = document.getTextLength();
    String date = DateFormatUtil.formatTime(notification.getTimestamp()) + "\t";
    append(document, date);
    int tabs = calculateTabs(editor, startDateOffset);
    int titleStartOffset = document.getTextLength();
    int startLine = document.getLineCount() - 1;
    EventLog.LogEntry pair = EventLog.formatForLog(notification, StringUtil.repeatSymbol('\t', tabs));
    final NotificationType type = notification.getType();
    TextAttributesKey key = type == NotificationType.ERROR ? ConsoleViewContentType.LOG_ERROR_OUTPUT_KEY : type == NotificationType.INFORMATION ? ConsoleViewContentType.NORMAL_OUTPUT_KEY : ConsoleViewContentType.LOG_WARNING_OUTPUT_KEY;
    int msgStart = document.getTextLength();
    append(document, pair.message);
    TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(key);
    int layer = HighlighterLayer.CARET_ROW + 1;
    RangeHighlighter highlighter = editor.getMarkupModel().addRangeHighlighter(msgStart, document.getTextLength(), layer, attributes, HighlighterTargetArea.EXACT_RANGE);
    GROUP_ID.set(highlighter, notification.getGroupId());
    NOTIFICATION_ID.set(highlighter, notification.id);
    for (Pair<TextRange, HyperlinkInfo> link : pair.links) {
        final RangeHighlighter rangeHighlighter = myHyperlinkSupport.getValue().createHyperlink(link.first.getStartOffset() + msgStart, link.first.getEndOffset() + msgStart, null, link.second);
        if (link.second instanceof EventLog.ShowBalloon) {
            ((EventLog.ShowBalloon) link.second).setRangeHighlighter(rangeHighlighter);
        }
    }
    append(document, "\n");
    if (scroll) {
        editor.getCaretModel().moveToOffset(document.getTextLength());
        editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
    }
    if (notification.isImportant()) {
        highlightNotification(notification, pair.status, startLine, document.getLineCount() - 1, titleStartOffset, pair.titleLength);
    }
}
Also used : TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) RelativePoint(com.intellij.ui.awt.RelativePoint) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo)

Example 32 with TextAttributesKey

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

the class PsiElementListCellRenderer method getNavigationItemAttributes.

@Nullable
protected TextAttributes getNavigationItemAttributes(Object value) {
    TextAttributes attributes = null;
    if (value instanceof NavigationItem) {
        TextAttributesKey attributesKey = null;
        final ItemPresentation presentation = ((NavigationItem) value).getPresentation();
        if (presentation instanceof ColoredItemPresentation)
            attributesKey = ((ColoredItemPresentation) presentation).getTextAttributesKey();
        if (attributesKey != null) {
            attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(attributesKey);
        }
    }
    return attributes;
}
Also used : NavigationItem(com.intellij.navigation.NavigationItem) ColoredItemPresentation(com.intellij.navigation.ColoredItemPresentation) ColoredItemPresentation(com.intellij.navigation.ColoredItemPresentation) ItemPresentation(com.intellij.navigation.ItemPresentation) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) Nullable(org.jetbrains.annotations.Nullable)

Example 33 with TextAttributesKey

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

the class HighlightNamesUtil method getScopeAttributes.

private static TextAttributes getScopeAttributes(@NotNull PsiElement element, @NotNull TextAttributesScheme colorsScheme) {
    PsiFile file = element.getContainingFile();
    if (file == null)
        return null;
    TextAttributes result = null;
    DependencyValidationManagerImpl validationManager = (DependencyValidationManagerImpl) DependencyValidationManager.getInstance(file.getProject());
    List<Pair<NamedScope, NamedScopesHolder>> scopes = validationManager.getScopeBasedHighlightingCachedScopes();
    for (Pair<NamedScope, NamedScopesHolder> scope : scopes) {
        final NamedScope namedScope = scope.getFirst();
        final TextAttributesKey scopeKey = ScopeAttributesUtil.getScopeTextAttributeKey(namedScope.getName());
        final TextAttributes attributes = colorsScheme.getAttributes(scopeKey);
        if (attributes == null || attributes.isEmpty()) {
            continue;
        }
        final PackageSet packageSet = namedScope.getValue();
        if (packageSet != null && packageSet.contains(file, scope.getSecond())) {
            result = TextAttributes.merge(attributes, result);
        }
    }
    return result;
}
Also used : NamedScope(com.intellij.psi.search.scope.packageSet.NamedScope) NamedScopesHolder(com.intellij.psi.search.scope.packageSet.NamedScopesHolder) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) PackageSet(com.intellij.psi.search.scope.packageSet.PackageSet) DependencyValidationManagerImpl(com.intellij.packageDependencies.DependencyValidationManagerImpl) Pair(com.intellij.openapi.util.Pair)

Example 34 with TextAttributesKey

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

the class JavaRearranger method getAttributes.

@Nullable
private static TextAttributes getAttributes(@NotNull EditorColorsScheme scheme, @NotNull TextAttributesKey... keys) {
    TextAttributes result = null;
    for (TextAttributesKey key : keys) {
        TextAttributes attributes = scheme.getAttributes(key).clone();
        if (attributes == null) {
            continue;
        }
        if (result == null) {
            result = attributes;
        }
        Color currentForegroundColor = result.getForegroundColor();
        if (currentForegroundColor == null) {
            result.setForegroundColor(attributes.getForegroundColor());
        }
        Color currentBackgroundColor = result.getBackgroundColor();
        if (currentBackgroundColor == null) {
            result.setBackgroundColor(attributes.getBackgroundColor());
        }
        if (result.getForegroundColor() != null && result.getBackgroundColor() != null) {
            return result;
        }
    }
    if (result != null && result.getForegroundColor() == null) {
        return null;
    }
    if (result != null && result.getBackgroundColor() == null) {
        result.setBackgroundColor(scheme.getDefaultBackground());
    }
    return result;
}
Also used : TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) Nullable(org.jetbrains.annotations.Nullable)

Example 35 with TextAttributesKey

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

the class ProblemDescriptorUtil method highlightTypeFromDescriptor.

@NotNull
public static HighlightInfoType highlightTypeFromDescriptor(@NotNull ProblemDescriptor problemDescriptor, @NotNull HighlightSeverity severity, @NotNull SeverityRegistrar severityRegistrar) {
    final ProblemHighlightType highlightType = problemDescriptor.getHighlightType();
    final HighlightInfoType highlightInfoType = getHighlightInfoType(highlightType, severity, severityRegistrar);
    if (highlightInfoType == HighlightSeverity.INFORMATION) {
        final TextAttributesKey attributes = ((ProblemDescriptorBase) problemDescriptor).getEnforcedTextAttributes();
        if (attributes != null) {
            return new HighlightInfoType.HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, attributes);
        }
    }
    return highlightInfoType;
}
Also used : TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) HighlightInfoType(com.intellij.codeInsight.daemon.impl.HighlightInfoType) NotNull(org.jetbrains.annotations.NotNull)

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