/** * 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; }
/** * Restores all colors and fonts to their default values. * * @param baseFont The base font to use when creating this scheme. If * this is <code>null</code>, then a default monospaced font is * used. */ public void restoreDefaults(Font baseFont) { restoreDefaults(baseFont, true); }
sb.append(c!=null ? (getHexString(c) + ",") : "-,"); c = ss.background; sb.append(c!=null ? (getHexString(c) + ",") : "-,");
/** * 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); } }
int tokenTypeCount) { SyntaxScheme scheme = new SyntaxScheme(true); fg = stringToColor(temp); bg = stringToColor(temp);
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(); } } }); }
for (int i=0; i<syntaxScheme.getStyleCount(); i++) { Style ss = syntaxScheme.getStyle(i); if (ss!=null && ss.font!=null) { FontMetrics fm = getFontMetrics(ss.font);
theme.scheme = new SyntaxScheme(theme.baseFont, false); 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;
SyntaxSchemeLoader(Font baseFont) { scheme = new SyntaxScheme(baseFont); }
private void refreshFontMetrics(Graphics2D g2d) { // It is assumed that any rendering hints are already applied to g2d. defaultFontMetrics = g2d.getFontMetrics(getFont()); syntaxScheme.refreshFontMetrics(g2d); if (!getLineWrap()) { // HORRIBLE HACK! The un-wrapped view needs to refresh its cached // longest line information. SyntaxView sv = (SyntaxView)getUI().getRootView(this).getView(0); sv.calculateLongestLine(); } }
/** * Loads a syntax highlighting color scheme from a string created from * <code>toCommaSeparatedString</code>. This method is useful for saving * and restoring color schemes.<p> * * Consider using the {@link Theme} class for saving and loading RSTA * styles rather than using this API. * * @param string A string generated from {@link #toCommaSeparatedString()}. * @return A color scheme. * @see #toCommaSeparatedString() */ public static SyntaxScheme loadFromString(String string) { return loadFromString(string, DEFAULT_NUM_TOKEN_TYPES); }
scheme.changeBaseFont(old, font); calculateLineHeight();
/** * 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; }
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 = new SyntaxScheme(theme.baseFont, false); 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;
/** * Returns the "default" syntax highlighting color scheme. The colors * used are somewhat standard among syntax highlighting text editors. * * @return The default syntax highlighting color scheme. * @see #restoreDefaultSyntaxScheme() * @see #getSyntaxScheme() * @see #setSyntaxScheme(SyntaxScheme) */ public SyntaxScheme getDefaultSyntaxScheme() { return new SyntaxScheme(getFont()); }
SyntaxScheme scheme = new SyntaxScheme(true); fg = stringToColor(temp); bg = stringToColor(temp);
private void refreshFontMetrics(Graphics2D g2d) { // It is assumed that any rendering hints are already applied to g2d. defaultFontMetrics = g2d.getFontMetrics(getFont()); syntaxScheme.refreshFontMetrics(g2d); if (!getLineWrap()) { // HORRIBLE HACK! The un-wrapped view needs to refresh its cached // longest line information. SyntaxView sv = (SyntaxView)getUI().getRootView(this).getView(0); sv.calculateLongestLine(); } }
/** * Loads a syntax highlighting color scheme from a string created from * <code>toCommaSeparatedString</code>. This method is useful for saving * and restoring color schemes.<p> * * Consider using the {@link Theme} class for saving and loading RSTA * styles rather than using this API. * * @param string A string generated from {@link #toCommaSeparatedString()}. * @return A color scheme. * @see #toCommaSeparatedString() */ public static SyntaxScheme loadFromString(String string) { return loadFromString(string, DEFAULT_NUM_TOKEN_TYPES); }
scheme.changeBaseFont(old, font); calculateLineHeight();