Search in sources :

Example 11 with Highlighter

use of javax.swing.text.Highlighter 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(Color.LIGHT_GRAY);
    try {
        // DOBIN
        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)

Example 12 with Highlighter

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

the class HttpPanelSyntaxHighlightTextArea 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 13 with Highlighter

use of javax.swing.text.Highlighter in project bytecode-viewer by Konloch.

the class FileViewer method highlight.

public void highlight(JTextComponent textComp, String pattern) {
    if (pattern.isEmpty()) {
        textComp.getHighlighter().removeAllHighlights();
        return;
    }
    try {
        Highlighter hilite = textComp.getHighlighter();
        hilite.removeAllHighlights();
        javax.swing.text.Document doc = textComp.getDocument();
        String text = doc.getText(0, doc.getLength());
        int pos = 0;
        if (!check.isSelected()) {
            pattern = pattern.toLowerCase();
            text = text.toLowerCase();
        }
        // Search for pattern
        while ((pos = text.indexOf(pattern, pos)) >= 0) {
            // Create highlighter using private painter and apply around
            // pattern
            hilite.addHighlight(pos, pos + pattern.length(), painter);
            pos += pattern.length();
        }
    } catch (Exception e) {
        new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
    }
}
Also used : IOException(java.io.IOException) DefaultHighlighter(javax.swing.text.DefaultHighlighter) Highlighter(javax.swing.text.Highlighter)

Example 14 with Highlighter

use of javax.swing.text.Highlighter in project bytecode-viewer by Konloch.

the class SystemErrConsole method highlight.

public void highlight(JTextComponent textComp, String pattern) {
    if (pattern.isEmpty()) {
        textComp.getHighlighter().removeAllHighlights();
        return;
    }
    try {
        Highlighter hilite = textComp.getHighlighter();
        hilite.removeAllHighlights();
        javax.swing.text.Document doc = textComp.getDocument();
        String text = doc.getText(0, doc.getLength());
        int pos = 0;
        if (!check.isSelected()) {
            pattern = pattern.toLowerCase();
            text = text.toLowerCase();
        }
        // Search for pattern
        while ((pos = text.indexOf(pattern, pos)) >= 0) {
            // Create highlighter using private painter and apply around
            // pattern
            hilite.addHighlight(pos, pos + pattern.length(), painter);
            pos += pattern.length();
        }
    } catch (Exception e) {
        new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
    }
}
Also used : IOException(java.io.IOException) DefaultHighlighter(javax.swing.text.DefaultHighlighter) Highlighter(javax.swing.text.Highlighter)

Aggregations

DefaultHighlighter (javax.swing.text.DefaultHighlighter)14 Highlighter (javax.swing.text.Highlighter)14 BadLocationException (javax.swing.text.BadLocationException)7 HighlightPainter (javax.swing.text.Highlighter.HighlightPainter)5 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 IOException (java.io.IOException)2 Matcher (java.util.regex.Matcher)2 JButton (javax.swing.JButton)2 Highlight (javax.swing.text.Highlighter.Highlight)2 LayerPainter (javax.swing.text.LayeredHighlighter.LayerPainter)1