Search in sources :

Example 51 with Highlighter

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

the class CustomScanDialog method getRemoveCustomButton.

private JButton getRemoveCustomButton() {
    if (removeCustomButton == null) {
        removeCustomButton = new JButton(Constant.messages.getString("ascan.custom.button.pt.rem"));
        removeCustomButton.setEnabled(false);
        removeCustomButton.addActionListener(new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent e) {
                // Remove any selected injection points
                int userDefStart = getRequestField().getSelectionStart();
                if (userDefStart >= 0) {
                    int userDefEnd = getRequestField().getSelectionEnd();
                    Highlighter hltr = getRequestField().getHighlighter();
                    Highlight[] hls = hltr.getHighlights();
                    if (hls != null && hls.length > 0) {
                        for (Highlight hl : hls) {
                            if (selectionIncludesHighlight(userDefStart, userDefEnd, hl)) {
                                hltr.removeHighlight(hl);
                                injectionPointModel.removeElement(hl);
                            }
                        }
                    }
                    // Unselect the text
                    getRequestField().setSelectionStart(userDefEnd);
                    getRequestField().setSelectionEnd(userDefEnd);
                    getRequestField().getCaret().setVisible(true);
                }
            }
        });
    }
    return removeCustomButton;
}
Also used : ActionListener(java.awt.event.ActionListener) Highlight(javax.swing.text.Highlighter.Highlight) JButton(javax.swing.JButton) ActionEvent(java.awt.event.ActionEvent) DefaultHighlighter(javax.swing.text.DefaultHighlighter) Highlighter(javax.swing.text.Highlighter)

Example 52 with Highlighter

use of javax.swing.text.Highlighter in project iris by mnit-rtmc.

the class WMsgMultiPanel method highlightErrors.

/**
 * Highlight any error-producing tokens
 */
public void highlightErrors(WEditorErrorManager errMan) {
    if (errMan.hasErrors()) {
        Highlighter h = textBox.getHighlighter();
        HighlightPainter hp = new DefaultHighlighter.DefaultHighlightPainter(Color.RED);
        String txt = textBox.getText();
        Iterator<WEditorError> it = errMan.iterator();
        while (it.hasNext()) {
            WEditorError e = it.next();
            if (e.hasToken()) {
                String ts = e.getToken().toString();
                // if this error has a token, highlight it
                int a = txt.indexOf(ts);
                if (a < 0)
                    continue;
                int b = a + ts.length();
                String s = txt.substring(a, b);
                if (s == ts) {
                    try {
                        h.addHighlight(a, b, hp);
                    } catch (BadLocationException ex) {
                        // just ignore this
                        ex.printStackTrace();
                    }
                }
            }
        }
    }
}
Also used : HighlightPainter(javax.swing.text.Highlighter.HighlightPainter) BadLocationException(javax.swing.text.BadLocationException) DefaultHighlighter(javax.swing.text.DefaultHighlighter) Highlighter(javax.swing.text.Highlighter) WEditorError(us.mn.state.dot.tms.utils.wysiwyg.WEditorError)

Example 53 with Highlighter

use of javax.swing.text.Highlighter in project phon by phon-ca.

the class RecordDataEditorView method addSelectionHighlights.

private void addSelectionHighlights(JTextComponent textComp, int recordIndex, String tierName, int groupIndex) {
    final List<SessionEditorSelection> selections = getEditor().getSelectionModel().getSelectionsForGroup(recordIndex, tierName, groupIndex);
    final Highlighter hl = new GroupFieldHighlighter();
    final Highlighter origHighlighter = textComp.getHighlighter();
    textComp.setHighlighter(hl);
    if (origHighlighter != null && origHighlighter.getHighlights().length > 0) {
        for (Highlight hilight : origHighlighter.getHighlights()) try {
            hl.addHighlight(hilight.getStartOffset(), hilight.getEndOffset(), hilight.getPainter());
        } catch (BadLocationException e) {
            LOGGER.info(e.getLocalizedMessage(), e);
        }
    }
    for (SessionEditorSelection selection : selections) {
        final Range r = selection.getGroupRange();
        try {
            HighlightPainter painter = selection.getExtension(HighlightPainter.class);
            if (painter == null)
                painter = new DefaultHighlighter.DefaultHighlightPainter(PhonGuiConstants.PHON_SELECTED);
            hl.addHighlight(r.getFirst(), r.getLast() + 1, painter);
        } catch (BadLocationException e) {
            LOGGER.info(e.getLocalizedMessage(), e);
        }
    }
}
Also used : Highlighter(javax.swing.text.Highlighter)

Example 54 with Highlighter

use of javax.swing.text.Highlighter in project Weasis by nroduit.

the class TagSearchDocumentPanel method showCurrentSearch.

public void showCurrentSearch(String pattern) {
    if (!searchPositions.isEmpty() && StringUtil.hasText(pattern)) {
        removeHighlights(textComponent);
        try {
            if (currentSearchIndex < 0 || currentSearchIndex >= searchPositions.size()) {
                currentSearchIndex = 0;
            }
            int curPos = searchPositions.get(currentSearchIndex);
            Highlighter highlighter = textComponent.getHighlighter();
            for (Integer pos : searchPositions) {
                if (pos == curPos) {
                    highlighter.addHighlight(pos, pos + pattern.length(), searchHighlightPainter);
                } else {
                    highlighter.addHighlight(pos, pos + pattern.length(), searchResultHighlightPainter);
                }
            }
            textComponent.scrollRectToVisible(textComponent.modelToView(curPos));
        } catch (BadLocationException e) {
            LOGGER.error("Highlight result of search", e);
        }
    }
}
Also used : BadLocationException(javax.swing.text.BadLocationException) Highlighter(javax.swing.text.Highlighter)

Example 55 with Highlighter

use of javax.swing.text.Highlighter in project stringtemplate4 by antlr.

the class STViz method highlight.

protected void highlight(JTextComponent comp, int i, int j, boolean scroll) {
    Highlighter highlighter = comp.getHighlighter();
    highlighter.removeAllHighlights();
    try {
        i = toComponentPosition(comp, i);
        j = toComponentPosition(comp, j);
        highlighter.addHighlight(i, j + 1, DefaultHighlighter.DefaultPainter);
        if (scroll) {
            if (comp.getCaretPosition() < i || comp.getCaretPosition() > j) {
                comp.moveCaretPosition(i);
                comp.scrollRectToVisible(comp.modelToView(i));
            }
        }
    } catch (BadLocationException ble) {
        errMgr.internalError(tmodel.root.event.scope.st, "bad highlight location", ble);
    }
}
Also used : BadLocationException(javax.swing.text.BadLocationException) DefaultHighlighter(javax.swing.text.DefaultHighlighter) Highlighter(javax.swing.text.Highlighter)

Aggregations

Highlighter (javax.swing.text.Highlighter)68 BadLocationException (javax.swing.text.BadLocationException)40 DefaultHighlighter (javax.swing.text.DefaultHighlighter)37 Matcher (java.util.regex.Matcher)12 HighlightPainter (javax.swing.text.Highlighter.HighlightPainter)10 JTextArea (javax.swing.JTextArea)9 Document (javax.swing.text.Document)9 Point (java.awt.Point)6 File (java.io.File)6 PatternSyntaxException (java.util.regex.PatternSyntaxException)5 DefaultHighlightPainter (javax.swing.text.DefaultHighlighter.DefaultHighlightPainter)5 Editor (omega.ui.component.Editor)5 StringTokenizer (java.util.StringTokenizer)4 JTextComponent (javax.swing.text.JTextComponent)4 Highlight (omega.instant.support.Highlight)4 IOException (java.io.IOException)3 ImageIcon (javax.swing.ImageIcon)3 AbstractErrorHighlighter (omega.instant.support.AbstractErrorHighlighter)3 JavaSyntaxParserGutterIconInfo (omega.instant.support.java.parser.JavaSyntaxParserGutterIconInfo)3 SquiggleUnderlineHighlightPainter (org.fife.ui.rsyntaxtextarea.SquiggleUnderlineHighlightPainter)3