Search in sources :

Example 41 with EditorColorsScheme

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

the class TodoFileNode method updateImpl.

@Override
protected void updateImpl(PresentationData data) {
    super.updateImpl(data);
    String newName;
    if (myBuilder.getTodoTreeStructure().isPackagesShown()) {
        newName = getValue().getName();
    } else {
        newName = mySingleFileMode ? getValue().getName() : getValue().getVirtualFile().getPresentableUrl();
    }
    int nameEndOffset = newName.length();
    int todoItemCount;
    try {
        todoItemCount = myBuilder.getTodoTreeStructure().getTodoItemCount(getValue());
    } catch (IndexNotReadyException e) {
        return;
    }
    if (mySingleFileMode) {
        if (todoItemCount == 0) {
            newName = IdeBundle.message("node.todo.no.items.found", newName);
        } else {
            newName = IdeBundle.message("node.todo.found.items", newName, todoItemCount);
        }
    } else {
        newName = IdeBundle.message("node.todo.items", newName, todoItemCount);
    }
    myHighlightedRegions.clear();
    TextAttributes textAttributes = new TextAttributes();
    textAttributes.setForegroundColor(myColor);
    myHighlightedRegions.add(new HighlightedRegion(0, nameEndOffset, textAttributes));
    EditorColorsScheme colorsScheme = UsageTreeColorsScheme.getInstance().getScheme();
    myHighlightedRegions.add(new HighlightedRegion(nameEndOffset, newName.length(), colorsScheme.getAttributes(UsageTreeColors.NUMBER_OF_USAGES)));
}
Also used : IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) HighlightedRegion(com.intellij.ui.HighlightedRegion) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme)

Example 42 with EditorColorsScheme

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

the class HTMLTextPainter method writeStyles.

private void writeStyles(@NonNls final Writer writer) throws IOException {
    EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
    writer.write("<style type=\"text/css\">\n");
    final Color lineNumbers = scheme.getColor(EditorColors.LINE_NUMBERS_COLOR);
    writer.write(String.format(".ln { color: #%s; font-weight: normal; font-style: normal; }\n", ColorUtil.toHex(lineNumbers == null ? Gray.x00 : lineNumbers)));
    HighlighterIterator hIterator = myHighlighter.createIterator(myOffset);
    while (!hIterator.atEnd()) {
        TextAttributes textAttributes = hIterator.getTextAttributes();
        if (!myStyleMap.containsKey(textAttributes)) {
            @NonNls String styleName = "s" + myStyleMap.size();
            myStyleMap.put(textAttributes, styleName);
            writer.write("." + styleName + " { ");
            Color foreColor = textAttributes.getForegroundColor();
            if (foreColor == null)
                foreColor = scheme.getDefaultForeground();
            writer.write("color: " + colorToHtml(foreColor) + "; ");
            if (BitUtil.isSet(textAttributes.getFontType(), Font.BOLD)) {
                writer.write("font-weight: bold; ");
            }
            if (BitUtil.isSet(textAttributes.getFontType(), Font.ITALIC)) {
                writer.write("font-style: italic; ");
            }
            writer.write("}\n");
        }
        hIterator.advance();
    }
    for (LineMarkerInfo separator : myMethodSeparators) {
        Color color = separator.separatorColor;
        if (color != null && !mySeparatorStyles.containsKey(color)) {
            @NonNls String styleName = "ls" + mySeparatorStyles.size();
            mySeparatorStyles.put(color, styleName);
            String htmlColor = colorToHtml(color);
            writer.write("." + styleName + " { height: 1px; border-width: 0; color: " + htmlColor + "; background-color:" + htmlColor + "}\n");
        }
    }
    writer.write("</style>\n");
}
Also used : NonNls(org.jetbrains.annotations.NonNls) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) JBColor(com.intellij.ui.JBColor) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) HighlighterIterator(com.intellij.openapi.editor.highlighter.HighlighterIterator)

Example 43 with EditorColorsScheme

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

the class BraceHighlightingHandler method highlightBraces.

private void highlightBraces(@Nullable TextRange lBrace, @Nullable TextRange rBrace, boolean matched, boolean scopeHighlighting, @NotNull FileType fileType) {
    if (!matched && fileType == FileTypes.PLAIN_TEXT) {
        return;
    }
    EditorColorsScheme scheme = myEditor.getColorsScheme();
    final TextAttributes attributes = matched ? scheme.getAttributes(CodeInsightColors.MATCHED_BRACE_ATTRIBUTES) : scheme.getAttributes(CodeInsightColors.UNMATCHED_BRACE_ATTRIBUTES);
    if (rBrace != null && !scopeHighlighting) {
        highlightBrace(rBrace, matched);
    }
    if (lBrace != null && !scopeHighlighting) {
        highlightBrace(lBrace, matched);
    }
    // null in default project
    FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);
    if (fileEditorManager == null || !myEditor.equals(fileEditorManager.getSelectedTextEditor())) {
        return;
    }
    if (lBrace != null && rBrace != null) {
        final int startLine = myEditor.offsetToLogicalPosition(lBrace.getStartOffset()).line;
        final int endLine = myEditor.offsetToLogicalPosition(rBrace.getEndOffset()).line;
        if (endLine - startLine > 0) {
            final Runnable runnable = () -> {
                if (myProject.isDisposed() || myEditor.isDisposed())
                    return;
                Color color = attributes.getBackgroundColor();
                if (color == null)
                    return;
                color = ColorUtil.isDark(EditorColorsManager.getInstance().getGlobalScheme().getDefaultBackground()) ? ColorUtil.shift(color, 1.5d) : color.darker();
                lineMarkFragment(startLine, endLine, color);
            };
            if (!scopeHighlighting) {
                myAlarm.addRequest(runnable, 300);
            } else {
                runnable.run();
            }
        } else {
            removeLineMarkers();
        }
        if (!scopeHighlighting) {
            showScopeHint(lBrace.getStartOffset(), lBrace.getEndOffset());
        }
    } else {
        if (!myCodeInsightSettings.HIGHLIGHT_SCOPE) {
            removeLineMarkers();
        }
    }
}
Also used : FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) DumbAwareRunnable(com.intellij.openapi.project.DumbAwareRunnable) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) LightweightHint(com.intellij.ui.LightweightHint)

Example 44 with EditorColorsScheme

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

the class TemplateEditorUtil method createEditor.

private static Editor createEditor(boolean isReadOnly, final Document document, final Project project) {
    EditorFactory editorFactory = EditorFactory.getInstance();
    Editor editor = (isReadOnly ? editorFactory.createViewer(document, project) : editorFactory.createEditor(document, project));
    editor.getContentComponent().setFocusable(!isReadOnly);
    EditorSettings editorSettings = editor.getSettings();
    editorSettings.setVirtualSpace(false);
    editorSettings.setLineMarkerAreaShown(false);
    editorSettings.setIndentGuidesShown(false);
    editorSettings.setLineNumbersShown(false);
    editorSettings.setFoldingOutlineShown(false);
    editorSettings.setCaretRowShown(false);
    EditorColorsScheme scheme = editor.getColorsScheme();
    VirtualFile file = FileDocumentManager.getInstance().getFile(document);
    if (file != null) {
        EditorHighlighter highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(file, scheme, project);
        ((EditorEx) editor).setHighlighter(highlighter);
    }
    return editor;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) EditorFactory(com.intellij.openapi.editor.EditorFactory) EditorSettings(com.intellij.openapi.editor.EditorSettings) EditorEx(com.intellij.openapi.editor.ex.EditorEx) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) Editor(com.intellij.openapi.editor.Editor) LayeredLexerEditorHighlighter(com.intellij.openapi.editor.ex.util.LayeredLexerEditorHighlighter) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter)

Example 45 with EditorColorsScheme

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

the class TemplateEditorUtil method setHighlighter.

private static void setHighlighter(EditorEx editor, @Nullable SyntaxHighlighter highlighter) {
    EditorColorsScheme editorColorsScheme = EditorColorsManager.getInstance().getGlobalScheme();
    LayeredLexerEditorHighlighter layeredHighlighter = new LayeredLexerEditorHighlighter(new TemplateHighlighter(), editorColorsScheme);
    layeredHighlighter.registerLayer(TemplateTokenType.TEXT, new LayerDescriptor(ObjectUtils.notNull(highlighter, new PlainSyntaxHighlighter()), ""));
    editor.setHighlighter(layeredHighlighter);
}
Also used : LayeredLexerEditorHighlighter(com.intellij.openapi.editor.ex.util.LayeredLexerEditorHighlighter) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) LayerDescriptor(com.intellij.openapi.editor.ex.util.LayerDescriptor) PlainSyntaxHighlighter(com.intellij.openapi.fileTypes.PlainSyntaxHighlighter)

Aggregations

EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)103 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)31 NotNull (org.jetbrains.annotations.NotNull)28 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)17 Nullable (org.jetbrains.annotations.Nullable)15 Document (com.intellij.openapi.editor.Document)14 Project (com.intellij.openapi.project.Project)14 TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)12 Editor (com.intellij.openapi.editor.Editor)11 DocumentMarkupModel (com.intellij.openapi.editor.impl.DocumentMarkupModel)10 EditorEx (com.intellij.openapi.editor.ex.EditorEx)8 TextRange (com.intellij.openapi.util.TextRange)8 EditorHighlighter (com.intellij.openapi.editor.highlighter.EditorHighlighter)7 PsiFile (com.intellij.psi.PsiFile)7 List (java.util.List)7 HighlightSeverity (com.intellij.lang.annotation.HighlightSeverity)6 ApplicationManager (com.intellij.openapi.application.ApplicationManager)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 java.awt (java.awt)6 java.util (java.util)6