Search in sources :

Example 76 with ActionListener

use of java.awt.event.ActionListener 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 77 with ActionListener

use of java.awt.event.ActionListener in project zaproxy by zaproxy.

the class OptionsApiPanel method getDisableKey.

private JCheckBox getDisableKey() {
    if (disableKey == null) {
        disableKey = new JCheckBox();
        disableKey.setText(Constant.messages.getString("api.options.disableKey"));
        disableKey.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        disableKey.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
        disableKey.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                getKeyField().setEnabled(!disableKey.isSelected());
                getGenerateKeyButton().setEnabled(!disableKey.isSelected());
                if (!disableKey.isSelected()) {
                    // Repopulate the previously used value
                    getKeyField().setText(Model.getSingleton().getOptionsParam().getApiParam().getRealKey());
                }
            }
        });
    }
    return disableKey;
}
Also used : JCheckBox(javax.swing.JCheckBox) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent)

Example 78 with ActionListener

use of java.awt.event.ActionListener in project zaproxy by zaproxy.

the class OptionsApiPanel method getGenerateKeyButton.

private JButton getGenerateKeyButton() {
    if (generateKeyButton == null) {
        generateKeyButton = new JButton(Constant.messages.getString("api.options.button.generateKey"));
        generateKeyButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                getKeyField().setText(ExtensionAPI.generateApiKey());
            }
        });
    }
    return generateKeyButton;
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton)

Example 79 with ActionListener

use of java.awt.event.ActionListener in project zaproxy by zaproxy.

the class ExtensionAutoUpdate method getOutOfDateButton.

private JButton getOutOfDateButton() {
    if (outOfDateButton == null) {
        outOfDateButton = new JButton(Constant.messages.getString("cfu.label.outofdateaddons"));
        outOfDateButton.setIcon(new ImageIcon(// Alert triangle
        ExtensionAutoUpdate.class.getResource("/resource/icon/16/050.png")));
        outOfDateButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                alertIfOutOfDate(true);
            }
        });
    }
    return outOfDateButton;
}
Also used : ImageIcon(javax.swing.ImageIcon) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton)

Example 80 with ActionListener

use of java.awt.event.ActionListener in project zaproxy by zaproxy.

the class ExtensionAutoUpdate method alertIfOutOfDate.

private void alertIfOutOfDate(boolean alwaysPrompt) {
    final OptionsParamCheckForUpdates options = getModel().getOptionsParam().getCheckForUpdatesParam();
    Date today = new Date();
    Date releaseCreated = Constant.getReleaseCreateDate();
    Date lastInstallWarning = options.getDayLastInstallWarned();
    int result = -1;
    logger.debug("Install created " + releaseCreated);
    if (releaseCreated != null) {
        // Should only be null for dev builds
        int daysOld = dayDiff(today, releaseCreated);
        logger.debug("Install is " + daysOld + " days old");
        if (daysOld > 365) {
            // Oh no, its more than a year old!
            boolean setCfuOnStart = false;
            if (alwaysPrompt || lastInstallWarning == null || dayDiff(today, lastInstallWarning) > 30) {
                JCheckBox cfuOnStart = new JCheckBox(Constant.messages.getString("cfu.label.cfuonstart"));
                cfuOnStart.setSelected(true);
                String msg = Constant.messages.getString("cfu.label.oldzap");
                result = View.getSingleton().showYesNoDialog(View.getSingleton().getMainFrame(), new Object[] { msg, cfuOnStart });
                setCfuOnStart = cfuOnStart.isSelected();
            }
            options.setDayLastInstallWarned();
            if (result == JOptionPane.OK_OPTION) {
                if (setCfuOnStart) {
                    options.setCheckOnStart(true);
                }
                getAddOnsDialog().setVisible(true);
                getAddOnsDialog().checkForUpdates();
            } else if (!oldZapAlertAdded) {
                JButton button = new JButton(Constant.messages.getString("cfu.label.outofdatezap"));
                button.setIcon(new ImageIcon(// Alert triangle
                ExtensionAutoUpdate.class.getResource("/resource/icon/16/050.png")));
                button.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        alertIfOutOfDate(true);
                    }
                });
                View.getSingleton().getMainFrame().getMainFooterPanel().addFooterToolbarLeftComponent(button);
                oldZapAlertAdded = true;
            }
            return;
        }
    }
    Date lastChecked = options.getDayLastChecked();
    Date lastUpdateWarning = options.getDayLastUpdateWarned();
    Date installDate = Constant.getInstallDate();
    if (installDate == null || dayDiff(today, installDate) < 90) {
    // Dont warn if installed in the last 3 months
    } else if (lastChecked == null || dayDiff(today, lastChecked) > 90) {
        // Not checked for updates in 3 months :(
        boolean setCfuOnStart = false;
        if (alwaysPrompt || lastUpdateWarning == null || dayDiff(today, lastUpdateWarning) > 30) {
            JCheckBox cfuOnStart = new JCheckBox(Constant.messages.getString("cfu.label.cfuonstart"));
            cfuOnStart.setSelected(true);
            String msg = Constant.messages.getString("cfu.label.norecentcfu");
            result = View.getSingleton().showYesNoDialog(View.getSingleton().getMainFrame(), new Object[] { msg, cfuOnStart });
            setCfuOnStart = cfuOnStart.isSelected();
        }
        options.setDayLastUpdateWarned();
        if (result == JOptionPane.OK_OPTION) {
            if (setCfuOnStart) {
                options.setCheckOnStart(true);
            }
            getAddOnsDialog().setVisible(true);
            getAddOnsDialog().checkForUpdates();
            if (noCfuAlertAdded) {
                View.getSingleton().getMainFrame().getMainFooterPanel().removeFooterToolbarLeftComponent(getOutOfDateButton());
            }
        } else if (!noCfuAlertAdded) {
            View.getSingleton().getMainFrame().getMainFooterPanel().addFooterToolbarLeftComponent(getOutOfDateButton());
            noCfuAlertAdded = true;
        }
    }
}
Also used : JCheckBox(javax.swing.JCheckBox) ImageIcon(javax.swing.ImageIcon) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) Date(java.util.Date)

Aggregations

ActionListener (java.awt.event.ActionListener)1347 ActionEvent (java.awt.event.ActionEvent)1303 JButton (javax.swing.JButton)363 JPanel (javax.swing.JPanel)345 JLabel (javax.swing.JLabel)234 JMenuItem (javax.swing.JMenuItem)191 BoxLayout (javax.swing.BoxLayout)150 GridBagConstraints (java.awt.GridBagConstraints)121 Insets (java.awt.Insets)121 GridBagLayout (java.awt.GridBagLayout)114 Dimension (java.awt.Dimension)113 FlowLayout (java.awt.FlowLayout)110 JCheckBox (javax.swing.JCheckBox)103 JScrollPane (javax.swing.JScrollPane)103 JMenu (javax.swing.JMenu)96 BorderLayout (java.awt.BorderLayout)88 JTextField (javax.swing.JTextField)79 JComboBox (javax.swing.JComboBox)73 ButtonGroup (javax.swing.ButtonGroup)64 ArrayList (java.util.ArrayList)60