private void setSyntaxTheme(int tokenType, String id) { Style style = getSyntaxScheme().getStyle(tokenType); Map<String, Object> styledFont = processing.app.Theme.getStyledFont(id, style.font); style.foreground = (Color) styledFont.get("color"); style.font = (Font) styledFont.get("font"); getSyntaxScheme().setStyle(tokenType, style); }
/** * Update the color in the default style of the document. * * @param color the new color to use or null to remove the color attribute from the document's * style */ private void updateForeground(Color color) { StyledDocument doc = (StyledDocument) getComponent().getDocument(); Style style = doc.getStyle(StyleContext.DEFAULT_STYLE); if (style == null) { return; } if (color == null) { style.removeAttribute(StyleConstants.Foreground); } else { StyleConstants.setForeground(style, color); } }
private void setTheme(String name) throws IOException { FileInputStream defaultXmlInputStream = null; try { defaultXmlInputStream = new FileInputStream( new File(BaseNoGui.getContentFile("lib"), "theme/syntax/" + name + ".xml")); Theme theme = Theme.load(defaultXmlInputStream); theme.apply(this); } finally { IOUtils.closeQuietly(defaultXmlInputStream); } setBackground(processing.app.Theme.getColor("editor.bgcolor")); setHighlightCurrentLine(processing.app.Theme.getBoolean("editor.linehighlight")); setCurrentLineHighlightColor(processing.app.Theme.getColor("editor.linehighlight.color")); setCaretColor(processing.app.Theme.getColor("editor.caret.color")); setSelectedTextColor(null); setUseSelectedTextColor(false); setSelectionColor(processing.app.Theme.getColor("editor.selection.color")); setMatchedBracketBorderColor(processing.app.Theme.getColor("editor.brackethighlight.color")); setHyperlinkForeground( (Color) processing.app.Theme.getStyledFont("url", getFont()).get("color")); setSyntaxTheme(TokenTypes.DATA_TYPE, "data_type"); setSyntaxTheme(TokenTypes.FUNCTION, "function"); setSyntaxTheme(TokenTypes.RESERVED_WORD, "reserved_word"); setSyntaxTheme(TokenTypes.RESERVED_WORD_2, "reserved_word_2"); setSyntaxTheme(TokenTypes.VARIABLE, "variable"); setSyntaxTheme(TokenTypes.OPERATOR, "operator"); setSyntaxTheme(TokenTypes.COMMENT_DOCUMENTATION, "comment1"); setSyntaxTheme(TokenTypes.COMMENT_EOL, "comment1"); setSyntaxTheme(TokenTypes.COMMENT_KEYWORD, "comment1"); setSyntaxTheme(TokenTypes.COMMENT_MARKUP, "comment1"); setSyntaxTheme(TokenTypes.COMMENT_MULTILINE, "comment2"); setSyntaxTheme(TokenTypes.LITERAL_BOOLEAN, "literal_boolean"); setSyntaxTheme(TokenTypes.LITERAL_CHAR, "literal_char"); setSyntaxTheme(TokenTypes.LITERAL_STRING_DOUBLE_QUOTE, "literal_string_double_quote"); setSyntaxTheme(TokenTypes.PREPROCESSOR, "preprocessor"); Style style = getSyntaxScheme().getStyle(TokenTypes.IDENTIFIER); style.foreground = processing.app.Theme.getColor("editor.fgcolor"); getSyntaxScheme().setStyle(TokenTypes.IDENTIFIER, style); }
/** * Update the font in the default style of the document. * * @param font the new font to use or null to remove the font attribute from the document's style */ private void updateFont(Font font) { StyledDocument doc = (StyledDocument) getComponent().getDocument(); Style style = doc.getStyle(StyleContext.DEFAULT_STYLE); if (style == null) { return; } if (font == null) { style.removeAttribute(StyleConstants.FontFamily); style.removeAttribute(StyleConstants.FontSize); style.removeAttribute(StyleConstants.Bold); style.removeAttribute(StyleConstants.Italic); } else { StyleConstants.setFontFamily(style, font.getName()); StyleConstants.setFontSize(style, font.getSize()); StyleConstants.setBold(style, font.isBold()); StyleConstants.setItalic(style, font.isItalic()); } }
public void displayScriptError(ScriptExceptionContainer se) { errorStyle.addAttribute("ip", se.ip); errorStyle.addAttribute("exception", se.exception); errorStyleRed.addAttribute("ip", se.ip); errorStyleRed.addAttribute("exception", se.exception); errorStyleMono.addAttribute("ip", se.ip); errorStyleMono.addAttribute("exception", se.exception); addStyledText("\n", null); addStyledText("Error", errorStyleRed); addStyledText(" at ", errorStyle); addStyledText(se.ip, errorStyleMono); }