Search in sources :

Example 96 with EditorColorsScheme

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

the class StudyBrowserWindow method createHtmlWithCodeHighlighting.

@Nullable
private String createHtmlWithCodeHighlighting(@NotNull final String content, @NotNull StudyPluginConfigurator configurator) {
    String template = null;
    InputStream stream = getClass().getResourceAsStream("/code-mirror/template.html");
    try {
        template = StreamUtil.readText(stream, "utf-8");
    } catch (IOException e) {
        LOG.warn(e.getMessage());
    } finally {
        try {
            stream.close();
        } catch (IOException e) {
            LOG.warn(e.getMessage());
        }
    }
    if (template == null) {
        LOG.warn("Code mirror template is null");
        return null;
    }
    final EditorColorsScheme editorColorsScheme = EditorColorsManager.getInstance().getGlobalScheme();
    int fontSize = editorColorsScheme.getEditorFontSize();
    template = template.replace("${font_size}", String.valueOf(fontSize - 2));
    template = template.replace("${codemirror}", getClass().getResource("/code-mirror/codemirror.js").toExternalForm());
    template = template.replace("${language_script}", configurator.getLanguageScriptUrl());
    template = template.replace("${default_mode}", configurator.getDefaultHighlightingMode());
    template = template.replace("${runmode}", getClass().getResource("/code-mirror/runmode.js").toExternalForm());
    template = template.replace("${colorize}", getClass().getResource("/code-mirror/colorize.js").toExternalForm());
    template = template.replace("${javascript}", getClass().getResource("/code-mirror/javascript.js").toExternalForm());
    if (LafManager.getInstance().getCurrentLookAndFeel() instanceof DarculaLookAndFeelInfo) {
        template = template.replace("${css_oldcodemirror}", getClass().getResource("/code-mirror/codemirror-old-darcula.css").toExternalForm());
        template = template.replace("${css_codemirror}", getClass().getResource("/code-mirror/codemirror-darcula.css").toExternalForm());
    } else {
        template = template.replace("${css_oldcodemirror}", getClass().getResource("/code-mirror/codemirror-old.css").toExternalForm());
        template = template.replace("${css_codemirror}", getClass().getResource("/code-mirror/codemirror.css").toExternalForm());
    }
    template = template.replace("${code}", content);
    return template;
}
Also used : InputStream(java.io.InputStream) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) DarculaLookAndFeelInfo(com.intellij.ide.ui.laf.darcula.DarculaLookAndFeelInfo) IOException(java.io.IOException) Nullable(org.jetbrains.annotations.Nullable)

Example 97 with EditorColorsScheme

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

the class EduAnswerPlaceholderPainter method drawAnswerPlaceholderFromPrevStep.

public static void drawAnswerPlaceholderFromPrevStep(@NotNull Editor editor, int start, int end) {
    EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
    Color color = scheme.getColor(EditorColors.TEARLINE_COLOR);
    SimpleTextAttributes attributes = SimpleTextAttributes.GRAY_ATTRIBUTES;
    final TextAttributes textAttributes = new TextAttributes(attributes.getFgColor(), color, null, null, attributes.getFontStyle());
    drawAnswerPlaceholder(editor, start, end, textAttributes, HighlighterLayer.LAST);
}
Also used : JBColor(com.intellij.ui.JBColor) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme)

Example 98 with EditorColorsScheme

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

the class EduAnswerPlaceholderPainter method drawAnswerPlaceholder.

public static void drawAnswerPlaceholder(@NotNull final Editor editor, @NotNull final AnswerPlaceholder placeholder, @NotNull final JBColor color) {
    EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
    final TextAttributes textAttributes = new TextAttributes(scheme.getDefaultForeground(), scheme.getDefaultBackground(), null, EffectType.BOXED, Font.PLAIN);
    textAttributes.setEffectColor(color);
    int startOffset = placeholder.getOffset();
    if (startOffset == -1) {
        return;
    }
    final int length = placeholder.isActive() ? placeholder.getRealLength() : placeholder.getVisibleLength(placeholder.getActiveSubtaskIndex());
    Pair<Integer, Integer> offsets = StudyUtils.getPlaceholderOffsets(placeholder, editor.getDocument());
    startOffset = offsets.first;
    int endOffset = offsets.second;
    if (placeholder.isActive()) {
        drawAnswerPlaceholder(editor, startOffset, endOffset, textAttributes, PLACEHOLDERS_LAYER);
    } else if (!placeholder.getUseLength() && length != 0) {
        drawAnswerPlaceholderFromPrevStep(editor, startOffset, endOffset);
    }
}
Also used : SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme)

Example 99 with EditorColorsScheme

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

the class StudySwingToolWindow method createTaskInfoPanel.

@Override
public JComponent createTaskInfoPanel(Project project) {
    myTaskTextPane = new JTextPane();
    final JBScrollPane scrollPane = new JBScrollPane(myTaskTextPane);
    myTaskTextPane.setContentType(new HTMLEditorKit().getContentType());
    final EditorColorsScheme editorColorsScheme = EditorColorsManager.getInstance().getGlobalScheme();
    int fontSize = editorColorsScheme.getEditorFontSize();
    final String fontName = editorColorsScheme.getEditorFontName();
    final Font font = new Font(fontName, Font.PLAIN, fontSize);
    String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() + "pt; }" + "pre {font-family: Courier; display: inline; ine-height: 50px; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; background-color:" + ColorUtil.toHex(ColorUtil.dimmer(UIUtil.getPanelBackground())) + ";}" + "code {font-family: Courier; display: flex; float: left; background-color:" + ColorUtil.toHex(ColorUtil.dimmer(UIUtil.getPanelBackground())) + ";}";
    ((HTMLDocument) myTaskTextPane.getDocument()).getStyleSheet().addRule(bodyRule);
    myTaskTextPane.setEditable(false);
    if (!UIUtil.isUnderDarcula()) {
        myTaskTextPane.setBackground(EditorColorsManager.getInstance().getGlobalScheme().getDefaultBackground());
    }
    myTaskTextPane.setBorder(new EmptyBorder(20, 20, 0, 10));
    myTaskTextPane.addHyperlinkListener(BrowserHyperlinkListener.INSTANCE);
    return scrollPane;
}
Also used : HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) EmptyBorder(javax.swing.border.EmptyBorder) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 100 with EditorColorsScheme

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

the class PythonHighlightingTest method testDeclarations.

public void testDeclarations() {
    EditorColorsManager manager = EditorColorsManager.getInstance();
    EditorColorsScheme scheme = (EditorColorsScheme) manager.getGlobalScheme().clone();
    manager.addColorsScheme(scheme);
    EditorColorsManager.getInstance().setGlobalScheme(scheme);
    TextAttributesKey xKey = TextAttributesKey.find("PY.CLASS_DEFINITION");
    TextAttributes xAttributes = new TextAttributes(Color.blue, Color.black, Color.white, EffectType.BOXED, Font.BOLD);
    scheme.setAttributes(xKey, xAttributes);
    xKey = TextAttributesKey.find("PY.FUNC_DEFINITION");
    xAttributes = new TextAttributes(Color.red, Color.black, Color.white, EffectType.BOXED, Font.BOLD);
    scheme.setAttributes(xKey, xAttributes);
    xKey = TextAttributesKey.find("PY.PREDEFINED_DEFINITION");
    xAttributes = new TextAttributes(Color.green, Color.black, Color.white, EffectType.BOXED, Font.BOLD);
    scheme.setAttributes(xKey, xAttributes);
    doTest();
}
Also used : TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey)

Aggregations

EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)105 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