Example usage for javax.swing.text StyleConstants setForeground

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

Introduction

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

Prototype

public static void setForeground(MutableAttributeSet a, Color fg) 

Source Link

Document

Sets the foreground color.

Usage

From source file:simplealbum.mvc.autocomplete.JTextPaneX.java

public JTextPaneX() {

    //Create the style array to show the colors 
    //        List<Object> colorList = CONFIGURATION.getList("ColorWord");
    List<Object> colorList = null;
    styles = new Style[colorList.size()];
    StyleContext sc = new StyleContext();
    for (int i = 0; i < colorList.size(); i++) {
        styles[i] = sc.addStyle((String) colorList.get(i), sc.getStyle(StyleContext.DEFAULT_STYLE));
        StyleConstants.setForeground(styles[i], ColorUtils.getColorByName((String) colorList.get(i)));
        StyleConstants.setBold(styles[i], true);
    }/* w w w  .j av  a 2  s . c o  m*/

    //Get the document for adding a document listener
    dsd = (DefaultStyledDocument) getDocument();
    dsd.addDocumentListener(new DocumentListenerTextPane());

    //...and setting a document filter
    documentFilter = new MyDocumentFilter();
    dsd.setDocumentFilter(documentFilter);
}

From source file:uk.ac.kcl.texthunter.core.AnnotationEditor.java

private void updateProjectSummary() {
    try {//  w  ww .  ja v a2  s. co m
        projectXML.updateProjectSummary(con, targetTableName);
    } catch (java.sql.SQLException ex) {
        updateProjectStatus("Annotation table not ready");
    }
    StyledDocument doc;
    doc = projectSummaryTextPane.getStyledDocument();
    SimpleAttributeSet newString = new SimpleAttributeSet();
    StyleConstants.setForeground(newString, Color.BLACK);
    StyleConstants.setBold(newString, true);

    StringBuilder newText = new StringBuilder("\n");
    DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
    Date date = new Date();

    newText.append("------ results updated on ").append(dateFormat.format(date)).append(" ------\n\n");
    newText.append("current project annotations:\n");
    newText = newText.append("Gold Standard Positive Annotations = ").append(projectXML.getGsPos())
            .append("\n");
    newText = newText.append("Gold Standard Negative Annotations = ").append(projectXML.getGsneg())
            .append("\n");
    newText = newText.append("Gold Standard Unknown Annotations = ").append(projectXML.getGsunk()).append("\n");
    newText = newText.append("Gold Standard Form Annotations = ").append(projectXML.getGsform()).append("\n");
    newText = newText.append("Seed positive Annotations = ").append(projectXML.getSeedpos()).append("\n");
    newText = newText.append("Seed Negative Annotations = ").append(projectXML.getSeedneg()).append("\n");
    newText = newText.append("Seed Unknown Annotations = ").append(projectXML.getSeedunk()).append("\n");
    newText = newText.append("Seed Form Annotations = ").append(projectXML.getSeedform()).append("\n");
    newText = newText.append("AL Positive Annotations = ").append(projectXML.getAlpos()).append("\n");
    newText = newText.append("AL Negative Annotations = ").append(projectXML.getAlneg()).append("\n");
    newText = newText.append("AL Form Annotations = ").append(projectXML.getAlform()).append("\n");
    newText = newText.append("AL Unknown Annotations = ").append(projectXML.getAlunk()).append("\n\n");

    newText = newText.append("Last Pipeline run results:\n");
    newText = newText.append("P = ").append(projectXML.getPrecision()).append("\n");
    newText = newText.append("R = ").append(projectXML.getRecall()).append("\n");
    newText = newText.append("F1 = ").append(projectXML.getF1()).append("\n");

    try {
        doc.insertString(doc.getLength(), "\n" + newText, newString);
    } catch (Exception e) {
        System.out.println(e);
    }
}

From source file:uk.ac.kcl.texthunter.core.AnnotationEditor.java

private void updateInfoTextPane(String newText) {
    StyledDocument doc;//w  w  w . j  a  v a  2s .c  o m
    doc = infoTextPane.getStyledDocument();

    //  Define a keyword attribute

    SimpleAttributeSet newString = new SimpleAttributeSet();
    StyleConstants.setForeground(newString, Color.RED);
    StyleConstants.setBold(newString, true);

    SimpleAttributeSet oldString = new SimpleAttributeSet();
    StyleConstants.setForeground(oldString, Color.BLACK);
    StyleConstants.setBold(oldString, false);

    //  Add some text

    try {
        doc.setCharacterAttributes(0, doc.getLength(), oldString, true);
        doc.insertString(doc.getLength(), "\n" + newText, newString);
    } catch (Exception e) {
        System.out.println(e);
    }
}