001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.bugreport;
003
004import static org.openstreetmap.josm.tools.I18n.tr;
005
006import java.awt.GridBagConstraints;
007import java.awt.GridBagLayout;
008
009import javax.swing.JOptionPane;
010import javax.swing.JPanel;
011import javax.swing.SwingUtilities;
012
013import org.openstreetmap.josm.gui.MainApplication;
014import org.openstreetmap.josm.gui.widgets.JMultilineLabel;
015import org.openstreetmap.josm.gui.widgets.UrlLabel;
016import org.openstreetmap.josm.spi.preferences.Config;
017import org.openstreetmap.josm.tools.GBC;
018import org.openstreetmap.josm.tools.OpenBrowser;
019import org.openstreetmap.josm.tools.bugreport.BugReportSender.BugReportSendingHandler;
020
021/**
022 * Default bug report callback that opens the bug report form in user browser
023 * and displays a dialog in case of error.
024 * @since 14176
025 */
026public class DefaultBugReportSendingHandler implements BugReportSendingHandler {
027
028    @Override
029    public String sendingBugReport(String bugUrl, String statusText) {
030        return OpenBrowser.displayUrl(bugUrl);
031    }
032
033    @Override
034    public void failed(String errorMessage, String statusText) {
035        SwingUtilities.invokeLater(() -> {
036            JPanel errorPanel = new JPanel(new GridBagLayout());
037            errorPanel.add(new JMultilineLabel(
038                    tr("Opening the bug report failed. Please report manually using this website:")),
039                    GBC.eol().fill(GridBagConstraints.HORIZONTAL));
040            errorPanel.add(new UrlLabel(Config.getUrls().getJOSMWebsite() + "/newticket", 2), GBC.eop().insets(8, 0, 0, 0));
041            errorPanel.add(new DebugTextDisplay(statusText));
042
043            JOptionPane.showMessageDialog(MainApplication.getMainFrame(), errorPanel, tr("You have encountered a bug in JOSM"),
044                    JOptionPane.ERROR_MESSAGE);
045        });
046    }
047}