Example usage for javax.swing.text Highlighter removeHighlight

List of usage examples for javax.swing.text Highlighter removeHighlight

Introduction

In this page you can find the example usage for javax.swing.text Highlighter removeHighlight.

Prototype

public void removeHighlight(Object tag);

Source Link

Document

Removes a highlight from the view.

Usage

From source file:org.zaproxy.zap.extension.ascan.CustomScanDialog.java

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//from   w  ww  .jav  a 2s .  c om
            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;
}

From source file:org.zaproxy.zap.extension.customFire.CustomFireDialog.java

private JButton getRemoveCustomButton() {
    if (removeCustomButton == null) {
        removeCustomButton = new JButton(Constant.messages.getString("customFire.custom.button.pt.rem"));
        removeCustomButton.setEnabled(false);

        removeCustomButton.addActionListener(new java.awt.event.ActionListener() {
            @Override//from ww w  . j a  va 2 s.c  om
            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)) {
                                try {
                                    int i = list.indexOf(
                                            "[" + userDefStart + "," + userDefEnd + "]:" + getRequestField()
                                                    .getText(userDefStart, userDefEnd - userDefStart));
                                    list.remove(i);
                                } catch (BadLocationException e1) {
                                    e1.printStackTrace();
                                }
                                hltr.removeHighlight(hl);
                                injectionPointModel.removeElement(hl);
                            }
                        }
                    }

                    // Unselect the text
                    getRequestField().setSelectionStart(userDefEnd);
                    getRequestField().setSelectionEnd(userDefEnd);
                    getRequestField().getCaret().setVisible(true);
                }
            }
        });
    }

    return removeCustomButton;
}