- Timestamp:
- 2017-09-08T21:10:14+02:00 (8 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 4 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r12777 r12790 149 149 import org.openstreetmap.josm.tools.bugreport.BugReportExceptionHandler; 150 150 import org.openstreetmap.josm.tools.bugreport.BugReportQueue; 151 import org.openstreetmap.josm.tools.bugreport.BugReportSender; 151 152 import org.xml.sax.SAXException; 152 153 … … 778 779 if (!GraphicsEnvironment.isHeadless()) { 779 780 BugReportQueue.getInstance().setBugReportHandler(BugReportDialog::showFor); 781 BugReportSender.setBugReportSendingHandler(BugReportDialog.bugReportSendingHandler); 780 782 } 781 783 -
trunk/src/org/openstreetmap/josm/gui/bugreport/BugReportDialog.java
r12649 r12790 19 19 import javax.swing.JOptionPane; 20 20 import javax.swing.JPanel; 21 import javax.swing.SwingUtilities; 21 22 import javax.swing.UIManager; 22 23 … … 32 33 import org.openstreetmap.josm.tools.ImageProvider; 33 34 import org.openstreetmap.josm.tools.InputMapUtils; 35 import org.openstreetmap.josm.tools.OpenBrowser; 34 36 import org.openstreetmap.josm.tools.bugreport.BugReport; 35 37 import org.openstreetmap.josm.tools.bugreport.BugReportQueue.SuppressionMode; 36 38 import org.openstreetmap.josm.tools.bugreport.BugReportSender; 39 import org.openstreetmap.josm.tools.bugreport.BugReportSender.BugReportSendingHandler; 37 40 import org.openstreetmap.josm.tools.bugreport.ReportedException; 38 41 … … 52 55 private JCheckBox cbSuppressSingle; 53 56 private JCheckBox cbSuppressAll; 57 58 /** 59 * Default bug report callback that opens the bug report form in user browser 60 * and displays a dialog in case of error. 61 * @since 12790 62 */ 63 public static final BugReportSendingHandler bugReportSendingHandler = new BugReportSendingHandler() { 64 @Override 65 public String sendingBugReport(String bugUrl, String statusText) { 66 return OpenBrowser.displayUrl(bugUrl); 67 } 68 69 @Override 70 public void failed(String errorMessage, String statusText) { 71 SwingUtilities.invokeLater(() -> { 72 JPanel errorPanel = new JPanel(new GridBagLayout()); 73 errorPanel.add(new JMultilineLabel( 74 tr("Opening the bug report failed. Please report manually using this website:")), 75 GBC.eol().fill(GridBagConstraints.HORIZONTAL)); 76 errorPanel.add(new UrlLabel(Main.getJOSMWebsite() + "/newticket", 2), GBC.eop().insets(8, 0, 0, 0)); 77 errorPanel.add(new DebugTextDisplay(statusText)); 78 79 JOptionPane.showMessageDialog(Main.parent, errorPanel, tr("You have encountered a bug in JOSM"), 80 JOptionPane.ERROR_MESSAGE); 81 }); 82 } 83 }; 54 84 55 85 /** -
trunk/src/org/openstreetmap/josm/tools/bugreport/BugReportQueue.java
r12770 r12790 4 4 import java.util.ArrayList; 5 5 import java.util.LinkedList; 6 import java.util.Objects; 6 7 import java.util.concurrent.CopyOnWriteArrayList; 7 8 import java.util.function.Predicate; … … 18 19 private static final BugReportQueue INSTANCE = new BugReportQueue(); 19 20 21 /** 22 * The fallback bug report handler if none is set. Prints the stacktrace on standard output. 23 * @since 12770 24 */ 20 25 public static final BugReportHandler FALLBACK_BUGREPORT_HANDLER = (e, index) -> { 21 26 e.printStackTrace(); … … 142 147 } 143 148 149 /** 150 * Sets the {@link BugReportHandler} for this queue. 151 * @param bugReportHandler the handler in charge of displaying the bug report. Must not be null 152 * @since 12770 153 */ 144 154 public void setBugReportHandler(BugReportHandler bugReportHandler) { 145 this.bugReportHandler = bugReportHandler; 155 this.bugReportHandler = Objects.requireNonNull(bugReportHandler, "bugReportHandler"); 146 156 } 147 157 -
trunk/src/org/openstreetmap/josm/tools/bugreport/BugReportSender.java
r12649 r12790 2 2 package org.openstreetmap.josm.tools.bugreport; 3 3 4 import static org.openstreetmap.josm.tools.I18n.tr;5 6 import java.awt.GridBagConstraints;7 import java.awt.GridBagLayout;8 4 import java.io.IOException; 9 5 import java.io.InputStream; … … 12 8 import java.nio.charset.StandardCharsets; 13 9 import java.util.Base64; 10 import java.util.Objects; 14 11 15 import javax.swing.JOptionPane;16 import javax.swing.JPanel;17 import javax.swing.SwingUtilities;18 12 import javax.xml.parsers.ParserConfigurationException; 19 13 import javax.xml.xpath.XPath; … … 23 17 24 18 import org.openstreetmap.josm.Main; 25 import org.openstreetmap.josm.gui.bugreport.DebugTextDisplay;26 import org.openstreetmap.josm.gui.widgets.JMultilineLabel;27 import org.openstreetmap.josm.gui.widgets.UrlLabel;28 import org.openstreetmap.josm.tools.GBC;29 19 import org.openstreetmap.josm.tools.HttpClient; 30 20 import org.openstreetmap.josm.tools.HttpClient.Response; … … 45 35 public class BugReportSender extends Thread { 46 36 37 /** 38 * Called during bug submission to JOSM bugtracker. Completes the bug report submission and handles errors. 39 * @since 12790 40 */ 41 public interface BugReportSendingHandler { 42 /** 43 * Called when a bug is sent to JOSM bugtracker. 44 * @param bugUrl URL to visit to effectively submit the bug report to JOSM website 45 * @param statusText the status text being sent 46 * @return <code>null</code> for success or a string in case of an error 47 */ 48 String sendingBugReport(String bugUrl, String statusText); 49 50 /** 51 * Called when a bug failed to be sent to JOSM bugtracker. 52 * @param errorMessage the error message 53 * @param statusText the status text being sent 54 */ 55 void failed(String errorMessage, String statusText); 56 } 57 58 /** 59 * The fallback bug report sending handler if none is set. 60 * @since xxx 61 */ 62 public static final BugReportSendingHandler FALLBACK_BUGREPORT_SENDING_HANDLER = new BugReportSendingHandler() { 63 @Override 64 public String sendingBugReport(String bugUrl, String statusText) { 65 return OpenBrowser.displayUrl(bugUrl); 66 } 67 68 @Override 69 public void failed(String errorMessage, String statusText) { 70 Logging.error("Unable to send bug report: {0}\n{1}", errorMessage, statusText); 71 } 72 }; 73 74 private static BugReportSendingHandler handler = FALLBACK_BUGREPORT_SENDING_HANDLER; 75 47 76 private final String statusText; 48 77 private String errorMessage; … … 62 91 // first, send the debug text using post. 63 92 String debugTextPasteId = pasteDebugText(); 93 String bugUrl = getJOSMTicketURL() + "?pdata_stored=" + debugTextPasteId; 64 94 65 // then open a browser to display the pasted text.66 String openBrowserError = OpenBrowser.displayUrl(getJOSMTicketURL() + "?pdata_stored=" + debugTextPasteId);67 if ( openBrowserError!= null) {68 Logging.warn( openBrowserError);69 failed( openBrowserError);95 // then notify handler 96 errorMessage = handler.sendingBugReport(bugUrl, statusText); 97 if (errorMessage != null) { 98 Logging.warn(errorMessage); 99 handler.failed(errorMessage, statusText); 70 100 } 71 101 } catch (BugReportSenderException e) { 72 102 Logging.warn(e); 73 failed(e.getMessage()); 103 errorMessage = e.getMessage(); 104 handler.failed(errorMessage, statusText); 74 105 } 75 106 } … … 128 159 } 129 160 130 private void failed(String string) {131 errorMessage = string;132 SwingUtilities.invokeLater(() -> {133 JPanel errorPanel = new JPanel(new GridBagLayout());134 errorPanel.add(new JMultilineLabel(135 tr("Opening the bug report failed. Please report manually using this website:")),136 GBC.eol().fill(GridBagConstraints.HORIZONTAL));137 errorPanel.add(new UrlLabel(Main.getJOSMWebsite() + "/newticket", 2), GBC.eop().insets(8, 0, 0, 0));138 errorPanel.add(new DebugTextDisplay(statusText));139 140 JOptionPane.showMessageDialog(Main.parent, errorPanel, tr("You have encountered a bug in JOSM"),141 JOptionPane.ERROR_MESSAGE);142 });143 }144 145 161 /** 146 162 * Returns the error message that could have occured during bug sending. … … 171 187 return sender; 172 188 } 189 190 /** 191 * Sets the {@link BugReportSendingHandler} for bug report sender. 192 * @param bugReportSendingHandler the handler in charge of completing the bug report submission and handle errors. Must not be null 193 * @since 12790 194 */ 195 public static void setBugReportSendingHandler(BugReportSendingHandler bugReportSendingHandler) { 196 handler = Objects.requireNonNull(bugReportSendingHandler, "bugReportSendingHandler"); 197 } 173 198 } -
trunk/test/unit/org/openstreetmap/josm/gui/bugreport/BugReportSettingsPanelTest.java
r12789 r12790 1 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm. tools.bugreport;2 package org.openstreetmap.josm.gui.bugreport; 3 3 4 4 import static org.junit.Assert.assertNotNull; … … 6 6 import org.junit.Rule; 7 7 import org.junit.Test; 8 import org.openstreetmap.josm.gui.bugreport.BugReportSettingsPanel;9 8 import org.openstreetmap.josm.testutils.JOSMTestRules; 9 import org.openstreetmap.josm.tools.bugreport.BugReport; 10 10 11 11 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -
trunk/test/unit/org/openstreetmap/josm/gui/bugreport/DebugTextDisplayTest.java
r12789 r12790 1 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm. tools.bugreport;2 package org.openstreetmap.josm.gui.bugreport; 3 3 4 4 import static org.junit.Assert.assertEquals; … … 6 6 import org.junit.Rule; 7 7 import org.junit.Test; 8 import org.openstreetmap.josm.gui.bugreport.DebugTextDisplay;9 8 import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils; 10 9 import org.openstreetmap.josm.testutils.JOSMTestRules;
Note:
See TracChangeset
for help on using the changeset viewer.