Search in sources :

Example 1 with Highlight

use of javax.swing.text.Highlighter.Highlight in project CoreNLP by stanfordnlp.

the class HighlightUtils method isInHighlight.

/**
   * Returns true if the given mouse event occurred within a highlight h on label.
   */
public static boolean isInHighlight(MouseEvent e, JTextField label, Highlighter h) {
    Highlight[] hls = h.getHighlights();
    if (hls == null || hls.length == 0)
        return false;
    Highlight hl = hls[0];
    FontMetrics fm = label.getFontMetrics(label.getFont());
    int offset = getCharOffset(fm, label.getText(), e.getX());
    return hl.getStartOffset() <= offset && offset < hl.getEndOffset();
}
Also used : Highlight(javax.swing.text.Highlighter.Highlight) FontMetrics(java.awt.FontMetrics)

Example 2 with Highlight

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

the class CustomScanDialog method getAddCustomButton.

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

            @Override
            public void actionPerformed(java.awt.event.ActionEvent e) {
                // Add the selected injection point
                int userDefStart = getRequestField().getSelectionStart();
                if (userDefStart >= 0) {
                    int userDefEnd = getRequestField().getSelectionEnd();
                    Highlighter hl = getRequestField().getHighlighter();
                    HighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(Color.RED);
                    try {
                        Highlight hlt = (Highlight) hl.addHighlight(userDefStart, userDefEnd, painter);
                        injectionPointModel.addElement(hlt);
                        // Unselect the text
                        getRequestField().setSelectionStart(userDefEnd);
                        getRequestField().setSelectionEnd(userDefEnd);
                        getRequestField().getCaret().setVisible(true);
                    } catch (BadLocationException e1) {
                        logger.error(e1.getMessage(), e1);
                    }
                }
            }
        });
    }
    return addCustomButton;
}
Also used : ActionListener(java.awt.event.ActionListener) Highlight(javax.swing.text.Highlighter.Highlight) HighlightPainter(javax.swing.text.Highlighter.HighlightPainter) JButton(javax.swing.JButton) DefaultHighlighter(javax.swing.text.DefaultHighlighter) ActionEvent(java.awt.event.ActionEvent) BadLocationException(javax.swing.text.BadLocationException) DefaultHighlighter(javax.swing.text.DefaultHighlighter) Highlighter(javax.swing.text.Highlighter)

Example 3 with Highlight

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

the class CustomScanDialog method getInjectionPointList.

private JList<Highlight> getInjectionPointList() {
    if (injectionPointList == null) {
        injectionPointList = new JList<>(injectionPointModel);
        injectionPointList.setCellRenderer(new ListCellRenderer<Highlight>() {

            @Override
            public Component getListCellRendererComponent(JList<? extends Highlight> list, Highlight hlt, int index, boolean isSelected, boolean cellHasFocus) {
                String str = "";
                try {
                    str = getRequestField().getText(hlt.getStartOffset(), hlt.getEndOffset() - hlt.getStartOffset());
                    if (str.length() > 8) {
                        // just show first 8 chrs (arbitrary limit;)
                        str = str.substring(0, 8) + "..";
                    }
                } catch (BadLocationException e) {
                // Ignore
                }
                return new JLabel("[" + hlt.getStartOffset() + "," + hlt.getEndOffset() + "]: " + str);
            }
        });
    }
    return injectionPointList;
}
Also used : Highlight(javax.swing.text.Highlighter.Highlight) JLabel(javax.swing.JLabel) Component(java.awt.Component) BadLocationException(javax.swing.text.BadLocationException)

Example 4 with Highlight

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

the class CustomScanDialog method save.

/**
     * Use the save method to launch a scan
     */
@Override
public void save() {
    List<Object> contextSpecificObjects = new ArrayList<Object>();
    if (!this.getBoolValue(FIELD_ADVANCED)) {
        contextSpecificObjects.add(scanPolicy);
    } else {
        contextSpecificObjects.add(policyPanel.getScanPolicy());
        if (target == null && this.customPanels != null) {
            // One of the custom scan panels must have specified a target 
            for (CustomScanPanel customPanel : this.customPanels) {
                target = customPanel.getTarget();
                if (target != null) {
                    break;
                }
            }
        }
        // Save all Variant configurations
        getVariantPanel().saveParam(scannerParam);
        // force all injectable params and rpc model to NULL
        if (getDisableNonCustomVectors().isSelected()) {
            scannerParam.setTargetParamsInjectable(0);
            scannerParam.setTargetParamsEnabledRPC(0);
        }
        if (!getBoolValue(FIELD_RECURSE) && injectionPointModel.getSize() > 0) {
            int[][] injPoints = new int[injectionPointModel.getSize()][];
            for (int i = 0; i < injectionPointModel.getSize(); i++) {
                Highlight hl = injectionPointModel.elementAt(i);
                injPoints[i] = new int[2];
                injPoints[i][0] = hl.getStartOffset();
                injPoints[i][1] = hl.getEndOffset();
            }
            try {
                if (target != null && target.getStartNode() != null) {
                    VariantUserDefined.setInjectionPoints(this.target.getStartNode().getHistoryReference().getURI().toString(), injPoints);
                    enableUserDefinedRPC();
                }
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
            }
        }
        scannerParam.setHostPerScan(extension.getScannerParam().getHostPerScan());
        scannerParam.setThreadPerHost(extension.getScannerParam().getThreadPerHost());
        scannerParam.setHandleAntiCSRFTokens(extension.getScannerParam().getHandleAntiCSRFTokens());
        scannerParam.setMaxResultsToList(extension.getScannerParam().getMaxResultsToList());
        contextSpecificObjects.add(scannerParam);
        contextSpecificObjects.add(getTechTree().getTechSet());
        if (this.customPanels != null) {
            for (CustomScanPanel customPanel : this.customPanels) {
                Object[] objs = customPanel.getContextSpecificObjects();
                if (objs != null) {
                    for (Object obj : objs) {
                        contextSpecificObjects.add(obj);
                    }
                }
            }
        }
    }
    target.setRecurse(this.getBoolValue(FIELD_RECURSE));
    if (target.getContext() == null && getSelectedContext() != null) {
        target.setContext(getSelectedContext());
    }
    this.extension.startScan(target, getSelectedUser(), contextSpecificObjects.toArray());
}
Also used : Highlight(javax.swing.text.Highlighter.Highlight) ArrayList(java.util.ArrayList) HttpMalformedHeaderException(org.parosproxy.paros.network.HttpMalformedHeaderException) BadLocationException(javax.swing.text.BadLocationException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 5 with Highlight

use of javax.swing.text.Highlighter.Highlight 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)

Aggregations

Highlight (javax.swing.text.Highlighter.Highlight)5 BadLocationException (javax.swing.text.BadLocationException)3 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 JButton (javax.swing.JButton)2 DefaultHighlighter (javax.swing.text.DefaultHighlighter)2 Highlighter (javax.swing.text.Highlighter)2 Component (java.awt.Component)1 FontMetrics (java.awt.FontMetrics)1 ArrayList (java.util.ArrayList)1 JLabel (javax.swing.JLabel)1 HighlightPainter (javax.swing.text.Highlighter.HighlightPainter)1 ConfigurationException (org.apache.commons.configuration.ConfigurationException)1 DatabaseException (org.parosproxy.paros.db.DatabaseException)1 HttpMalformedHeaderException (org.parosproxy.paros.network.HttpMalformedHeaderException)1