use of javax.swing.text.StyleContext in project gradle by gradle.
the class OutputPanel method createSearchPanel.
private Component createSearchPanel() {
StyleContext styleContent = StyleContext.getDefaultStyleContext();
AttributeSet highlightStyle = gradleOutputTextPane.getDefaultStyle().copyAttributes();
highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Foreground, Color.white);
highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Background, Color.orange);
highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Underline, true);
AttributeSet emphasizedHighlightStyle = highlightStyle.copyAttributes();
emphasizedHighlightStyle = styleContent.addAttribute(emphasizedHighlightStyle, StyleConstants.Foreground, Color.black);
emphasizedHighlightStyle = styleContent.addAttribute(emphasizedHighlightStyle, StyleConstants.Background, Color.yellow);
searchPanel = new SearchPanel(new OutputPanelSearchInteraction(gradleOutputTextPane.getTextComponent(), gradleOutputTextPane.getDefaultStyle(), highlightStyle, emphasizedHighlightStyle));
searchPanel.hide();
return searchPanel.getComponent();
}
use of javax.swing.text.StyleContext in project MtgDesktopCompanion by nicho92.
the class MagicTextPane method updateTextWithIcons.
public void updateTextWithIcons() {
setText(getText().replaceAll("CHAOS", "{CHAOS}"));
setText(getText().replaceAll("(?m)^[ \t]*\r?\n", ""));
String regex = "\\{(.*?)\\}";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(getText());
String text = getText();
StyleContext context = new StyleContext();
StyledDocument document = new DefaultStyledDocument(context);
Style labelStyle = context.getStyle(StyleContext.DEFAULT_STYLE);
Style italic = context.addStyle("italicStyle", labelStyle);
StyleConstants.setItalic(italic, true);
int cumule = 0;
try {
document.insertString(0, text, null);
while (m.find()) {
Image ic = manaPanel.getManaSymbol(m.group());
int width = 15;
if (m.group().equals("{100}"))
width = 30;
JLabel label = new JLabel(new ImageIcon(ic.getScaledInstance(width, 15, Image.SCALE_DEFAULT)));
label.setAlignmentY(JLabel.TOP);
StyleConstants.setComponent(labelStyle, label);
document.remove(m.start() + cumule, (m.end() - m.start()));
document.insertString(m.start() + cumule, m.group(), labelStyle);
}
setDocument(document);
} catch (BadLocationException e) {
setText(text);
}
}
use of javax.swing.text.StyleContext in project emuRox by rossdrew.
the class DebuggerWindow method getCodeArea.
private JTextPane getCodeArea() {
final StyleContext sc = new StyleContext();
final DefaultStyledDocument doc = new DefaultStyledDocument(sc);
final JTextPane codeArea = new JTextPane(doc);
codeArea.setBackground(new Color(0x25401C));
codeArea.setCaretColor(new Color(0xD1E8CE));
final Style bodyStyle = sc.addStyle("body", null);
bodyStyle.addAttribute(StyleConstants.Foreground, new Color(0x789C6C));
bodyStyle.addAttribute(StyleConstants.FontSize, 13);
bodyStyle.addAttribute(StyleConstants.FontFamily, "monospaced");
bodyStyle.addAttribute(StyleConstants.Bold, true);
doc.setLogicalStyle(0, bodyStyle);
return codeArea;
}
use of javax.swing.text.StyleContext in project jadx by skylot.
the class FontUtils method loadByStr.
public static Font loadByStr(String fontDesc) {
String[] parts = fontDesc.split("/");
if (parts.length != 3) {
throw new JadxRuntimeException("Unsupported font description format: " + fontDesc);
}
String name = parts[0];
int style = parseFontStyle(parts[1]);
int size = Integer.parseInt(parts[2]);
StyleContext sc = StyleContext.getDefaultStyleContext();
Font font = sc.getFont(name, style, size);
if (font == null) {
throw new JadxRuntimeException("Font not found: " + fontDesc);
}
return font;
}
use of javax.swing.text.StyleContext in project groovy by apache.
the class GroovyFilter method init.
private void init() {
StyleContext styleContext = StyleContext.getDefaultStyleContext();
Style defaultStyle = styleContext.getStyle(StyleContext.DEFAULT_STYLE);
Style comment = styleContext.addStyle(COMMENT, defaultStyle);
StyleConstants.setForeground(comment, COMMENT_COLOR);
StyleConstants.setItalic(comment, true);
Style quotes = styleContext.addStyle(QUOTES, defaultStyle);
StyleConstants.setForeground(quotes, Color.MAGENTA.darker().darker());
Style charQuotes = styleContext.addStyle(SINGLE_QUOTES, defaultStyle);
StyleConstants.setForeground(charQuotes, Color.GREEN.darker().darker());
Style slashyQuotes = styleContext.addStyle(SLASHY_QUOTES, defaultStyle);
StyleConstants.setForeground(slashyQuotes, Color.ORANGE.darker());
Style digit = styleContext.addStyle(DIGIT, defaultStyle);
StyleConstants.setForeground(digit, Color.RED.darker());
Style operation = styleContext.addStyle(OPERATION, defaultStyle);
StyleConstants.setBold(operation, true);
Style ident = styleContext.addStyle(IDENT, defaultStyle);
Style reservedWords = styleContext.addStyle(RESERVED_WORD, defaultStyle);
StyleConstants.setBold(reservedWords, true);
StyleConstants.setForeground(reservedWords, Color.BLUE.darker().darker());
Style leftParens = styleContext.addStyle(IDENT, defaultStyle);
getRootNode().putStyle(SLASH_STAR_COMMENT, comment);
getRootNode().putStyle(SLASH_SLASH_COMMENT, comment);
getRootNode().putStyle(QUOTES, quotes);
getRootNode().putStyle(SINGLE_QUOTES, charQuotes);
getRootNode().putStyle(SLASHY_QUOTES, slashyQuotes);
getRootNode().putStyle(new String[] { HEX_INTEGER_LITERAL, OCTAL_INTEGER_LITERAL, BINARY_INTEGER_LITERAL, DECIMAL_FLOATING_POINT_LITERAL, HEXADECIMAL_FLOATING_POINT_LITERAL, DECIMAL_INTEGER_LITERAL }, digit);
getRootNode().putStyle(OPERATION, operation);
StructuredSyntaxDocumentFilter.LexerNode node = createLexerNode();
node.putStyle(RESERVED_WORDS, reservedWords);
node.putStyle(LEFT_PARENS, leftParens);
getRootNode().putChild(OPERATION, node);
getRootNode().putStyle(IDENT, ident);
node = createLexerNode();
node.putStyle(RESERVED_WORDS, reservedWords);
getRootNode().putChild(IDENT, node);
}
Aggregations