Search in sources :

Example 6 with HighlightPainter

use of javax.swing.text.Highlighter.HighlightPainter in project zaproxy by zaproxy.

the class HttpPanelTextArea method highlightEntryParser.

// Parse the TextArea data and search the HighlightEntry strings
// Highlight all found strings
private void highlightEntryParser(HighlightSearchEntry entry) {
    String text;
    int lastPos = 0;
    text = this.getText();
    Highlighter hilite = this.getHighlighter();
    HighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(entry.getColor());
    while ((lastPos = text.indexOf(entry.getToken(), lastPos)) > -1) {
        try {
            hilite.addHighlight(lastPos, lastPos + entry.getToken().length(), painter);
            lastPos += entry.getToken().length();
        } catch (BadLocationException e) {
            log.warn("Could not highlight entry", e);
        }
    }
}
Also used : HighlightPainter(javax.swing.text.Highlighter.HighlightPainter) BadLocationException(javax.swing.text.BadLocationException) DefaultHighlighter(javax.swing.text.DefaultHighlighter) Highlighter(javax.swing.text.Highlighter)

Example 7 with HighlightPainter

use of javax.swing.text.Highlighter.HighlightPainter in project zaproxy by zaproxy.

the class HttpPanelTextArea method highlight.

protected void highlight(int start, int end) {
    Highlighter hilite = this.getHighlighter();
    HighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(DisplayUtils.getHighlightColor());
    try {
        removeAllHighlights();
        hilite.addHighlight(start, end, painter);
        this.setCaretPosition(start);
    } catch (BadLocationException e) {
        log.error(e.getMessage(), e);
    }
}
Also used : HighlightPainter(javax.swing.text.Highlighter.HighlightPainter) BadLocationException(javax.swing.text.BadLocationException) DefaultHighlighter(javax.swing.text.DefaultHighlighter) Highlighter(javax.swing.text.Highlighter)

Aggregations

HighlightPainter (javax.swing.text.Highlighter.HighlightPainter)7 BadLocationException (javax.swing.text.BadLocationException)6 Highlighter (javax.swing.text.Highlighter)6 DefaultHighlighter (javax.swing.text.DefaultHighlighter)5 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 JButton (javax.swing.JButton)1 AttributeSet (javax.swing.text.AttributeSet)1 DefaultHighlightPainter (javax.swing.text.DefaultHighlighter.DefaultHighlightPainter)1 Highlight (javax.swing.text.Highlighter.Highlight)1 ProtectedPart (org.omegat.core.data.ProtectedPart)1