source: josm/src/org/openstreetmap/josm/tools/BugReportExceptionHandler.java@ 196

Last change on this file since 196 was 172, checked in by imi, 17 years ago
  • added support for Applet mode again (the basics)
  • added customizable toolbar
  • fixed shortcut for "New Empty Layer"
File size: 3.6 KB
Line 
1package org.openstreetmap.josm.tools;
2
3import static org.openstreetmap.josm.tools.I18n.tr;
4
5import java.awt.GridBagLayout;
6import java.io.BufferedReader;
7import java.io.File;
8import java.io.InputStreamReader;
9import java.io.PrintWriter;
10import java.io.StringWriter;
11import java.net.URL;
12import java.text.DateFormat;
13import java.text.SimpleDateFormat;
14import java.util.Date;
15
16import javax.swing.JLabel;
17import javax.swing.JOptionPane;
18import javax.swing.JPanel;
19import javax.swing.JScrollPane;
20import javax.swing.JTextArea;
21
22import org.openstreetmap.josm.Main;
23import org.openstreetmap.josm.plugins.PluginException;
24import org.openstreetmap.josm.plugins.PluginProxy;
25
26/**
27 * An exception handler, that ask the user to send a bug report.
28 *
29 * @author imi
30 */
31public final class BugReportExceptionHandler implements Thread.UncaughtExceptionHandler {
32
33 public void uncaughtException(Thread t, Throwable e) {
34 e.printStackTrace();
35 if (Main.parent != null) {
36 if (e instanceof OutOfMemoryError) {
37 JOptionPane.showMessageDialog(Main.parent, "You are out of memory. Strange things may happen.\nPlease restart JOSM and load smaller data sets.");
38 return;
39 }
40
41 if (e instanceof PluginException) {
42 PluginProxy plugin = ((PluginException)e).getPlugin();
43 if (plugin != null && !plugin.misbehaving) {
44 JOptionPane.showMessageDialog(Main.parent, tr("The plugin {0} throwed an exception: {1}\nIt may be outdated. Please contact the plugin's autor.\nThis message will not shown again until JOSM is restarted.", plugin.info.name, e.getMessage()));
45 plugin.misbehaving = true;
46 return;
47 }
48 }
49
50 Object[] options = new String[]{tr("Do nothing"), tr("Report Bug")};
51 int answer = JOptionPane.showOptionDialog(Main.parent, tr("An unexpected exception occoured.\n\n" +
52 "This is always a coding error. If you are running the latest\n" +
53 "version of JOSM, please consider be kind and file a bug report."),
54 tr("Unexpected Exception"), JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE,
55 null, options, options[0]);
56 if (answer == 1) {
57 try {
58 StringWriter stack = new StringWriter();
59 e.printStackTrace(new PrintWriter(stack));
60
61 URL revUrl = Main.class.getResource("/REVISION");
62 StringBuilder sb = new StringBuilder(tr("Please send this to josm@eigenheimstrasse.de\n\n"));
63 if (revUrl == null) {
64 sb.append("Development version. Unknown revision.");
65 File f = new File("org/openstreetmap/josm/Main.class");
66 if (!f.exists())
67 f = new File("bin/org/openstreetmap/josm/Main.class");
68 if (!f.exists())
69 f = new File("build/org/openstreetmap/josm/Main.class");
70 if (f.exists()) {
71 DateFormat sdf = SimpleDateFormat.getDateTimeInstance();
72 sb.append("\nMain.class build on "+sdf.format(new Date(f.lastModified())));
73 sb.append("\n");
74 }
75 } else {
76 BufferedReader in = new BufferedReader(new InputStreamReader(revUrl.openStream()));
77 for (String line = in.readLine(); line != null; line = in.readLine()) {
78 sb.append(line);
79 sb.append('\n');
80 }
81 }
82 sb.append("\n"+stack.getBuffer().toString());
83
84 JPanel p = new JPanel(new GridBagLayout());
85 p.add(new JLabel(tr("Please send an email with the following information to josm@eigenheimstrasse.de")), GBC.eop());
86
87 JTextArea info = new JTextArea(sb.toString(), 20, 60);
88 info.setCaretPosition(0);
89 info.setEditable(false);
90 p.add(new JScrollPane(info), GBC.eop());
91
92 JOptionPane.showMessageDialog(Main.parent, p);
93 } catch (Exception e1) {
94 e1.printStackTrace();
95 }
96 }
97 }
98 }
99}
Note: See TracBrowser for help on using the repository browser.