List of usage examples for javax.swing.text StyleContext getStyle
public Style getStyle(String nm)
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 ww w . j a v a 2 s .co m 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());/*from w ww.ja va 2 s . c om*/ // 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); }//from w ww. j a v a 2 s . com //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); }