Changeset 10649 in josm
- Timestamp:
- 2016-07-26T21:34:35+02:00 (8 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/ExtendedDialog.java
r10616 r10649 6 6 import java.awt.Component; 7 7 import java.awt.Dimension; 8 import java.awt.Frame; 8 9 import java.awt.GridBagConstraints; 9 10 import java.awt.GridBagLayout; … … 146 147 147 148 public ExtendedDialog(Component parent, String title, String[] buttonTexts, boolean modal, boolean disposeOnClose) { 148 super( GuiHelper.getFrameForComponent(parent), title, modal ? ModalityType.DOCUMENT_MODAL : ModalityType.MODELESS);149 super(searchRealParent(parent), title, modal ? ModalityType.DOCUMENT_MODAL : ModalityType.MODELESS); 149 150 this.parent = parent; 150 151 this.modal = modal; … … 154 155 } 155 156 this.disposeOnClose = disposeOnClose; 157 } 158 159 private static Frame searchRealParent(Component parent) { 160 if (parent == null) { 161 return null; 162 } else { 163 return GuiHelper.getFrameForComponent(parent); 164 } 156 165 } 157 166 -
trunk/src/org/openstreetmap/josm/tools/GBC.java
r9231 r10649 97 97 98 98 /** 99 * Adds insets to this GBC. 100 * @param insets The insets in all directions. 101 * @return This constraint for chaining. 102 * @since 10649 103 */ 104 public GBC insets(int insets) { 105 insets(insets, insets, insets, insets); 106 return this; 107 } 108 109 /** 99 110 * Specifies how to distribute extra horizontal space. 100 111 * @param weightx Weight in horizontal direction -
trunk/src/org/openstreetmap/josm/tools/bugreport/BugReport.java
r10598 r10649 3 3 4 4 import java.io.PrintWriter; 5 import java.io.Serializable; 5 6 import java.io.StringWriter; 6 7 import java.util.concurrent.CopyOnWriteArrayList; … … 38 39 * @since 10285 39 40 */ 40 public final class BugReport { 41 public final class BugReport implements Serializable { 42 private static final long serialVersionUID = 1L; 43 41 44 private boolean includeStatusReport = true; 42 45 private boolean includeData = true; -
trunk/src/org/openstreetmap/josm/tools/bugreport/BugReportExceptionHandler.java
r10585 r10649 2 2 package org.openstreetmap.josm.tools.bugreport; 3 3 4 import static org.openstreetmap.josm.tools.I18n.tr;4 import java.awt.GraphicsEnvironment; 5 5 6 import java.awt.Component;7 import java.awt.GraphicsEnvironment;8 import java.awt.GridBagConstraints;9 import java.awt.GridBagLayout;10 import java.io.IOException;11 import java.io.PrintWriter;12 import java.io.StringWriter;13 14 import javax.swing.JButton;15 import javax.swing.JCheckBox;16 import javax.swing.JLabel;17 6 import javax.swing.JOptionPane; 18 import javax.swing.JPanel;19 7 import javax.swing.SwingUtilities; 20 8 21 9 import org.openstreetmap.josm.Main; 22 import org.openstreetmap.josm.actions.ReportBugAction;23 import org.openstreetmap.josm.actions.ShowStatusReportAction;24 import org.openstreetmap.josm.data.Version;25 import org.openstreetmap.josm.gui.ExtendedDialog;26 10 import org.openstreetmap.josm.gui.preferences.plugin.PluginPreference; 27 import org.openstreetmap.josm.gui.widgets.JMultilineLabel;28 import org.openstreetmap.josm.gui.widgets.UrlLabel;29 11 import org.openstreetmap.josm.plugins.PluginDownloadTask; 30 12 import org.openstreetmap.josm.plugins.PluginHandler; 31 import org.openstreetmap.josm.tools.GBC;32 import org.openstreetmap.josm.tools.WikiReader;33 13 34 14 /** … … 79 59 80 60 static void askForBugReport(final Throwable e) { 81 String[] buttonTexts = new String[] {tr("Do nothing"), tr("Report Bug")};82 String[] buttonIcons = new String[] {"cancel", "bug"};83 int defaultButtonIdx = 1;84 String message = tr("An unexpected exception occurred.<br>" +85 "This is always a coding error. If you are running the latest<br>" +86 "version of JOSM, please consider being kind and file a bug report."87 );88 // Check user is running current tested version, the error may already be fixed89 int josmVersion = Version.getInstance().getVersion();90 if (josmVersion != Version.JOSM_UNKNOWN_VERSION) {91 try {92 int latestVersion = Integer.parseInt(new WikiReader().93 read(Main.getJOSMWebsite()+"/wiki/TestedVersion?format=txt").trim());94 if (latestVersion > josmVersion) {95 buttonTexts = new String[] {tr("Do nothing"), tr("Update JOSM"), tr("Report Bug")};96 buttonIcons = new String[] {"cancel", "download", "bug"};97 defaultButtonIdx = 2;98 message = tr("An unexpected exception occurred. This is always a coding error.<br><br>" +99 "However, you are running an old version of JOSM ({0}),<br>" +100 "instead of using the current tested version (<b>{1}</b>).<br><br>"+101 "<b>Please update JOSM</b> before considering to file a bug report.",102 String.valueOf(josmVersion), String.valueOf(latestVersion));103 }104 } catch (IOException | NumberFormatException ex) {105 Main.warn(ex, "Unable to detect latest version of JOSM:");106 }107 }108 // Build panel109 JPanel pnl = new JPanel(new GridBagLayout());110 pnl.add(new JLabel("<html>" + message + "</html>"), GBC.eol());111 JCheckBox cbSuppress = null;112 if (exceptionCounter > 1) {113 cbSuppress = new JCheckBox(tr("Suppress further error dialogs for this session."));114 pnl.add(cbSuppress, GBC.eol());115 }116 61 if (GraphicsEnvironment.isHeadless()) { 117 62 return; 118 63 } 119 // Show dialog 120 ExtendedDialog ed = new ExtendedDialog(Main.parent, tr("Unexpected Exception"), buttonTexts); 121 ed.setButtonIcons(buttonIcons); 122 ed.setIcon(JOptionPane.ERROR_MESSAGE); 123 ed.setCancelButton(1); 124 ed.setDefaultButton(defaultButtonIdx); 125 ed.setContent(pnl); 126 ed.setFocusOnDefaultButton(true); 127 ed.showDialog(); 128 if (cbSuppress != null && cbSuppress.isSelected()) { 129 suppressExceptionDialogs = true; 130 } 131 if (ed.getValue() <= 1) { 132 // "Do nothing" 133 return; 134 } else if (ed.getValue() < buttonTexts.length) { 135 // "Update JOSM" 136 try { 137 Main.platform.openUrl(Main.getJOSMWebsite()); 138 } catch (IOException ex) { 139 Main.warn(ex, "Unable to access JOSM website:"); 140 } 141 } else { 142 // "Report bug" 143 try { 144 JPanel p = buildPanel(e); 145 JOptionPane.showMessageDialog(Main.parent, p, tr("You have encountered a bug in JOSM"), JOptionPane.ERROR_MESSAGE); 146 } catch (RuntimeException ex) { 147 Main.error(ex); 148 } 149 } 64 BugReport report = new BugReport(BugReport.intercept(e)); 65 BugReportDialog dialog = new BugReportDialog(report); 66 dialog.setShowSuppress(exceptionCounter > 1); 67 dialog.setVisible(true); 68 suppressExceptionDialogs = dialog.shouldSuppressFurtherErrors(); 150 69 } 151 70 … … 196 115 } 197 116 198 static JPanel buildPanel(final Throwable e) {199 DebugTextDisplay textarea;200 if (e instanceof ReportedException) {201 // Temporary!202 textarea = new DebugTextDisplay(new BugReport((ReportedException) e));203 } else {204 StringWriter stack = new StringWriter();205 e.printStackTrace(new PrintWriter(stack));206 textarea = new DebugTextDisplay(ShowStatusReportAction.getReportHeader() + stack.getBuffer().toString());207 }208 209 JPanel p = new JPanel(new GridBagLayout());210 p.add(new JMultilineLabel(211 tr("You have encountered an error in JOSM. Before you file a bug report " +212 "make sure you have updated to the latest version of JOSM here:")),213 GBC.eol().fill(GridBagConstraints.HORIZONTAL));214 p.add(new UrlLabel(Main.getJOSMWebsite(), 2), GBC.eop().insets(8, 0, 0, 0));215 p.add(new JMultilineLabel(216 tr("You should also update your plugins. If neither of those help please " +217 "file a bug report in our bugtracker using this link:")),218 GBC.eol().fill(GridBagConstraints.HORIZONTAL));219 p.add(new JButton(new ReportBugAction(textarea.getCodeText())), GBC.eop().insets(8, 0, 0, 0));220 p.add(new JMultilineLabel(221 tr("There the error information provided below should already be " +222 "filled in for you. Please include information on how to reproduce " +223 "the error and try to supply as much detail as possible.")),224 GBC.eop().fill(GridBagConstraints.HORIZONTAL));225 p.add(new JMultilineLabel(226 tr("Alternatively, if that does not work you can manually fill in the information " +227 "below at this URL:")), GBC.eol().fill(GridBagConstraints.HORIZONTAL));228 p.add(new UrlLabel(Main.getJOSMWebsite()+"/newticket", 2), GBC.eop().insets(8, 0, 0, 0));229 230 if (textarea.copyToClippboard()) {231 p.add(new JLabel(tr("(The text has already been copied to your clipboard.)")),232 GBC.eop().fill(GridBagConstraints.HORIZONTAL));233 }234 235 p.add(textarea, GBC.eop().fill());236 237 for (Component c: p.getComponents()) {238 if (c instanceof JMultilineLabel) {239 ((JMultilineLabel) c).setMaxWidth(400);240 }241 }242 return p;243 }244 245 117 /** 246 118 * Determines if an exception is currently being handled -
trunk/src/org/openstreetmap/josm/tools/bugreport/BugReportSettingsPanel.java
r10597 r10649 26 26 add(statusReport); 27 27 28 JCheckBox data = new JCheckBox(tr("Include information about the data that was workedon."));28 JCheckBox data = new JCheckBox(tr("Include information about the data you were working on.")); 29 29 data.setSelected(report.isIncludeData()); 30 30 data.addChangeListener(e -> report.setIncludeData(data.isSelected())); -
trunk/test/unit/org/openstreetmap/josm/tools/bugreport/BugReportExceptionHandlerTest.java
r10067 r10649 3 3 4 4 import static org.junit.Assert.assertFalse; 5 import static org.junit.Assert.assertNotNull;6 5 7 6 import org.junit.Before; … … 23 22 24 23 /** 25 * Unit test for {@link BugReportExceptionHandler#buildPanel} method.26 */27 @Test28 public void testBuildPanel() {29 assertNotNull(BugReportExceptionHandler.buildPanel(new Exception("testBuildPanel")));30 }31 32 /**33 24 * Unit test for {@link BugReportExceptionHandler.BugReporterThread#askForBugReport} method. 34 25 */
Note:
See TracChangeset
for help on using the changeset viewer.