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;
}
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);
}
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);
}
}
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;
}
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();
}
Aggregations