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

Last change on this file since 2474 was 2017, checked in by Gubaer, 15 years ago

removed OptionPaneUtil
cleanup of deprecated Layer API
cleanup of deprecated APIs in OsmPrimitive and Way
cleanup of imports

  • Property svn:eol-style set to native
File size: 4.1 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.tools;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.GridBagLayout;
7import java.awt.Toolkit;
8import java.awt.datatransfer.Clipboard;
9import java.awt.datatransfer.ClipboardOwner;
10import java.awt.datatransfer.StringSelection;
11import java.awt.datatransfer.Transferable;
12import java.io.PrintWriter;
13import java.io.StringWriter;
14
15import javax.swing.JLabel;
16import javax.swing.JOptionPane;
17import javax.swing.JPanel;
18import javax.swing.JScrollPane;
19import javax.swing.JTextArea;
20
21import org.openstreetmap.josm.Main;
22import org.openstreetmap.josm.actions.ShowStatusReportAction;
23import org.openstreetmap.josm.plugins.PluginHandler;
24
25/**
26 * An exception handler that asks the user to send a bug report.
27 *
28 * @author imi
29 */
30public final class BugReportExceptionHandler implements Thread.UncaughtExceptionHandler {
31
32 public void uncaughtException(Thread t, Throwable e) {
33 handleException(e);
34 }
35 public static void handleException(Throwable e) {
36 e.printStackTrace();
37 if (Main.parent != null) {
38 if (e instanceof OutOfMemoryError) {
39 // do not translate the string, as translation may raise an exception
40 JOptionPane.showMessageDialog(Main.parent, "JOSM is out of memory. " +
41 "Strange things may happen.\nPlease restart JOSM with the -Xmx###M option,\n" +
42 "where ### is the the number of MB assigned to JOSM (e.g. 256).\n" +
43 "Currently, " + Runtime.getRuntime().maxMemory()/1024/1024 + " MB are available to JOSM.",
44 tr("Error"),
45 JOptionPane.ERROR_MESSAGE
46 );
47 return;
48 }
49
50 if(PluginHandler.checkException(e))
51 return;
52
53 Object[] options = new String[]{tr("Do nothing"), tr("Report Bug")};
54 int answer = JOptionPane.showOptionDialog(Main.parent, tr("An unexpected exception occurred.\n\n" +
55 "This is always a coding error. If you are running the latest\n" +
56 "version of JOSM, please consider being kind and file a bug report."),
57 tr("Unexpected Exception"), JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE,null,
58 options, options[0]);
59 if (answer == 1) {
60 try {
61 StringWriter stack = new StringWriter();
62 e.printStackTrace(new PrintWriter(stack));
63
64 String text = ShowStatusReportAction.getReportHeader()
65 + stack.getBuffer().toString();
66
67 JPanel p = new JPanel(new GridBagLayout());
68 p.add(new JLabel("<html>" + tr("Please report a ticket at {0}","http://josm.openstreetmap.de/newticket") +
69 "<br>" + tr("Include your steps to get to the error (as detailed as possible)!") +
70 "<br>" + tr("Try updating to the newest version of JOSM and all plugins before reporting a bug.") +
71 "<br>" + tr("Be sure to include the following information:") + "</html>"), GBC.eol());
72 try {
73 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(text), new ClipboardOwner(){
74 public void lostOwnership(Clipboard clipboard, Transferable contents) {}
75 });
76 p.add(new JLabel(tr("(The text has already been copied to your clipboard.)")), GBC.eop());
77 }
78 catch (RuntimeException x) {}
79
80 JTextArea info = new JTextArea(text, 20, 60);
81 info.setCaretPosition(0);
82 info.setEditable(false);
83 p.add(new JScrollPane(info), GBC.eop());
84
85 JOptionPane.showMessageDialog(Main.parent, p, tr("Warning"), JOptionPane.WARNING_MESSAGE);
86 } catch (Exception e1) {
87 e1.printStackTrace();
88 }
89 }
90 }
91 }
92}
Note: See TracBrowser for help on using the repository browser.