source: josm/src/org/openstreetmap/josm/gui/BugReportExceptionHandler.java@ 48

Last change on this file since 48 was 48, checked in by imi, 18 years ago
File size: 2.6 KB
Line 
1package org.openstreetmap.josm.gui;
2
3import java.awt.GridBagLayout;
4import java.io.BufferedReader;
5import java.io.File;
6import java.io.InputStreamReader;
7import java.io.PrintWriter;
8import java.io.StringWriter;
9import java.net.URL;
10import java.text.DateFormat;
11import java.text.SimpleDateFormat;
12import java.util.Date;
13
14import javax.swing.JLabel;
15import javax.swing.JOptionPane;
16import javax.swing.JPanel;
17import javax.swing.JScrollPane;
18import javax.swing.JTextArea;
19
20import org.openstreetmap.josm.Main;
21
22/**
23 * An exception handler, that ask the user to send a bug report.
24 *
25 * @author imi
26 */
27public 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}
Note: See TracBrowser for help on using the repository browser.