1 | package org.openstreetmap.josm.gui;
|
---|
2 |
|
---|
3 | import java.awt.GridBagLayout;
|
---|
4 | import java.io.BufferedReader;
|
---|
5 | import java.io.File;
|
---|
6 | import java.io.InputStreamReader;
|
---|
7 | import java.io.PrintWriter;
|
---|
8 | import java.io.StringWriter;
|
---|
9 | import java.net.URL;
|
---|
10 | import java.text.DateFormat;
|
---|
11 | import java.text.SimpleDateFormat;
|
---|
12 | import java.util.Date;
|
---|
13 |
|
---|
14 | import javax.swing.JLabel;
|
---|
15 | import javax.swing.JOptionPane;
|
---|
16 | import javax.swing.JPanel;
|
---|
17 | import javax.swing.JScrollPane;
|
---|
18 | import javax.swing.JTextArea;
|
---|
19 |
|
---|
20 | import org.openstreetmap.josm.Main;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * An exception handler, that ask the user to send a bug report.
|
---|
24 | *
|
---|
25 | * @author imi
|
---|
26 | */
|
---|
27 | public final class BugReportExceptionHandler implements Thread.UncaughtExceptionHandler {
|
---|
28 | public void uncaughtException(Thread t, Throwable e) {
|
---|
29 | e.printStackTrace();
|
---|
30 | if (Main.main != null) {
|
---|
31 | Object[] options = new String[]{"Do nothing", "Report Bug"};
|
---|
32 | int answer = JOptionPane.showOptionDialog(Main.main, "An unexpected exception occoured.\n\n" +
|
---|
33 | "This is always a coding error. If you are running the latest\n" +
|
---|
34 | "version of JOSM, please consider be kind and file a bug report.",
|
---|
35 | "Unexpected Exception", JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE,
|
---|
36 | null, options, options[0]);
|
---|
37 | if (answer == 1) {
|
---|
38 | try {
|
---|
39 | StringWriter stack = new StringWriter();
|
---|
40 | e.printStackTrace(new PrintWriter(stack));
|
---|
41 |
|
---|
42 | URL revUrl = Main.class.getResource("/REVISION");
|
---|
43 | StringBuilder sb = new StringBuilder("Please send this to josm@eigenheimstrasse.de\n\n");
|
---|
44 | if (revUrl == null) {
|
---|
45 | sb.append("Development version. Unknown revision.");
|
---|
46 | File f = new File("org/openstreetmap/josm/Main.class");
|
---|
47 | if (!f.exists())
|
---|
48 | f = new File("bin/org/openstreetmap/josm/Main.class");
|
---|
49 | if (f.exists()) {
|
---|
50 | DateFormat sdf = SimpleDateFormat.getDateTimeInstance();
|
---|
51 | sb.append("\nMain.class build on "+sdf.format(new Date(f.lastModified())));
|
---|
52 | sb.append("\n");
|
---|
53 | }
|
---|
54 | } else {
|
---|
55 | BufferedReader in = new BufferedReader(new InputStreamReader(revUrl.openStream()));
|
---|
56 | for (String line = in.readLine(); line != null; line = in.readLine()) {
|
---|
57 | sb.append(line);
|
---|
58 | sb.append('\n');
|
---|
59 | }
|
---|
60 | }
|
---|
61 | sb.append("\n"+stack.getBuffer().toString());
|
---|
62 |
|
---|
63 | JPanel p = new JPanel(new GridBagLayout());
|
---|
64 | p.add(new JLabel("Please send an email with the following information to josm@eigenheimstrasse.de"), GBC.eop());
|
---|
65 |
|
---|
66 | JTextArea info = new JTextArea(sb.toString(), 20, 60);
|
---|
67 | info.setCaretPosition(0);
|
---|
68 | info.setEditable(false);
|
---|
69 | p.add(new JScrollPane(info), GBC.eop());
|
---|
70 |
|
---|
71 | JOptionPane.showMessageDialog(Main.main, p);
|
---|
72 | } catch (Exception e1) {
|
---|
73 | e1.printStackTrace();
|
---|
74 | }
|
---|
75 | }
|
---|
76 | }
|
---|
77 | }
|
---|
78 | }
|
---|