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

Last change on this file since 2001 was 1882, checked in by jttt, 16 years ago

Fix BugReportExceptionHandler - buttons were reversed

  • 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.gui.OptionPaneUtil;
24import org.openstreetmap.josm.plugins.PluginHandler;
25
26/**
27 * An exception handler that asks 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 handleException(e);
35 }
36 public static void handleException(Throwable e) {
37 e.printStackTrace();
38 if (Main.parent != null) {
39 if (e instanceof OutOfMemoryError) {
40 // do not translate the string, as translation may raise an exception
41 OptionPaneUtil.showMessageDialog(Main.parent, "JOSM is out of memory. " +
42 "Strange things may happen.\nPlease restart JOSM with the -Xmx###M option,\n" +
43 "where ### is the the number of MB assigned to JOSM (e.g. 256).\n" +
44 "Currently, " + Runtime.getRuntime().maxMemory()/1024/1024 + " MB are available to JOSM.",
45 tr("Error"),
46 JOptionPane.ERROR_MESSAGE
47 );
48 return;
49 }
50
51 if(PluginHandler.checkException(e))
52 return;
53
54 Object[] options = new String[]{tr("Do nothing"), tr("Report Bug")};
55 int answer = OptionPaneUtil.showOptionDialog(Main.parent, tr("An unexpected exception occurred.\n\n" +
56 "This is always a coding error. If you are running the latest\n" +
57 "version of JOSM, please consider being kind and file a bug report."),
58 tr("Unexpected Exception"), JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE,
59 options, options[0]);
60 if (answer == 1) {
61 try {
62 StringWriter stack = new StringWriter();
63 e.printStackTrace(new PrintWriter(stack));
64
65 String text = ShowStatusReportAction.getReportHeader()
66 + stack.getBuffer().toString();
67
68 JPanel p = new JPanel(new GridBagLayout());
69 p.add(new JLabel("<html>" + tr("Please report a ticket at {0}","http://josm.openstreetmap.de/newticket") +
70 "<br>" + tr("Include your steps to get to the error (as detailed as possible)!") +
71 "<br>" + tr("Try updating to the newest version of JOSM and all plugins before reporting a bug.") +
72 "<br>" + tr("Be sure to include the following information:") + "</html>"), GBC.eol());
73 try {
74 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(text), new ClipboardOwner(){
75 public void lostOwnership(Clipboard clipboard, Transferable contents) {}
76 });
77 p.add(new JLabel(tr("(The text has already been copied to your clipboard.)")), GBC.eop());
78 }
79 catch (RuntimeException x) {}
80
81 JTextArea info = new JTextArea(text, 20, 60);
82 info.setCaretPosition(0);
83 info.setEditable(false);
84 p.add(new JScrollPane(info), GBC.eop());
85
86 OptionPaneUtil.showMessageDialog(Main.parent, p, tr("Warning"), JOptionPane.WARNING_MESSAGE);
87 } catch (Exception e1) {
88 e1.printStackTrace();
89 }
90 }
91 }
92 }
93}
Note: See TracBrowser for help on using the repository browser.