Example usage for javax.swing JButton setIcon

List of usage examples for javax.swing JButton setIcon

Introduction

In this page you can find the example usage for javax.swing JButton setIcon.

Prototype

@BeanProperty(visualUpdate = true, description = "The button's default icon")
public void setIcon(Icon defaultIcon) 

Source Link

Document

Sets the button's default icon.

Usage

From source file:org.tinymediamanager.ui.tvshows.dialogs.TvShowExporterDialog.java

/**
 * Create the dialog./*from  w ww .  j a  v  a2s. c  o m*/
 * 
 * @param tvShowsToExport
 *          the movies to export
 */
public TvShowExporterDialog(List<TvShow> tvShowsToExport) {
    super(BUNDLE.getString("tvshow.export"), "tvShowExporter"); //$NON-NLS-1$
    setBounds(5, 5, 600, 300);

    getContentPane().setLayout(new FormLayout(
            new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("300dlu:grow"),
                    FormSpecs.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("100dlu:grow"),
                    FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.UNRELATED_GAP_ROWSPEC,
                    FormSpecs.DEFAULT_ROWSPEC, FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, }));

    JSplitPane splitPane = new JSplitPane();
    splitPane.setResizeWeight(0.7);
    getContentPane().add(splitPane, "2, 2, fill, fill");

    JScrollPane scrollPane = new JScrollPane();
    splitPane.setLeftComponent(scrollPane);

    list = new JList();
    scrollPane.setViewportView(list);

    JPanel panelExporterDetails = new JPanel();
    splitPane.setRightComponent(panelExporterDetails);
    panelExporterDetails.setLayout(new FormLayout(
            new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC,
                    FormSpecs.LABEL_COMPONENT_GAP_COLSPEC, ColumnSpec.decode("default:grow"),
                    FormSpecs.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, RowSpec.decode("default:grow"), }));

    lblTemplateName = new JLabel("");
    panelExporterDetails.add(lblTemplateName, "2, 2, 3, 1");

    lblUrl = new JLabel("");
    panelExporterDetails.add(lblUrl, "2, 4, 3, 1");

    chckbxTemplateWithDetail = new JCheckBox("");
    chckbxTemplateWithDetail.setEnabled(false);
    panelExporterDetails.add(chckbxTemplateWithDetail, "2, 6");

    JLabel lblDetails = new JLabel(BUNDLE.getString("export.detail")); //$NON-NLS-1$
    panelExporterDetails.add(lblDetails, "4, 6");

    JScrollPane scrollPaneDescription = new JScrollPane();
    panelExporterDetails.add(scrollPaneDescription, "2, 8, 3, 1, fill, fill");

    tpDescription = new JTextPane();
    scrollPaneDescription.setViewportView(tpDescription);
    splitPane.setDividerLocation(300);

    JPanel panel = new JPanel();
    getContentPane().add(panel, "2, 4, fill, fill");
    panel.setLayout(
            new FormLayout(new ColumnSpec[] { ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC,
                    FormSpecs.DEFAULT_COLSPEC, }, new RowSpec[] { FormSpecs.DEFAULT_ROWSPEC, }));

    tfExportDir = new JTextField();
    panel.add(tfExportDir, "1, 1, fill, default");
    tfExportDir.setColumns(10);

    JButton btnSetDestination = new JButton(BUNDLE.getString("export.setdestination")); //$NON-NLS-1$
    panel.add(btnSetDestination, "3, 1");
    btnSetDestination.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Path file = TmmUIHelper.selectDirectory(BUNDLE.getString("export.selectdirectory")); //$NON-NLS-1$
            if (file != null) {
                tfExportDir.setText(file.toAbsolutePath().toString());
            }
        }
    });

    JPanel panelButtons = new JPanel();
    panelButtons.setLayout(new EqualsLayout(5));
    getContentPane().add(panelButtons, "2, 6, fill, fill");

    JButton btnExport = new JButton("Export");
    btnExport.setIcon(IconManager.EXPORT);
    btnExport.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (StringUtils.isBlank(tfExportDir.getText())) {
                return;
            }
            // check selected template
            int index = list.getSelectedIndex();
            if (index < 0) {
                return;
            }

            ExportTemplate selectedTemplate = templatesFound.get(index);
            if (selectedTemplate != null) {
                try {
                    TvShowExporter exporter = new TvShowExporter(Paths.get(selectedTemplate.getPath()));
                    exporter.export(tvShows, Paths.get(tfExportDir.getText()));
                } catch (Exception e) {
                    LOGGER.error("Error exporting tv shows: ", e);
                }
                setVisible(false);
            }
        }
    });
    panelButtons.add(btnExport);

    JButton btnCancel = new JButton(BUNDLE.getString("Button.cancel")); //$NON-NLS-1$
    btnCancel.setIcon(IconManager.CANCEL);
    btnCancel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            setVisible(false);
        }
    });
    panelButtons.add(btnCancel);

    tvShows = tvShowsToExport;
    templatesFound = TvShowExporter.findTemplates(TemplateType.TV_SHOW);
    initDataBindings();
}

From source file:org.tinymediamanager.ui.tvshows.dialogs.TvShowSubtitleChooserDialog.java

private void initComponents() {
    getContentPane().setLayout(new BorderLayout());

    final JPanel panelContent = new JPanel();
    getContentPane().add(panelContent, BorderLayout.CENTER);
    panelContent.setLayout(new FormLayout(
            new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC,
                    FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("100dlu:grow"),
                    FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC,
                    FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("200dlu:grow"),
                    FormSpecs.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.UNRELATED_GAP_ROWSPEC,
                    FormSpecs.DEFAULT_ROWSPEC, FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("120dlu:grow"),
                    FormSpecs.RELATED_GAP_ROWSPEC, }));

    final JLabel lblEpisodeTitle = new JLabel(episodeToScrape.getTitle());
    TmmFontHelper.changeFont(lblEpisodeTitle, 1.33, Font.BOLD);
    panelContent.add(lblEpisodeTitle, "2, 2, 9, 1");

    JLabel lblSeasonT = new JLabel(BUNDLE.getString("metatag.season")); //$NON-NLS-1$
    panelContent.add(lblSeasonT, "2, 4, right, default");

    JLabel lblSeason = new JLabel(String.valueOf(episodeToScrape.getSeason()));
    panelContent.add(lblSeason, "4, 4");

    JLabel lblEpisodeT = new JLabel(BUNDLE.getString("metatag.episode")); //$NON-NLS-1$
    panelContent.add(lblEpisodeT, "2, 6, right, default");

    JLabel lblEpisode = new JLabel(String.valueOf(episodeToScrape.getEpisode()));
    panelContent.add(lblEpisode, "4, 6");

    final JLabel lblMediaFileNameT = new JLabel(BUNDLE.getString("metatag.filename")); //$NON-NLS-1$
    panelContent.add(lblMediaFileNameT, "2, 8, right, default");

    final JLabel lblMediaFileName = new JLabel(fileToScrape.getFilename());
    panelContent.add(lblMediaFileName, "4, 8, 7, 1");

    final JLabel lblScraperT = new JLabel(BUNDLE.getString("scraper")); //$NON-NLS-1$
    panelContent.add(lblScraperT, "2, 10, right, default");

    cbScraper = new MediaScraperCheckComboBox();
    panelContent.add(cbScraper, "4, 10, fill, default");

    final JLabel lblLanguageT = new JLabel(BUNDLE.getString("metatag.language")); //$NON-NLS-1$
    panelContent.add(lblLanguageT, "2, 12, right, default");

    cbLanguage = new JComboBox<>();
    panelContent.add(cbLanguage, "4, 12, fill, default");

    final JButton btnSearch = new JButton(BUNDLE.getString("Button.search")); //$NON-NLS-1$
    btnSearch.addActionListener(new ActionListener() {
        @Override/*from  ww w  .  j  a v  a  2s  .  co  m*/
        public void actionPerformed(ActionEvent e) {
            searchSubtitle(fileToScrape.getFileAsPath().toFile(), episodeToScrape.getTvShow().getImdbId(),
                    episodeToScrape.getSeason(), episodeToScrape.getEpisode());
        }
    });
    panelContent.add(btnSearch, "8, 12");

    final JScrollPane scrollPaneSubs = new JScrollPane();
    panelContent.add(scrollPaneSubs, "2, 14, 9, 1, fill, fill");

    tableSubs = new JTable(subtitleTableModel);
    scrollPaneSubs.setViewportView(tableSubs);

    {
        JPanel panelBottom = new JPanel();
        getContentPane().add(panelBottom, BorderLayout.SOUTH);
        panelBottom.setLayout(new FormLayout(
                new ColumnSpec[] { FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
                        ColumnSpec.decode("max(82dlu;default)"), FormFactory.RELATED_GAP_COLSPEC,
                        ColumnSpec.decode("default:grow"), FormFactory.DEFAULT_COLSPEC, },
                new RowSpec[] { FormFactory.LINE_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC,
                        FormFactory.LINE_GAP_ROWSPEC }));

        progressBar = new JProgressBar();
        panelBottom.add(progressBar, "2, 2");

        lblProgressAction = new JLabel("");
        panelBottom.add(lblProgressAction, "4, 2");

        {
            final JPanel panelButtons = new JPanel();
            EqualsLayout layout = new EqualsLayout(5);
            layout.setMinWidth(100);
            panelButtons.setLayout(layout);
            panelBottom.add(panelButtons, "5, 2, fill, fill");

            JButton btnDone = new JButton(BUNDLE.getString("Button.done")); //$NON-NLS-1$
            btnDone.setIcon(IconManager.APPLY);
            btnDone.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    setVisible(false);
                }
            });
            panelButtons.add(btnDone);

            if (inQueue) {
                JButton btnAbortQueue = new JButton(BUNDLE.getString("Button.abortqueue")); //$NON-NLS-1$
                btnAbortQueue.setIcon(IconManager.PROCESS_STOP);
                btnAbortQueue.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        continueQueue = false;
                        setVisible(false);
                    }
                });
                panelButtons.add(btnAbortQueue);
            }
        }
    }
}

From source file:org.ut.biolab.medsavant.client.view.notify.NotificationsPanel.java

private void refreshButtonIcons() {
    if (isHidden) {
        for (JButton menuButton : menuButtons) {
            menuButton.setIcon(inactiveButtonIcon);
            menuButton.setToolTipText("Show notifications");
        }/*from w  ww .ja v  a  2s  .  c  o m*/
    } else {
        for (JButton menuButton : menuButtons) {
            menuButton.setIcon(activeButtonIcon);
            menuButton.setToolTipText("Hide notifications");
        }
    }
}

From source file:org.xulux.swing.util.SwingUtilsTest.java

/**
 * Test the swing components for accepting null values in images and imageIcons.
 *//*from   w ww.j  a va  2 s .co  m*/
public void testSwingComponents() {
    System.out.println("testSwingComponents");
    JLabel label = new JLabel((Icon) null);
    label.setIcon(null);
    JButton button = new JButton((Icon) null);
    button.setIcon(null);
}

From source file:org.zaproxy.zap.extension.autoupdate.ExtensionAutoUpdate.java

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();

            }//from ww  w .j av  a 2  s .  c  o m
            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(ExtensionAutoUpdate.class.getResource("/resource/icon/16/050.png"))); // Alert triangle
                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;
        }
    }
}

From source file:org.zaproxy.zap.extension.browserView.ResponseBrowserView.java

private JButton createAdjustHeightButton() {
    JButton button = new JButton();
    button.setToolTipText(ADJUST_HEIGHT_BUTTON_TOOLTIP);
    button.setIcon(ADJUST_HEIGHT_ICON);

    ActionListener actionListener = new ActionListener() {
        @Override//  w w  w . j a v  a  2 s  . co  m
        public void actionPerformed(ActionEvent arg0) {
            ssb.adjustPanelHeightToWebsite();
        }
    };

    button.addActionListener(actionListener);
    return button;
}

From source file:org.zaproxy.zap.extension.dynssl.DynamicSSLPanel.java

/**
 * Create the panel.// ww  w  .jav a  2s. com
 */
public DynamicSSLPanel(ExtensionDynSSL extension) {
    super();
    this.extension = extension;

    setName(Constant.messages.getString("dynssl.options.name"));
    setLayout(new BorderLayout(0, 0));

    final JPanel panel = new JPanel();
    panel.setBorder(new EmptyBorder(2, 2, 2, 2));
    add(panel);

    final JLabel lbl_Cert = new JLabel(Constant.messages.getString("dynssl.label.rootca"));

    txt_PubCert = new ZapTextArea();
    txt_PubCert.setFont(FontUtils.getFont("Monospaced"));
    txt_PubCert.setEditable(false);
    txt_PubCert.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent e) {
            checkAndEnableButtons();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            checkAndEnableButtons();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            checkAndEnableButtons();
        }

        private void checkAndEnableButtons() {
            checkAndEnableViewButton();
            checkAndEnableSaveButton();
        }
    });

    final JScrollPane pubCertScrollPane = new JScrollPane(txt_PubCert);

    final JButton bt_generate = new JButton(Constant.messages.getString("dynssl.button.generate"));
    bt_generate.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            doGenerate();
        }
    });
    bt_generate.setIcon(new ImageIcon(DynamicSSLPanel.class.getResource("/resource/icon/16/041.png")));

    bt_save = new JButton(Constant.messages.getString("menu.file.save"));
    checkAndEnableSaveButton();
    bt_save.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            doSave();
        }
    });
    bt_save.setIcon(new ImageIcon(DynamicSSLPanel.class.getResource("/resource/icon/16/096.png")));

    bt_view = new JButton(Constant.messages.getString("menu.view"));
    checkAndEnableViewButton();
    bt_view.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            doView();
        }
    });
    bt_view.setIcon(new ImageIcon(DynamicSSLPanel.class.getResource("/resource/icon/16/049.png")));

    final JButton bt_import = new JButton(Constant.messages.getString("dynssl.button.import"));
    bt_import.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            doImport();
        }
    });
    bt_import.setIcon(new ImageIcon(DynamicSSLPanel.class.getResource("/resource/icon/16/047.png")));

    final GroupLayout gl_panel = new GroupLayout(panel);
    gl_panel.setHorizontalGroup(gl_panel.createParallelGroup(Alignment.LEADING).addGroup(gl_panel
            .createSequentialGroup().addContainerGap()
            .addGroup(gl_panel.createParallelGroup(Alignment.LEADING, false).addGroup(gl_panel
                    .createSequentialGroup()
                    .addGroup(gl_panel.createParallelGroup(Alignment.LEADING, false)
                            .addComponent(lbl_Cert, GroupLayout.PREFERRED_SIZE, 115, GroupLayout.PREFERRED_SIZE)
                            .addGroup(gl_panel.createSequentialGroup()
                                    .addPreferredGap(ComponentPlacement.RELATED).addComponent(bt_generate)))
                    .addGap(6))
                    .addGroup(gl_panel.createSequentialGroup().addComponent(bt_import)
                            .addPreferredGap(ComponentPlacement.RELATED)))
            .addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
                    .addGroup(gl_panel.createSequentialGroup().addComponent(bt_view)
                            .addPreferredGap(ComponentPlacement.RELATED).addComponent(bt_save))
                    .addComponent(pubCertScrollPane, GroupLayout.DEFAULT_SIZE, 369, Short.MAX_VALUE))
            .addContainerGap()));
    gl_panel.setVerticalGroup(gl_panel.createParallelGroup(Alignment.LEADING).addGroup(gl_panel
            .createSequentialGroup().addGap(10)
            .addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
                    .addGroup(gl_panel.createSequentialGroup().addComponent(lbl_Cert).addGap(10)
                            .addComponent(bt_generate, GroupLayout.PREFERRED_SIZE, 25,
                                    GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(ComponentPlacement.RELATED).addComponent(bt_import,
                                    GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE))
                    .addComponent(pubCertScrollPane, GroupLayout.PREFERRED_SIZE, 400,
                            GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(ComponentPlacement.RELATED)
            .addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
                    .addComponent(bt_save, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE)
                    .addComponent(bt_view, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE))
            .addGap(0, 29, Short.MAX_VALUE)));
    panel.setLayout(gl_panel);
}

From source file:org.zaproxy.zap.extension.fuzz.httpfuzzer.ui.HttpFuzzResultsContentPanel.java

public HttpFuzzResultsContentPanel() {
    super(new BorderLayout());

    tabbedPane = new JTabbedPane();

    toolbar = new JToolBar();
    toolbar.setFloatable(false);/*w  w  w  . j  ava2  s  . com*/
    toolbar.setRollover(true);

    messageCountLabel = new JLabel(Constant.messages.getString("fuzz.httpfuzzer.results.toolbar.messagesSent"));
    messageCountValueLabel = new JLabel("0");

    errorCountLabel = new JLabel(Constant.messages.getString("fuzz.httpfuzzer.results.toolbar.errors"));
    errorCountValueLabel = new JLabel("0");

    showErrorsToggleButton = new ZapToggleButton(
            Constant.messages.getString("fuzz.httpfuzzer.results.toolbar.button.showErrors.label"));
    showErrorsToggleButton.setEnabled(false);
    showErrorsToggleButton.setToolTipText(
            Constant.messages.getString("fuzz.httpfuzzer.results.toolbar.button.showErrors.tooltip"));
    showErrorsToggleButton.setSelectedToolTipText(
            Constant.messages.getString("fuzz.httpfuzzer.results.toolbar.button.showErrors.tooltip.selected"));
    showErrorsToggleButton.setDisabledToolTipText(
            Constant.messages.getString("fuzz.httpfuzzer.results.toolbar.button.showErrors.tooltip.disabled"));
    showErrorsToggleButton
            .setIcon(new ImageIcon(HttpFuzzResultsContentPanel.class.getResource("/resource/icon/16/050.png")));
    showErrorsToggleButton.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (ItemEvent.SELECTED == e.getStateChange()) {
                showTabs();
            } else {
                hideErrorsTab();
            }
        }
    });

    toolbar.add(Box.createHorizontalStrut(4));
    toolbar.add(messageCountLabel);
    toolbar.add(Box.createHorizontalStrut(4));
    toolbar.add(messageCountValueLabel);
    toolbar.add(Box.createHorizontalStrut(32));

    toolbar.add(errorCountLabel);
    toolbar.add(Box.createHorizontalStrut(4));
    toolbar.add(errorCountValueLabel);

    toolbar.add(Box.createHorizontalStrut(16));
    toolbar.add(showErrorsToggleButton);

    JButton button = new JButton(Constant.messages.getString("fuzz.httpfuzzer.results.toolbar.button.export"));
    button.setIcon(new ImageIcon(HttpFuzzResultsContentPanel.class.getResource("/resource/icon/16/115.png")));
    button.addActionListener((new AbstractAction() {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            WritableFileChooser chooser = new WritableFileChooser(
                    Model.getSingleton().getOptionsParam().getUserDirectory()) {

                private static final long serialVersionUID = -1660943014924270012L;

                @Override
                public void approveSelection() {
                    File file = getSelectedFile();
                    if (file != null) {
                        String filePath = file.getAbsolutePath();
                        if (!filePath.toLowerCase(Locale.ROOT).endsWith(CSV_EXTENSION)) {
                            setSelectedFile(new File(filePath + CSV_EXTENSION));
                        }
                    }

                    super.approveSelection();
                }
            };
            chooser.setSelectedFile(new File(
                    Constant.messages.getString("fuzz.httpfuzzer.results.toolbar.button.export.defaultName")));
            if (chooser
                    .showSaveDialog(View.getSingleton().getMainFrame()) == WritableFileChooser.APPROVE_OPTION) {

                boolean success = true;
                try (CSVPrinter pw = new CSVPrinter(
                        Files.newBufferedWriter(chooser.getSelectedFile().toPath(), StandardCharsets.UTF_8),
                        CSVFormat.DEFAULT)) {
                    pw.printRecord(currentFuzzer.getMessagesModel().getHeaders());
                    int count = currentFuzzer.getMessagesModel().getRowCount();
                    for (int i = 0; i < count; i++) {
                        List<Object> valueOfRow = currentFuzzer.getMessagesModel().getEntry(i)
                                .getValuesOfHeaders();
                        String customStateValue = fuzzResultTable.getCustomStateValue(
                                currentFuzzer.getMessagesModel().getEntry(i).getCustomStates());
                        valueOfRow.add(13, customStateValue);
                        pw.printRecord(valueOfRow);
                    }
                } catch (Exception ex) {
                    success = false;
                    JOptionPane.showMessageDialog(View.getSingleton().getMainFrame(),
                            Constant.messages
                                    .getString("fuzz.httpfuzzer.results.toolbar.button.export.showMessageError")
                                    + "\n" + ex.getLocalizedMessage());
                    logger.error("Export Failed: " + ex);
                }
                // Delay the presentation of success message, to ensure all the data was
                // already flushed.
                if (success) {
                    JOptionPane.showMessageDialog(View.getSingleton().getMainFrame(), Constant.messages
                            .getString("fuzz.httpfuzzer.results.toolbar.button.export.showMessageSuccessful"));
                }
            }
        }
    }));
    toolbar.add(Box.createHorizontalGlue());
    toolbar.add(button);
    mainPanel = new JPanel(new BorderLayout());

    fuzzResultTable = new HttpFuzzerResultsTable(RESULTS_PANEL_NAME, EMPTY_RESULTS_MODEL);
    errorsTable = new HttpFuzzerErrorsTable(ERRORS_PANEL_NAME, EMPTY_ERRORS_MODEL);

    fuzzResultTableScrollPane = new JScrollPane();
    fuzzResultTableScrollPane.setViewportView(fuzzResultTable);

    errorsTableScrollPane = new JScrollPane();
    errorsTableScrollPane.setViewportView(errorsTable);

    mainPanel.add(fuzzResultTableScrollPane);

    add(toolbar, BorderLayout.PAGE_START);
    add(mainPanel, BorderLayout.CENTER);
}

From source file:org.zaproxy.zap.extension.quickstart.QuickStartPanel.java

private void initialize() {
    this.setIcon(new ImageIcon(BreakPanel.class.getResource("/resource/icon/16/147.png"))); // 'lightning' icon
    this.setDefaultAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q,
            Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() | Event.SHIFT_MASK, false));
    this.setMnemonic(Constant.messages.getChar("quickstart.panel.mnemonic"));
    this.setLayout(new BorderLayout());

    JPanel panelContent = new JPanel(new GridBagLayout());
    JScrollPane jScrollPane = new JScrollPane();
    jScrollPane.setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 11));
    jScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    jScrollPane.setViewportView(panelContent);

    this.add(jScrollPane, BorderLayout.CENTER);

    panelContent.setBackground(Color.white);
    panelContent.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));

    /*//from   w  ww . j  av  a  2  s  .  c  om
     * Layout:
     * Col            0                      1                      2                    3                       4
     * Row+----------------------+----------------------+----------------------+----------------------+----------------------+
     *  0 | Top welcome message                                                                       |    zap128x128.png    |
     *  1 | URL:                 | [ Url field                                                      ] |                      |
     *  2 |                      | [ Attack button ]    | [ Stop button ]      | padding              |                      |
     *  3 | Progress:            | Progress details                                                   |                      |
     *    | Bottom message                                                                                                   |
     *    | Show at start:       | [x]                  |                      |                      |                      |
     *    +----------------------+----------------------+----------------------+----------------------+----------------------+
     */

    panelContent.add(new JLabel(Constant.messages.getString("quickstart.panel.topmsg")),
            LayoutHelper.getGBC(0, 0, 4, 1.0D, new Insets(5, 5, 5, 5)));
    if (Constant.isDevBuild()) {
        panelContent.add(
                new JLabel(new ImageIcon(QuickStartPanel.class
                        .getResource("/org/zaproxy/zap/extension/quickstart/resources/zap128x128dark.png"))),
                LayoutHelper.getGBC(4, 0, 1, 0.0D, 0.0D, GridBagConstraints.NORTH));
    } else {
        panelContent.add(
                new JLabel(DisplayUtils.getScaledIcon(
                        new ImageIcon(SearchPanel.class.getResource("/resource/zap128x128.png")))),
                LayoutHelper.getGBC(4, 0, 1, 0.0D, 0.0D, GridBagConstraints.NORTH));
    }

    panelContent.add(new JLabel(Constant.messages.getString("quickstart.label.url")),
            LayoutHelper.getGBC(0, 1, 1, 0.0D, new Insets(5, 5, 5, 5)));

    JPanel urlSelectPanel = new JPanel(new GridBagLayout());
    JButton selectButton = new JButton(Constant.messages.getString("all.button.select"));
    selectButton.setIcon(
            DisplayUtils.getScaledIcon(new ImageIcon(View.class.getResource("/resource/icon/16/094.png")))); // Globe icon
    selectButton.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent e) {
            NodeSelectDialog nsd = new NodeSelectDialog(View.getSingleton().getMainFrame());
            SiteNode node = null;
            try {
                node = Model.getSingleton().getSession().getSiteTree()
                        .findNode(new URI(getUrlField().getText(), false));
            } catch (Exception e2) {
                // Ignore
            }
            node = nsd.showDialog(node);
            if (node != null && node.getHistoryReference() != null) {
                try {
                    getUrlField().setText(node.getHistoryReference().getURI().toString());
                } catch (Exception e1) {
                    // Ignore
                }
            }
        }
    });

    urlSelectPanel.add(this.getUrlField(), LayoutHelper.getGBC(0, 0, 1, 1.0D));
    urlSelectPanel.add(selectButton, LayoutHelper.getGBC(1, 0, 1, 0.0D));
    panelContent.add(urlSelectPanel, LayoutHelper.getGBC(1, 1, 3, 0.25D));

    panelContent.add(this.getAttackButton(), LayoutHelper.getGBC(1, 2, 1, 0.0D));
    panelContent.add(this.getStopButton(), LayoutHelper.getGBC(2, 2, 1, 0.0D));
    panelContent.add(new JLabel(""), LayoutHelper.getGBC(3, 2, 1, 0.75D, 0.0D)); // Padding to right of buttons

    progressLabel = new JLabel(
            Constant.messages.getString("quickstart.progress." + AttackThread.Progress.notstarted.name()));
    panelContent.add(new JLabel(Constant.messages.getString("quickstart.label.progress")),
            LayoutHelper.getGBC(0, 3, 1, 0.0D, new Insets(5, 5, 5, 5)));
    panelContent.add(this.progressLabel, LayoutHelper.getGBC(1, 3, 3, 0.0D));

    panelContent.add(new JLabel(Constant.messages.getString("quickstart.panel.proxymsg")),
            LayoutHelper.getGBC(0, 4, 5, 1.0D, new Insets(5, 5, 5, 5)));

    if (Control.getSingleton().getExtensionLoader().getExtension("ExtensionPlugNHack") != null) {
        // Plug-n-Hack extension has been installed - this makes configuration much easier :)
        if (DesktopUtils.canOpenUrlInBrowser()) {
            panelContent.add(new JLabel(Constant.messages.getString("quickstart.label.mitm")),
                    LayoutHelper.getGBC(0, 6, 1, 0.0D, new Insets(5, 5, 5, 5)));
            panelContent.add(this.getConfButton(), LayoutHelper.getGBC(1, 6, 1, 0.0D));

            panelContent.add(new JLabel(Constant.messages.getString("quickstart.label.mitmalt")),
                    LayoutHelper.getGBC(0, 7, 1, 0.0D, new Insets(5, 5, 5, 5)));
        } else {
            panelContent.add(new JLabel(Constant.messages.getString("quickstart.label.mitmurl")),
                    LayoutHelper.getGBC(0, 7, 1, 0.0D, new Insets(5, 5, 5, 5)));
        }
        panelContent.add(this.getConfField(), LayoutHelper.getGBC(1, 7, 3, 0.25D));

    } else {
        panelContent.add(new JLabel(Constant.messages.getString("quickstart.panel.helpmsg")),
                LayoutHelper.getGBC(0, 5, 5, 1.0D, new Insets(5, 5, 5, 5)));

    }

    panelContent.add(new JLabel(""), LayoutHelper.getGBC(0, 10, 4, 1.D, 1.0D)); // Padding at bottom

    this.setMode(Control.getSingleton().getMode());
}

From source file:org.zaproxy.zap.extension.requester.ManualHttpRequestEditorPanel.java

@Override
protected Component getManualSendPanel() {
    if (requestResponsePanel == null) {
        requestResponsePanel = new RequestResponsePanel(configurationKey, getRequestPanel(),
                getResponsePanel());/*w ww. ja v  a 2 s  .c o m*/

        if (helpKey != null) {
            JButton helpButton = new JButton();
            helpButton.setIcon(ExtensionHelp.getHelpIcon());
            helpButton.setToolTipText(Constant.messages.getString("help.dialog.button.tooltip"));
            helpButton.addActionListener(new java.awt.event.ActionListener() {
                @Override
                public void actionPerformed(java.awt.event.ActionEvent e) {
                    ExtensionHelp.showHelp(helpKey);
                }
            });
            requestResponsePanel.addToolbarButton(helpButton);
        }

        requestResponsePanel.addEndButton(getBtnSend());
        requestResponsePanel.addSeparator();

        requestResponsePanel.loadConfig();
    }
    return requestResponsePanel;
}