Search in sources :

Example 21 with TextAttributes

use of com.intellij.openapi.editor.markup.TextAttributes in project intellij-community by JetBrains.

the class ExpectedHighlightingData method extractExpectedHighlight.

private int extractExpectedHighlight(final Matcher matcher, final String text, final Document document, final Ref<Integer> textOffset) {
    document.deleteString(textOffset.get(), textOffset.get() + matcher.end() - matcher.start());
    int groupIdx = 1;
    final String marker = matcher.group(groupIdx++);
    String descr = matcher.group(groupIdx++);
    final String typeString = matcher.group(groupIdx++);
    final String foregroundColor = matcher.group(groupIdx++);
    final String backgroundColor = matcher.group(groupIdx++);
    final String effectColor = matcher.group(groupIdx++);
    final String effectType = matcher.group(groupIdx++);
    final String fontType = matcher.group(groupIdx++);
    final String attrKey = matcher.group(groupIdx++);
    final String bundleMessage = matcher.group(groupIdx++);
    final boolean closed = matcher.group(groupIdx) != null;
    if (descr == null) {
        // no descr means any string by default
        descr = ANY_TEXT;
    } else if (descr.equals("null")) {
        // explicit "null" descr
        descr = null;
    }
    if (descr != null) {
        // replace: \\" to ", doesn't check symbol before sequence \\"
        descr = descr.replaceAll("\\\\\\\\\"", "\"");
        descr = descr.replaceAll("\\\\\"", "\"");
    }
    HighlightInfoType type = WHATEVER;
    if (typeString != null) {
        try {
            type = getTypeByName(typeString);
        } catch (Exception e) {
            LOG.error(e);
        }
        LOG.assertTrue(type != null, "Wrong highlight type: " + typeString);
    }
    TextAttributes forcedAttributes = null;
    if (foregroundColor != null) {
        //noinspection MagicConstant
        forcedAttributes = new TextAttributes(Color.decode(foregroundColor), Color.decode(backgroundColor), Color.decode(effectColor), EffectType.valueOf(effectType), Integer.parseInt(fontType));
    }
    final int rangeStart = textOffset.get();
    final int toContinueFrom;
    if (closed) {
        toContinueFrom = matcher.end();
    } else {
        int pos = matcher.end();
        final Matcher closingTagMatcher = Pattern.compile("</" + marker + ">").matcher(text);
        while (true) {
            if (!closingTagMatcher.find(pos)) {
                LOG.error("Cannot find closing </" + marker + "> in position " + pos);
            }
            final int nextTagStart = matcher.find(pos) ? matcher.start() : text.length();
            if (closingTagMatcher.start() < nextTagStart) {
                textOffset.set(textOffset.get() + closingTagMatcher.start() - pos);
                document.deleteString(textOffset.get(), textOffset.get() + closingTagMatcher.end() - closingTagMatcher.start());
                toContinueFrom = closingTagMatcher.end();
                break;
            }
            textOffset.set(textOffset.get() + nextTagStart - pos);
            pos = extractExpectedHighlight(matcher, text, document, textOffset);
        }
    }
    final ExpectedHighlightingSet expectedHighlightingSet = myHighlightingTypes.get(marker);
    if (expectedHighlightingSet.enabled) {
        TextAttributesKey forcedTextAttributesKey = attrKey == null ? null : TextAttributesKey.createTextAttributesKey(attrKey);
        HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(type).range(rangeStart, textOffset.get()).severity(expectedHighlightingSet.severity);
        if (forcedAttributes != null)
            builder.textAttributes(forcedAttributes);
        if (forcedTextAttributesKey != null)
            builder.textAttributes(forcedTextAttributesKey);
        if (bundleMessage != null) {
            final List<String> split = StringUtil.split(bundleMessage, "|");
            final ResourceBundle bundle = ResourceBundle.getBundle(split.get(0));
            descr = CommonBundle.message(bundle, split.get(1), split.stream().skip(2).toArray());
        }
        if (descr != null) {
            builder.description(descr);
            builder.unescapedToolTip(descr);
        }
        if (expectedHighlightingSet.endOfLine)
            builder.endOfLine();
        HighlightInfo highlightInfo = builder.createUnconditionally();
        expectedHighlightingSet.infos.add(highlightInfo);
    }
    return toContinueFrom;
}
Also used : Matcher(java.util.regex.Matcher) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) HighlightInfoType(com.intellij.codeInsight.daemon.impl.HighlightInfoType) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes)

Example 22 with TextAttributes

use of com.intellij.openapi.editor.markup.TextAttributes in project intellij-community by JetBrains.

the class BreakpointItem method showInEditor.

protected static void showInEditor(DetailView panel, VirtualFile virtualFile, int line) {
    TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(DebuggerColors.BREAKPOINT_ATTRIBUTES);
    DetailView.PreviewEditorState state = DetailView.PreviewEditorState.create(virtualFile, line, attributes);
    if (state.equals(panel.getEditorState())) {
        return;
    }
    panel.navigateInPreviewEditor(state);
    TextAttributes softerAttributes = attributes.clone();
    Color backgroundColor = softerAttributes.getBackgroundColor();
    if (backgroundColor != null) {
        softerAttributes.setBackgroundColor(ColorUtil.softer(backgroundColor));
    }
    final Editor editor = panel.getEditor();
    if (editor != null) {
        final MarkupModel editorModel = editor.getMarkupModel();
        final MarkupModel documentModel = DocumentMarkupModel.forDocument(editor.getDocument(), editor.getProject(), false);
        for (RangeHighlighter highlighter : documentModel.getAllHighlighters()) {
            if (highlighter.getUserData(DebuggerColors.BREAKPOINT_HIGHLIGHTER_KEY) == Boolean.TRUE) {
                final int line1 = editor.offsetToLogicalPosition(highlighter.getStartOffset()).line;
                if (line1 != line) {
                    editorModel.addLineHighlighter(line1, DebuggerColors.BREAKPOINT_HIGHLIGHTER_LAYER + 1, softerAttributes);
                }
            }
        }
    }
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) DetailView(com.intellij.ui.popup.util.DetailView) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) Editor(com.intellij.openapi.editor.Editor) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel) MarkupModel(com.intellij.openapi.editor.markup.MarkupModel)

Example 23 with TextAttributes

use of com.intellij.openapi.editor.markup.TextAttributes in project intellij-community by JetBrains.

the class AbstractValueHint method invokeHint.

public void invokeHint(Runnable hideRunnable) {
    myHideRunnable = hideRunnable;
    if (!canShowHint()) {
        hideHint();
        return;
    }
    if (myType == ValueHintType.MOUSE_ALT_OVER_HINT) {
        EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
        TextAttributes attributes = scheme.getAttributes(EditorColors.REFERENCE_HYPERLINK_COLOR);
        attributes = NavigationUtil.patchAttributesColor(attributes, myCurrentRange, myEditor);
        myHighlighter = myEditor.getMarkupModel().addRangeHighlighter(myCurrentRange.getStartOffset(), myCurrentRange.getEndOffset(), HighlighterLayer.HYPERLINK, attributes, HighlighterTargetArea.EXACT_RANGE);
        Component internalComponent = myEditor.getContentComponent();
        myStoredCursor = internalComponent.getCursor();
        internalComponent.addKeyListener(myEditorKeyListener);
        internalComponent.setCursor(hintCursor());
        if (LOG.isDebugEnabled()) {
            LOG.debug("internalComponent.setCursor(hintCursor())");
        }
    } else {
        evaluateAndShowHint();
    }
}
Also used : TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme)

Example 24 with TextAttributes

use of com.intellij.openapi.editor.markup.TextAttributes in project intellij-community by JetBrains.

the class MethodHierarchyNodeDescriptor method update.

public final boolean update() {
    int flags = Iconable.ICON_FLAG_VISIBILITY;
    if (isMarkReadOnly()) {
        flags |= Iconable.ICON_FLAG_READ_STATUS;
    }
    boolean changes = super.update();
    final PsiElement psiClass = getPsiClass();
    if (psiClass == null) {
        final String invalidPrefix = IdeBundle.message("node.hierarchy.invalid");
        if (!myHighlightedText.getText().startsWith(invalidPrefix)) {
            myHighlightedText.getBeginning().addText(invalidPrefix, HierarchyNodeDescriptor.getInvalidPrefixAttributes());
        }
        return true;
    }
    final Icon newRawIcon = psiClass.getIcon(flags);
    final Icon newStateIcon = psiClass instanceof PsiClass ? calculateState((PsiClass) psiClass) : AllIcons.Hierarchy.MethodDefined;
    if (changes || newRawIcon != myRawIcon || newStateIcon != myStateIcon) {
        changes = true;
        myRawIcon = newRawIcon;
        myStateIcon = newStateIcon;
        Icon newIcon = myRawIcon;
        if (myIsBase) {
            final LayeredIcon icon = new LayeredIcon(2);
            icon.setIcon(newIcon, 0);
            icon.setIcon(AllIcons.Hierarchy.Base, 1, -AllIcons.Hierarchy.Base.getIconWidth() / 2, 0);
            newIcon = icon;
        }
        if (myStateIcon != null) {
            newIcon = new RowIcon(myStateIcon, newIcon);
        }
        setIcon(newIcon);
    }
    final CompositeAppearance oldText = myHighlightedText;
    myHighlightedText = new CompositeAppearance();
    TextAttributes classNameAttributes = null;
    if (myColor != null) {
        classNameAttributes = new TextAttributes(myColor, null, null, null, Font.PLAIN);
    }
    if (psiClass instanceof PsiClass) {
        myHighlightedText.getEnding().addText(ClassPresentationUtil.getNameForClass((PsiClass) psiClass, false), classNameAttributes);
        myHighlightedText.getEnding().addText("  (" + JavaHierarchyUtil.getPackageName((PsiClass) psiClass) + ")", HierarchyNodeDescriptor.getPackageNameAttributes());
    } else if (psiClass instanceof PsiFunctionalExpression) {
        myHighlightedText.getEnding().addText(ClassPresentationUtil.getFunctionalExpressionPresentation((PsiFunctionalExpression) psiClass, false));
    }
    myName = myHighlightedText.getText();
    if (!Comparing.equal(myHighlightedText, oldText)) {
        changes = true;
    }
    return changes;
}
Also used : LayeredIcon(com.intellij.ui.LayeredIcon) CompositeAppearance(com.intellij.openapi.roots.ui.util.CompositeAppearance) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) RowIcon(com.intellij.ui.RowIcon) LayeredIcon(com.intellij.ui.LayeredIcon) RowIcon(com.intellij.ui.RowIcon)

Example 25 with TextAttributes

use of com.intellij.openapi.editor.markup.TextAttributes in project intellij-community by JetBrains.

the class TypeHierarchyNodeDescriptor method update.

public final boolean update() {
    boolean changes = super.update();
    if (getPsiElement() == null) {
        final String invalidPrefix = IdeBundle.message("node.hierarchy.invalid");
        if (!myHighlightedText.getText().startsWith(invalidPrefix)) {
            myHighlightedText.getBeginning().addText(invalidPrefix, HierarchyNodeDescriptor.getInvalidPrefixAttributes());
        }
        return true;
    }
    if (changes && myIsBase) {
        final LayeredIcon icon = new LayeredIcon(2);
        icon.setIcon(getIcon(), 0);
        icon.setIcon(AllIcons.Hierarchy.Base, 1, -AllIcons.Hierarchy.Base.getIconWidth() / 2, 0);
        setIcon(icon);
    }
    final PsiElement psiElement = getPsiClass();
    final CompositeAppearance oldText = myHighlightedText;
    myHighlightedText = new CompositeAppearance();
    TextAttributes classNameAttributes = null;
    if (myColor != null) {
        classNameAttributes = new TextAttributes(myColor, null, null, null, Font.PLAIN);
    }
    if (psiElement instanceof PsiClass) {
        myHighlightedText.getEnding().addText(ClassPresentationUtil.getNameForClass((PsiClass) psiElement, false), classNameAttributes);
        myHighlightedText.getEnding().addText(" (" + JavaHierarchyUtil.getPackageName((PsiClass) psiElement) + ")", HierarchyNodeDescriptor.getPackageNameAttributes());
    } else if (psiElement instanceof PsiFunctionalExpression) {
        myHighlightedText.getEnding().addText(ClassPresentationUtil.getFunctionalExpressionPresentation(((PsiFunctionalExpression) psiElement), false));
    }
    myName = myHighlightedText.getText();
    if (!Comparing.equal(myHighlightedText, oldText)) {
        changes = true;
    }
    return changes;
}
Also used : LayeredIcon(com.intellij.ui.LayeredIcon) PsiFunctionalExpression(com.intellij.psi.PsiFunctionalExpression) PsiClass(com.intellij.psi.PsiClass) CompositeAppearance(com.intellij.openapi.roots.ui.util.CompositeAppearance) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) PsiElement(com.intellij.psi.PsiElement)

Aggregations

TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)215 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)40 TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)33 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)31 NotNull (org.jetbrains.annotations.NotNull)29 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)28 HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)26 TextRange (com.intellij.openapi.util.TextRange)23 SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)23 Nullable (org.jetbrains.annotations.Nullable)21 Project (com.intellij.openapi.project.Project)20 Editor (com.intellij.openapi.editor.Editor)19 ArrayList (java.util.ArrayList)19 PsiElement (com.intellij.psi.PsiElement)12 HighlightInfoType (com.intellij.codeInsight.daemon.impl.HighlightInfoType)11 JBColor (com.intellij.ui.JBColor)11 HighlightSeverity (com.intellij.lang.annotation.HighlightSeverity)10 Document (com.intellij.openapi.editor.Document)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)10 ContainerUtil (com.intellij.util.containers.ContainerUtil)9