Example usage for javax.swing.text StyleConstants Foreground

List of usage examples for javax.swing.text StyleConstants Foreground

Introduction

In this page you can find the example usage for javax.swing.text StyleConstants Foreground.

Prototype

Object Foreground

To view the source code for javax.swing.text StyleConstants Foreground.

Click Source Link

Document

Name of the foreground color attribute.

Usage

From source file:net.sf.jasperreports.engine.util.JEditorPaneHtmlMarkupProcessor.java

@Override
protected Map<Attribute, Object> getAttributes(AttributeSet attrSet) {
    Map<Attribute, Object> attrMap = new HashMap<Attribute, Object>();
    if (attrSet.isDefined(StyleConstants.FontFamily)) {
        attrMap.put(TextAttribute.FAMILY, StyleConstants.getFontFamily(attrSet));
    }/*from   w w  w . j  a  va 2s .  c o  m*/

    if (attrSet.isDefined(StyleConstants.Bold)) {
        attrMap.put(TextAttribute.WEIGHT,
                StyleConstants.isBold(attrSet) ? TextAttribute.WEIGHT_BOLD : TextAttribute.WEIGHT_REGULAR);
    }

    if (attrSet.isDefined(StyleConstants.Italic)) {
        attrMap.put(TextAttribute.POSTURE, StyleConstants.isItalic(attrSet) ? TextAttribute.POSTURE_OBLIQUE
                : TextAttribute.POSTURE_REGULAR);
    }

    if (attrSet.isDefined(StyleConstants.Underline)) {
        attrMap.put(TextAttribute.UNDERLINE,
                StyleConstants.isUnderline(attrSet) ? TextAttribute.UNDERLINE_ON : null);
    }

    if (attrSet.isDefined(StyleConstants.StrikeThrough)) {
        attrMap.put(TextAttribute.STRIKETHROUGH,
                StyleConstants.isStrikeThrough(attrSet) ? TextAttribute.STRIKETHROUGH_ON : null);
    }

    if (attrSet.isDefined(StyleConstants.FontSize)) {
        attrMap.put(TextAttribute.SIZE, StyleConstants.getFontSize(attrSet));
    }

    if (attrSet.isDefined(StyleConstants.Foreground)) {
        attrMap.put(TextAttribute.FOREGROUND, StyleConstants.getForeground(attrSet));
    }

    if (attrSet.isDefined(StyleConstants.Background)) {
        attrMap.put(TextAttribute.BACKGROUND, StyleConstants.getBackground(attrSet));
    }

    //FIXME: why StyleConstants.isSuperscript(attrSet) does return false
    if (attrSet.isDefined(StyleConstants.Superscript) && !StyleConstants.isSubscript(attrSet)) {
        attrMap.put(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER);
    }

    if (attrSet.isDefined(StyleConstants.Subscript) && StyleConstants.isSubscript(attrSet)) {
        attrMap.put(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUB);
    }

    return attrMap;
}

From source file:com.NewJFrame.java

private void appendToPane(JTextPane tp, String msg, Color c) {
    StyleContext sc = StyleContext.getDefaultStyleContext();
    AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);

    //        aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Lucida Console");
    //        aset = sc.addAttribute(aset, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED);
    int len = tp.getDocument().getLength();
    tp.setCaretPosition(len);//from   w w w . j ava2s .c om
    tp.setCharacterAttributes(aset, false);
    tp.replaceSelection(msg);

}

From source file:tk.tomby.tedit.editorkits.HighlightPlainContext.java

/**
 * Creates a new HighlightContext object.
 *
 * @param syntax DOCUMENT ME!/*  w w w . j  a  v a2  s  .c  o m*/
 */
public HighlightPlainContext(Syntax syntax) {
    super();

    tokenizer = new Tokenizer(syntax);

    Style style = addStyle(Syntax.UNKNOWN_NAME, getStyle(DEFAULT_STYLE));

    int red = PreferenceManager.getInt("general.editor.foreground.red", 0);
    int green = PreferenceManager.getInt("general.editor.foreground.green", 0);
    int blue = PreferenceManager.getInt("general.editor.foreground.blue", 0);
    style.addAttribute(StyleConstants.Foreground, new Color(red, green, blue));

    String font = PreferenceManager.getString("general.editor.font", "Monospaced");
    int size = PreferenceManager.getInt("general.editor.fontSize", 12);
    style.addAttribute(StyleConstants.FontFamily, new Font(font, Font.PLAIN, size));

    createStyle(Syntax.KEYWORD1_NAME, "highlight.keyword1");
    createStyle(Syntax.KEYWORD2_NAME, "highlight.keyword2");
    createStyle(Syntax.KEYWORD3_NAME, "highlight.keyword3");
    createStyle(Syntax.KEYWORD4_NAME, "highlight.keyword4");

    createStyle(Syntax.COMMENT1_NAME, "highlight.comment1");
    createStyle(Syntax.COMMENT2_NAME, "highlight.comment2");
    createStyle(Syntax.COMMENT3_NAME, "highlight.comment3");
    createStyle(Syntax.COMMENT4_NAME, "highlight.comment3");

    createStyle(Syntax.LITERAL1_NAME, "highlight.literal1");
    createStyle(Syntax.LITERAL2_NAME, "highlight.literal2");
    createStyle(Syntax.LITERAL3_NAME, "highlight.literal3");
    createStyle(Syntax.LITERAL4_NAME, "highlight.literal4");

    createStyle(Syntax.IDENTIFIER1_NAME, "highlight.identifier1");
    createStyle(Syntax.IDENTIFIER2_NAME, "highlight.identifier2");
    createStyle(Syntax.IDENTIFIER3_NAME, "highlight.identifier3");
    createStyle(Syntax.IDENTIFIER4_NAME, "highlight.identifier4");

    createStyle(Syntax.OPERATOR_NAME, "highlight.operator");
    createStyle(Syntax.SEPARATOR_NAME, "highlight.separator");
    createStyle(Syntax.LABEL_NAME, "highlight.label");
    createStyle(Syntax.MARKUP_NAME, "highlight.markup");
    createStyle(Syntax.DIGIT_NAME, "highlight.digit");
    createStyle(Syntax.SCRIPTLET_NAME, "highlight.scriptlet");

    MessageManager.addMessageListener(MessageManager.PREFERENCE_GROUP_NAME, this);
}

From source file:tk.tomby.tedit.editorkits.HighlightPlainContext.java

/**
 * DOCUMENT ME!//w  ww. j  a  v  a2  s  .  c o  m
 *
 * @param message DOCUMENT ME!
 */
public void receiveMessage(PreferenceMessage message) {
    if (message.getKey().startsWith("highlight")) {
        int index = message.getKey().indexOf('.');
        String styleName = message.getKey().substring(index + 1);

        log.debug("styleName=" + styleName);

        HighlightModel model = (HighlightModel) message.getNewValue();

        Style style = getStyle(styleName);
        style.addAttribute(StyleConstants.Foreground, model.getColor());
        style.addAttribute(StyleConstants.FontFamily, model.getFont());
    }
}

From source file:tk.tomby.tedit.editorkits.HighlightPlainContext.java

/**
 * DOCUMENT ME!//from w  w  w.j  av a 2  s  .  c o  m
 *
 * @param name DOCUMENT ME!
 * @param key DOCUMENT ME!
 */
private void createStyle(String name, String key) {
    HighlightModel model = new HighlightModel(key);

    Style style = addStyle(name, getStyle(DEFAULT_STYLE));
    style.addAttribute(StyleConstants.Foreground, model.getColor());
    style.addAttribute(StyleConstants.FontFamily, model.getFont());
}