1 | package org.openstreetmap.josm.tools;
|
---|
2 |
|
---|
3 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
4 |
|
---|
5 | import java.awt.GridBagLayout;
|
---|
6 | import java.io.BufferedReader;
|
---|
7 | import java.io.File;
|
---|
8 | import java.io.InputStreamReader;
|
---|
9 | import java.io.PrintWriter;
|
---|
10 | import java.io.StringWriter;
|
---|
11 | import java.net.URL;
|
---|
12 | import java.text.DateFormat;
|
---|
13 | import java.text.SimpleDateFormat;
|
---|
14 | import java.util.Date;
|
---|
15 |
|
---|
16 | import javax.swing.JLabel;
|
---|
17 | import javax.swing.JOptionPane;
|
---|
18 | import javax.swing.JPanel;
|
---|
19 | import javax.swing.JScrollPane;
|
---|
20 | import javax.swing.JTextArea;
|
---|
21 |
|
---|
22 | import org.openstreetmap.josm.Main;
|
---|
23 | import org.openstreetmap.josm.plugins.PluginException;
|
---|
24 | import 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 | */
|
---|
31 | public 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 | }
|
---|