public LineNumbers(CodeArea component) { this.codeArea = component; setFont(component.getFont()); SyntaxScheme syntaxScheme = codeArea.getSyntaxScheme(); numberColor = syntaxScheme.getStyle(Token.LITERAL_NUMBER_DECIMAL_INT).foreground; currentColor = syntaxScheme.getStyle(Token.LITERAL_STRING_DOUBLE_QUOTE).foreground; border = new MatteBorder(0, 0, 0, 1, syntaxScheme.getStyle(Token.COMMENT_MULTILINE).foreground); setBackground(codeArea.getBackground()); setForeground(numberColor); setBorderGap(5); setPreferredWidth(); component.addCaretListener(this); addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { useSourceLines = !useSourceLines; repaint(); } } }); }
/** * Set the font for all token types. * * @param textArea The text area to modify. * @param font The font to use. */ public static void setFont(RSyntaxTextArea textArea, Font font) { if (font != null) { SyntaxScheme ss = textArea.getSyntaxScheme(); ss = (SyntaxScheme) ss.clone(); for (int i = 0; i < ss.getStyleCount(); i++) { if (ss.getStyle(i) != null) { ss.getStyle(i).font = font; } } textArea.setSyntaxScheme(ss); textArea.setFont(font); } }
/** * Returns the font metrics for tokens of the specified type. * * @param type The type of token. * @return The font metrics to use for that token type. * @see #getFontForTokenType(int) */ public FontMetrics getFontMetricsForTokenType(int type) { FontMetrics fm = syntaxScheme.getStyle(type).fontMetrics; return fm!=null ? fm : defaultFontMetrics; }
Style ss = syntaxScheme.getStyle(i); if (ss!=null && ss.font!=null) { FontMetrics fm = getFontMetrics(ss.font);
/** * Changes the styles used in the editor programmatically. */ private void changeStyleProgrammatically() { // Set the font for all token types. setFont(textArea, new Font("Comic Sans MS", Font.PLAIN, 16)); // Change a few things here and there. SyntaxScheme scheme = textArea.getSyntaxScheme(); scheme.getStyle(Token.RESERVED_WORD).background = Color.pink; scheme.getStyle(Token.DATA_TYPE).foreground = Color.blue; scheme.getStyle(Token.LITERAL_STRING_DOUBLE_QUOTE).underline = true; scheme.getStyle(Token.COMMENT_EOL).font = new Font("Georgia", Font.ITALIC, 12); textArea.revalidate(); }
/** * Creates and returns a syntax scheme where all styles have the same * font and foreground color. * * @param font The font for the styles. * @param fg The foreground color for the styles. * @return The syntax scheme. */ private SyntaxScheme createSyntaxScheme(Font font, Color fg) { SyntaxScheme scheme = new SyntaxScheme(true); for (int i=0; i<scheme.getStyleCount(); i++) { Style style = scheme.getStyle(i); if (style != null) { style.background = style.foreground = fg; style.font = font; if (i == 5) { style.underline = true; } else if (i == 6) { style.font = font.deriveFont(Font.BOLD, 24f); } else if (i == 7) { style.font = font.deriveFont(Font.ITALIC, 25f); } } } return scheme; }
/** * Returns the font for tokens of the specified type. * * @param type The type of token. * @return The font to use for that token type. * @see #getFontMetricsForTokenType(int) */ public Font getFontForTokenType(int type) { Font f = syntaxScheme.getStyle(type).font; return f!=null ? f : getFont(); }
int count = scheme.getStyleCount(); for (int i=0; i<count; i++) { Style ss = scheme.getStyle(i); if (ss!=null) { Font font = ss.font;
/** * Returns the foreground color to use when painting a token. This does * not take into account whether the token is a hyperlink. * * @param type The token type. * @return The foreground color to use for that token. This * value is never <code>null</code>. * @see #getForegroundForToken(Token) */ public Color getForegroundForTokenType(int type) { Color fg = syntaxScheme.getStyle(type).foreground; return fg!=null ? fg : getForeground(); }
int count = scheme.getStyleCount(); for (int i=0; i<count; i++) { Style ss = scheme.getStyle(i); if (ss!=null) { Font font = ss.font;
theme.scheme.getStyle(index).foreground = fg; theme.scheme.getStyle(index).background = bg; theme.scheme.getStyle(index).font = font; style |= Font.ITALIC; Font orig = theme.scheme.getStyle(index).font; theme.scheme.getStyle(index).font = orig.deriveFont(style); if (ulineStr!=null) { boolean uline = Boolean.parseBoolean(ulineStr); theme.scheme.getStyle(index).underline = uline;
int value = field.getInt(null); if (value != TokenTypes.DEFAULT_NUM_TOKEN_TYPES) { Style style = scheme.getStyle(value); if (style != null) { Element elem2 = doc.createElement("style");
Style scheme = colorScheme.getStyle(getType());
/** * Returns the background color for a token. * * @param token The token. * @return The background color to use for that token. If this value is * is <code>null</code> then this token has no special background * color. * @see #getForegroundForToken(Token) */ public Color getBackgroundForToken(Token token) { Color c = null; if (getHighlightSecondaryLanguages()) { // 1-indexed, since 0 == main language. int languageIndex = token.getLanguageIndex() - 1; if (languageIndex>=0 && languageIndex<secondaryLanguageBackgrounds.length) { c = secondaryLanguageBackgrounds[languageIndex]; } } if (c==null) { c = syntaxScheme.getStyle(token.getType()).background; } // Don't default to this.getBackground(), as Tokens simply don't // paint a background if they get a null Color. return c; }
/** * Returns whether the specified token should be underlined. * A token is underlined if its syntax style includes underlining, * or if it is a hyperlink and hyperlinks are enabled. * * @param t The token. * @return Whether the specified token should be underlined. */ public boolean getUnderlineForToken(Token t) { return (getHyperlinksEnabled() && (t.isHyperlink() || (linkGeneratorResult!=null && linkGeneratorResult.getSourceOffset()==t.getOffset()))) || syntaxScheme.getStyle(t.getType()).underline; }
/** * Returns the font metrics for tokens of the specified type. * * @param type The type of token. * @return The font metrics to use for that token type. * @see #getFontForTokenType(int) */ public FontMetrics getFontMetricsForTokenType(int type) { FontMetrics fm = syntaxScheme.getStyle(type).fontMetrics; return fm!=null ? fm : defaultFontMetrics; }
SyntaxScheme scheme = textArea.getSyntaxScheme(); scheme.getStyle(Token.ERROR_NUMBER_FORMAT).foreground = Color.BLACK; textArea.repaint(); textArea.revalidate();
/** * Returns the font for tokens of the specified type. * * @param type The type of token. * @return The font to use for that token type. * @see #getFontMetricsForTokenType(int) */ public Font getFontForTokenType(int type) { Font f = syntaxScheme.getStyle(type).font; return f!=null ? f : getFont(); }
/** * Returns the foreground color to use when painting a token. This does * not take into account whether the token is a hyperlink. * * @param type The token type. * @return The foreground color to use for that token. This * value is never <code>null</code>. * @see #getForegroundForToken(Token) */ public Color getForegroundForTokenType(int type) { Color fg = syntaxScheme.getStyle(type).foreground; return fg!=null ? fg : getForeground(); }
/** * Returns whether the specified token should be underlined. * A token is underlined if its syntax style includes underlining, * or if it is a hyperlink and hyperlinks are enabled. * * @param t The token. * @return Whether the specified token should be underlined. */ public boolean getUnderlineForToken(Token t) { return (getHyperlinksEnabled() && (t.isHyperlink() || (linkGeneratorResult!=null && linkGeneratorResult.getSourceOffset()==t.getOffset()))) || syntaxScheme.getStyle(t.getType()).underline; }