Search in sources :

Example 1 with ZapNumberSpinner

use of org.zaproxy.zap.utils.ZapNumberSpinner in project zaproxy by zaproxy.

the class AlertViewPanel method getAlertDisplay.

private JPanel getAlertDisplay() {
    if (alertDisplay == null) {
        alertDisplay = new JPanel();
        alertDisplay.setLayout(new GridBagLayout());
        alertDisplay.setName("alertDisplay");
        // Create the labels
        alertEditName = new JComboBox<>();
        alertEditName.setEditable(true);
        nameListModel = new DefaultComboBoxModel<>();
        List<String> allVulns = getAllVulnerabilityNames();
        // Default to blank
        nameListModel.addElement("");
        for (String vuln : allVulns) {
            nameListModel.addElement(vuln);
        }
        alertEditName.setModel(nameListModel);
        alertEditName.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if ("comboBoxChanged".equals(e.getActionCommand())) {
                    Vulnerability v = getVulnerability((String) alertEditName.getSelectedItem());
                    if (v != null) {
                        if (v.getDescription() != null && v.getDescription().length() > 0) {
                            setAlertDescription(v.getDescription());
                        }
                        if (v.getSolution() != null && v.getSolution().length() > 0) {
                            setAlertSolution(v.getSolution());
                        }
                        if (v.getReferences() != null) {
                            StringBuilder sb = new StringBuilder();
                            for (String ref : v.getReferences()) {
                                sb.append(ref);
                                sb.append('\n');
                            }
                            setAlertReference(sb.toString());
                        }
                        alertEditWascId.setValue(v.getWascId());
                    }
                }
            }
        });
        alertEditRisk = new JComboBox<>(Alert.MSG_RISK);
        alertEditConfidence = new JComboBox<>(Alert.MSG_CONFIDENCE);
        alertEditConfidence.setSelectedItem(Alert.MSG_CONFIDENCE[Alert.CONFIDENCE_MEDIUM]);
        alertEditAttack = new ZapTextField();
        paramListModel = new DefaultComboBoxModel<>();
        // Default is empty so user can type anything in
        paramListModel.addElement("");
        alertEditParam = new JComboBox<>();
        alertEditParam.setModel(paramListModel);
        alertEditParam.setEditable(true);
        alertEditEvidence = new ZapTextField();
        alertEditCweId = new ZapNumberSpinner();
        if (alertEditCweId.getEditor() instanceof JSpinner.DefaultEditor) {
            ((JSpinner.DefaultEditor) alertEditCweId.getEditor()).getTextField().setHorizontalAlignment(JTextField.LEFT);
        }
        alertEditWascId = new ZapNumberSpinner();
        if (alertEditWascId.getEditor() instanceof JSpinner.DefaultEditor) {
            ((JSpinner.DefaultEditor) alertEditWascId.getEditor()).getTextField().setHorizontalAlignment(JTextField.LEFT);
        }
        // Read only ones
        alertName = new ZapLabel();
        alertName.setFont(FontUtils.getFont(Font.BOLD));
        alertRisk = new JLabel();
        alertConfidence = new JLabel();
        alertParam = new ZapLabel();
        alertAttack = new ZapLabel();
        alertEvidence = new ZapLabel();
        alertCweId = new JLabel();
        alertWascId = new JLabel();
        alertSource = new JLabel();
        alertUrl = new ZapLabel();
        alertDescription = createZapTextArea();
        JScrollPane descSp = createJScrollPane(Constant.messages.getString("alert.label.desc"));
        descSp.setViewportView(alertDescription);
        alertDescription.addKeyListener(new KeyAdapter() {

            // Change tab key to transfer focus to the next element
            @Override
            public void keyPressed(java.awt.event.KeyEvent evt) {
                if (evt.getKeyCode() == KeyEvent.VK_TAB) {
                    alertDescription.transferFocus();
                }
            }
        });
        alertOtherInfo = createZapTextArea();
        JScrollPane otherSp = createJScrollPane(Constant.messages.getString("alert.label.other"));
        otherSp.setViewportView(alertOtherInfo);
        alertOtherInfo.addKeyListener(new KeyAdapter() {

            // Change tab key to transfer focus to the next element
            @Override
            public void keyPressed(java.awt.event.KeyEvent evt) {
                if (evt.getKeyCode() == KeyEvent.VK_TAB) {
                    alertOtherInfo.transferFocus();
                }
            }
        });
        alertSolution = createZapTextArea();
        JScrollPane solutionSp = createJScrollPane(Constant.messages.getString("alert.label.solution"));
        solutionSp.setViewportView(alertSolution);
        alertSolution.addKeyListener(new KeyAdapter() {

            // Change tab key to transfer focus to the next element
            @Override
            public void keyPressed(java.awt.event.KeyEvent evt) {
                if (evt.getKeyCode() == KeyEvent.VK_TAB) {
                    alertSolution.transferFocus();
                }
            }
        });
        alertReference = createZapTextArea();
        JScrollPane referenceSp = createJScrollPane(Constant.messages.getString("alert.label.ref"));
        referenceSp.setViewportView(alertReference);
        alertReference.addKeyListener(new KeyAdapter() {

            // Change tab key to transfer focus to the next element
            @Override
            public void keyPressed(java.awt.event.KeyEvent evt) {
                if (evt.getKeyCode() == KeyEvent.VK_TAB) {
                    alertReference.transferFocus();
                }
            }
        });
        int gbcRow = 0;
        alertDisplay.add(editable ? alertEditName : alertName, LayoutHelper.getGBC(0, gbcRow, 2, 0, DEFAULT_INSETS));
        // Show a blank label instead of the edit button if already editing
        gbcRow++;
        alertDisplay.add(getUrlLabel(), LayoutHelper.getGBC(0, gbcRow, 1, 0, DEFAULT_INSETS));
        alertDisplay.add(alertUrl, LayoutHelper.getGBC(1, gbcRow, 1, 1, DEFAULT_INSETS));
        gbcRow++;
        alertDisplay.add(getRiskLabel(), LayoutHelper.getGBC(0, gbcRow, 1, 0, DEFAULT_INSETS));
        alertDisplay.add(editable ? alertEditRisk : alertRisk, LayoutHelper.getGBC(1, gbcRow, 1, 1, DEFAULT_INSETS));
        gbcRow++;
        alertDisplay.add(getConfidenceLabel(), LayoutHelper.getGBC(0, gbcRow, 1, 0, DEFAULT_INSETS));
        alertDisplay.add(editable ? alertEditConfidence : alertConfidence, LayoutHelper.getGBC(1, gbcRow, 1, 1, DEFAULT_INSETS));
        gbcRow++;
        alertDisplay.add(getParameterLabel(), LayoutHelper.getGBC(0, gbcRow, 1, 0, DEFAULT_INSETS));
        alertDisplay.add(editable ? alertEditParam : alertParam, LayoutHelper.getGBC(1, gbcRow, 1, 1, DEFAULT_INSETS));
        gbcRow++;
        alertDisplay.add(getAttackLabel(), LayoutHelper.getGBC(0, gbcRow, 1, 0, DEFAULT_INSETS));
        alertDisplay.add(editable ? alertEditAttack : alertAttack, LayoutHelper.getGBC(1, gbcRow, 1, 1, DEFAULT_INSETS));
        gbcRow++;
        alertDisplay.add(getEvidenceLabel(), LayoutHelper.getGBC(0, gbcRow, 1, 0, DEFAULT_INSETS));
        alertDisplay.add(editable ? alertEditEvidence : alertEvidence, LayoutHelper.getGBC(1, gbcRow, 1, 1, DEFAULT_INSETS));
        gbcRow++;
        alertDisplay.add(getCweidLabel(), LayoutHelper.getGBC(0, gbcRow, 1, 0, DEFAULT_INSETS));
        alertDisplay.add(editable ? alertEditCweId : alertCweId, LayoutHelper.getGBC(1, gbcRow, 1, 1, DEFAULT_INSETS));
        gbcRow++;
        alertDisplay.add(getWascidLabel(), LayoutHelper.getGBC(0, gbcRow, 1, 0, DEFAULT_INSETS));
        alertDisplay.add(editable ? alertEditWascId : alertWascId, LayoutHelper.getGBC(1, gbcRow, 1, 1, DEFAULT_INSETS));
        gbcRow++;
        if (!editable) {
            alertDisplay.add(getSourceLabel(), LayoutHelper.getGBC(0, gbcRow, 1, 0, DEFAULT_INSETS));
            alertDisplay.add(alertSource, LayoutHelper.getGBC(1, gbcRow, 1, 1, DEFAULT_INSETS));
            gbcRow++;
        }
        alertDisplay.add(descSp, LayoutHelper.getGBC(0, gbcRow, 2, 1.0D, 1.0D, GridBagConstraints.BOTH, DEFAULT_INSETS));
        gbcRow++;
        alertDisplay.add(otherSp, LayoutHelper.getGBC(0, gbcRow, 2, 1.0D, 1.0D, GridBagConstraints.BOTH, DEFAULT_INSETS));
        gbcRow++;
        alertDisplay.add(solutionSp, LayoutHelper.getGBC(0, gbcRow, 2, 1.0D, 1.0D, GridBagConstraints.BOTH, DEFAULT_INSETS));
        gbcRow++;
        alertDisplay.add(referenceSp, LayoutHelper.getGBC(0, gbcRow, 2, 1.0D, 1.0D, GridBagConstraints.BOTH, DEFAULT_INSETS));
    }
    return alertDisplay;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter) JLabel(javax.swing.JLabel) Vulnerability(org.zaproxy.zap.model.Vulnerability) ZapLabel(org.zaproxy.zap.utils.ZapLabel) KeyEvent(java.awt.event.KeyEvent) ActionListener(java.awt.event.ActionListener) ZapNumberSpinner(org.zaproxy.zap.utils.ZapNumberSpinner) ZapTextField(org.zaproxy.zap.utils.ZapTextField) JSpinner(javax.swing.JSpinner)

Example 2 with ZapNumberSpinner

use of org.zaproxy.zap.utils.ZapNumberSpinner in project zaproxy by zaproxy.

the class OptionsScannerPanel method getSpinnerMaxResultsList.

private ZapNumberSpinner getSpinnerMaxResultsList() {
    if (spinnerMaxResultsList == null) {
        spinnerMaxResultsList = new ZapNumberSpinner();
        spinnerMaxResultsList.setToolTipText(Constant.messages.getString("ascan.options.maxRes.tooltip"));
    }
    return spinnerMaxResultsList;
}
Also used : ZapNumberSpinner(org.zaproxy.zap.utils.ZapNumberSpinner)

Example 3 with ZapNumberSpinner

use of org.zaproxy.zap.utils.ZapNumberSpinner in project zaproxy by zaproxy.

the class OptionsScannerPanel method getSpinnerMaxChartTime.

private ZapNumberSpinner getSpinnerMaxChartTime() {
    if (spinnerMaxChartTime == null) {
        spinnerMaxChartTime = new ZapNumberSpinner();
        spinnerMaxChartTime.setToolTipText(Constant.messages.getString("ascan.options.maxChart.tooltip"));
    }
    return spinnerMaxChartTime;
}
Also used : ZapNumberSpinner(org.zaproxy.zap.utils.ZapNumberSpinner)

Example 4 with ZapNumberSpinner

use of org.zaproxy.zap.utils.ZapNumberSpinner in project zaproxy by zaproxy.

the class OptionsViewPanel method getFontSize.

private ZapNumberSpinner getFontSize() {
    if (fontSize == null) {
        fontSize = new ZapNumberSpinner(-1, 8, 100);
        if (!FontUtils.canChangeSize()) {
            fontSize.setEnabled(false);
        }
        fontSize.addChangeListener(new ChangeListener() {

            @Override
            public void stateChanged(ChangeEvent e) {
                // Show what the default font will look like
                setExampleFont();
            }
        });
    }
    return fontSize;
}
Also used : ChangeEvent(javax.swing.event.ChangeEvent) ZapNumberSpinner(org.zaproxy.zap.utils.ZapNumberSpinner) ChangeListener(javax.swing.event.ChangeListener)

Example 5 with ZapNumberSpinner

use of org.zaproxy.zap.utils.ZapNumberSpinner in project zaproxy by zaproxy.

the class StandardFieldsDialog method addNumberField.

public void addNumberField(String fieldLabel, Integer min, Integer max, int value) {
    if (isTabbed()) {
        throw new IllegalArgumentException("Initialised as a tabbed dialog - must use method with tab parameters");
    }
    ZapNumberSpinner field = new ZapNumberSpinner(min, value, max);
    this.addField(fieldLabel, field, field, 0.0D);
}
Also used : ZapNumberSpinner(org.zaproxy.zap.utils.ZapNumberSpinner)

Aggregations

ZapNumberSpinner (org.zaproxy.zap.utils.ZapNumberSpinner)5 GridBagLayout (java.awt.GridBagLayout)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 KeyAdapter (java.awt.event.KeyAdapter)1 KeyEvent (java.awt.event.KeyEvent)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 JScrollPane (javax.swing.JScrollPane)1 JSpinner (javax.swing.JSpinner)1 ChangeEvent (javax.swing.event.ChangeEvent)1 ChangeListener (javax.swing.event.ChangeListener)1 Vulnerability (org.zaproxy.zap.model.Vulnerability)1 ZapLabel (org.zaproxy.zap.utils.ZapLabel)1 ZapTextField (org.zaproxy.zap.utils.ZapTextField)1