Example usage for javax.swing.text StyleContext addStyle

List of usage examples for javax.swing.text StyleContext addStyle

Introduction

In this page you can find the example usage for javax.swing.text StyleContext addStyle.

Prototype

public Style addStyle(String nm, Style parent) 

Source Link

Document

Adds a new style into the style hierarchy.

Usage

From source file:pl.otros.logview.gui.message.SearchResultColorizer.java

@Override
public Collection<MessageFragmentStyle> colorize(String textToColorize) throws BadLocationException {
    Collection<MessageFragmentStyle> list = new ArrayList<MessageFragmentStyle>();
    if (StringUtils.isEmpty(searchString)) {
        return list;
    }//from www  . j  a  v a2  s  . c om
    StyleContext sc = new StyleContext();
    Style searchStyle = sc.addStyle("searchResult", sc.getStyle(StyleContext.DEFAULT_STYLE));
    StyleConstants.setBackground(searchStyle, color);
    if (searchMode.equals(SearchMode.STRING_CONTAINS)) {
        list.addAll(colorizeString(textToColorize, searchStyle, searchString));
    } else if (searchMode.equals(SearchMode.REGEX)) {
        list.addAll(MessageColorizerUtils.colorizeRegex(searchStyle, textToColorize,
                Pattern.compile(searchString, Pattern.CASE_INSENSITIVE), 0));
    }
    for (MessageFragmentStyle style : list) {
        style.setSearchResult(true);
    }
    return list;
}

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

void changeSeeker(Seeker seeker) {
    view.setTitle(seeker.getTitle());//w  ww . j av a2s. co  m
    //        jTextPane.setText("");  TODO 
    model.emptyList();
    model.setSeeker(seeker);
    request();

    List<String> colors = seeker.getColors();
    styles = new Style[colors.size()];
    StyleContext sc = new StyleContext();
    for (int i = 0; i < colors.size(); i++) {
        styles[i] = sc.addStyle((String) colors.get(i), sc.getStyle(StyleContext.DEFAULT_STYLE));
        StyleConstants.setForeground(styles[i], ColorUtils.getColorByName(colors.get(i)));
        StyleConstants.setBold(styles[i], true);
    }
    colorInputText();

    filter = seeker.getFilter();
}

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  . ja v a2 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);
}