Search in sources :

Example 1 with LayerPainter

use of javax.swing.text.LayeredHighlighter.LayerPainter in project jabref by JabRef.

the class JEditorPaneWithHighlighting method highlightPattern.

public void highlightPattern(Optional<Pattern> highlightPattern) {
    Highlighter highlighter = getHighlighter();
    highlighter.removeAllHighlights();
    if ((highlightPattern == null) || !highlightPattern.isPresent()) {
        return;
    }
    String text = getDocumentText();
    Matcher matcher = highlightPattern.get().matcher(text);
    LayerPainter painter = DefaultHighlighter.DefaultPainter;
    while (matcher.find()) {
        try {
            highlighter.addHighlight(matcher.start(), matcher.end(), painter);
        } catch (BadLocationException ble) {
            // should not occur if matcher works right
            LOGGER.warn("Highlighting not possible, bad location", ble);
        }
    }
}
Also used : Matcher(java.util.regex.Matcher) BadLocationException(javax.swing.text.BadLocationException) DefaultHighlighter(javax.swing.text.DefaultHighlighter) Highlighter(javax.swing.text.Highlighter) LayerPainter(javax.swing.text.LayeredHighlighter.LayerPainter)

Aggregations

Matcher (java.util.regex.Matcher)1 BadLocationException (javax.swing.text.BadLocationException)1 DefaultHighlighter (javax.swing.text.DefaultHighlighter)1 Highlighter (javax.swing.text.Highlighter)1 LayerPainter (javax.swing.text.LayeredHighlighter.LayerPainter)1