Changeset 3478 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2010-08-29T14:25:18+02:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MapView.java
r3451 r3478 52 52 import org.openstreetmap.josm.gui.layer.markerlayer.PlayHeadMarker; 53 53 import org.openstreetmap.josm.tools.AudioPlayer; 54 import org.openstreetmap.josm.tools.BugReportExceptionHandler; 54 55 55 56 /** … … 443 444 */ 444 445 @Override public void paint(Graphics g) { 446 if (BugReportExceptionHandler.exceptionHandlingInProgress()) 447 return; 448 445 449 if (center == null) 446 450 return; // no data loaded yet. -
trunk/src/org/openstreetmap/josm/tools/BugReportExceptionHandler.java
r3098 r3478 33 33 public final class BugReportExceptionHandler implements Thread.UncaughtExceptionHandler { 34 34 35 private static boolean handlingInProgress = false; 36 35 37 public void uncaughtException(Thread t, Throwable e) { 36 38 handleException(e); … … 43 45 44 46 public static void handleException(Throwable e) { 45 e.printStackTrace(); 46 if (Main.parent != null) { 47 if (e instanceof OutOfMemoryError) { 48 // do not translate the string, as translation may raise an exception 49 JOptionPane.showMessageDialog(Main.parent, "JOSM is out of memory. " + 50 "Strange things may happen.\nPlease restart JOSM with the -Xmx###M option,\n" + 51 "where ### is the number of MB assigned to JOSM (e.g. 256).\n" + 52 "Currently, " + Runtime.getRuntime().maxMemory()/1024/1024 + " MB are available to JOSM.", 53 "Error", 54 JOptionPane.ERROR_MESSAGE 55 ); 56 return; 57 } 58 59 // Give the user a chance to deactivate the plugin which threw the exception (if it 60 // was thrown from a plugin) 61 // 62 PluginHandler.disablePluginAfterException(e); 63 64 // Then ask for submitting a bug report, for exceptions thrown from a plugin too 65 // 66 Object[] options = new String[]{tr("Do nothing"), tr("Report Bug")}; 67 int answer = JOptionPane.showOptionDialog( 68 Main.parent, 69 "<html>" 70 + tr("An unexpected exception occurred.<br>" + 71 "This is always a coding error. If you are running the latest<br>" + 72 "version of JOSM, please consider being kind and file a bug report." 73 ) 74 + "</html>", 75 tr("Unexpected Exception"), 76 JOptionPane.YES_NO_OPTION, 77 JOptionPane.ERROR_MESSAGE, 78 null, 79 options, options[0] 80 ); 81 if (answer != 1) return; 82 83 try { 84 final int maxlen = 7000; 85 StringWriter stack = new StringWriter(); 86 e.printStackTrace(new PrintWriter(stack)); 87 88 String text = ShowStatusReportAction.getReportHeader() 89 + stack.getBuffer().toString(); 90 String urltext = text.replaceAll("\r",""); /* strip useless return chars */ 91 if(urltext.length() > maxlen) 92 { 93 urltext = urltext.substring(0,maxlen); 94 int idx = urltext.lastIndexOf("\n"); 95 /* cut whole line when not loosing too much */ 96 if(maxlen-idx < 200) { 97 urltext = urltext.substring(0,idx+1); 98 } 99 urltext += "...<snip>...\n"; 47 if (handlingInProgress) 48 return; // we do not handle secondary exceptions, this gets too messy 49 handlingInProgress = true; 50 try { 51 e.printStackTrace(); 52 if (Main.parent != null) { 53 if (e instanceof OutOfMemoryError) { 54 // do not translate the string, as translation may raise an exception 55 JOptionPane.showMessageDialog(Main.parent, "JOSM is out of memory. " + 56 "Strange things may happen.\nPlease restart JOSM with the -Xmx###M option,\n" + 57 "where ### is the number of MB assigned to JOSM (e.g. 256).\n" + 58 "Currently, " + Runtime.getRuntime().maxMemory()/1024/1024 + " MB are available to JOSM.", 59 "Error", 60 JOptionPane.ERROR_MESSAGE 61 ); 62 return; 100 63 } 101 64 102 URL url = new URL("http://josm.openstreetmap.de/josmticket?" + 103 "data="+ 104 Base64.encode( 105 // To note that it came from this code 106 "keywords=template_report&" + 107 "description=" + java.net.URLEncoder.encode( 108 // Note: This doesn't use tr() intentionally, we want bug reports in English 109 "What steps will reproduce the problem?\n" 110 + " 1. \n" 111 + " 2. \n" 112 + " 3. \n" 113 + "\n" 114 + "What is the expected result?\n\n" 115 + "What happens instead?\n\n" 116 + "Please provide any additional information below. Attach a screenshot if\n" 117 + "possible.\n\n" 118 + "{{{\n" + urltext + "\n}}}\n", 119 "UTF-8"))); 65 // Give the user a chance to deactivate the plugin which threw the exception (if it 66 // was thrown from a plugin) 67 // 68 PluginHandler.disablePluginAfterException(e); 120 69 121 JPanel p = new JPanel(new GridBagLayout()); 122 p.add(new JMultilineLabel( 123 tr("You have encountered an error in JOSM. Before you file a bug report " + 124 "make sure you have updated to the latest version of JOSM here:")), GBC.eol()); 125 p.add(new UrlLabel("http://josm.openstreetmap.de/#Download"), GBC.eop().insets(8,0,0,0)); 126 p.add(new JMultilineLabel( 127 tr("You should also update your plugins. If neither of those help please " + 128 "file a bug report in our bugtracker using this link:")), GBC.eol()); 129 p.add(new UrlLabel(url.toString(), "http://josm.openstreetmap.de/josmticket?..."), GBC.eop().insets(8,0,0,0)); 130 p.add(new JMultilineLabel( 131 tr("There the error information provided below should already be " + 132 "filled in for you. Please include information on how to reproduce " + 133 "the error and try to supply as much detail as possible.")), GBC.eop()); 134 p.add(new JMultilineLabel( 135 tr("Alternatively, if that does not work you can manually fill in the information " + 136 "below at this URL:")), GBC.eol()); 137 p.add(new UrlLabel("http://josm.openstreetmap.de/newticket"), GBC.eop().insets(8,0,0,0)); 70 // Then ask for submitting a bug report, for exceptions thrown from a plugin too 71 // 72 Object[] options = new String[]{tr("Do nothing"), tr("Report Bug")}; 73 int answer = JOptionPane.showOptionDialog( 74 Main.parent, 75 "<html>" 76 + tr("An unexpected exception occurred.<br>" + 77 "This is always a coding error. If you are running the latest<br>" + 78 "version of JOSM, please consider being kind and file a bug report." 79 ) 80 + "</html>", 81 tr("Unexpected Exception"), 82 JOptionPane.YES_NO_OPTION, 83 JOptionPane.ERROR_MESSAGE, 84 null, 85 options, options[0] 86 ); 87 if (answer != 1) return; 88 138 89 try { 139 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(text), new ClipboardOwner(){ 140 public void lostOwnership(Clipboard clipboard, Transferable contents) {} 141 }); 142 p.add(new JLabel(tr("(The text has already been copied to your clipboard.)")), GBC.eop()); 90 final int maxlen = 7000; 91 StringWriter stack = new StringWriter(); 92 e.printStackTrace(new PrintWriter(stack)); 93 94 String text = ShowStatusReportAction.getReportHeader() 95 + stack.getBuffer().toString(); 96 String urltext = text.replaceAll("\r",""); /* strip useless return chars */ 97 if(urltext.length() > maxlen) 98 { 99 urltext = urltext.substring(0,maxlen); 100 int idx = urltext.lastIndexOf("\n"); 101 /* cut whole line when not loosing too much */ 102 if(maxlen-idx < 200) { 103 urltext = urltext.substring(0,idx+1); 104 } 105 urltext += "...<snip>...\n"; 106 } 107 108 URL url = new URL("http://josm.openstreetmap.de/josmticket?" + 109 "data="+ 110 Base64.encode( 111 // To note that it came from this code 112 "keywords=template_report&" + 113 "description=" + java.net.URLEncoder.encode( 114 // Note: This doesn't use tr() intentionally, we want bug reports in English 115 "What steps will reproduce the problem?\n" 116 + " 1. \n" 117 + " 2. \n" 118 + " 3. \n" 119 + "\n" 120 + "What is the expected result?\n\n" 121 + "What happens instead?\n\n" 122 + "Please provide any additional information below. Attach a screenshot if\n" 123 + "possible.\n\n" 124 + "{{{\n" + urltext + "\n}}}\n", 125 "UTF-8"))); 126 127 JPanel p = new JPanel(new GridBagLayout()); 128 p.add(new JMultilineLabel( 129 tr("You have encountered an error in JOSM. Before you file a bug report " + 130 "make sure you have updated to the latest version of JOSM here:")), GBC.eol()); 131 p.add(new UrlLabel("http://josm.openstreetmap.de/#Download"), GBC.eop().insets(8,0,0,0)); 132 p.add(new JMultilineLabel( 133 tr("You should also update your plugins. If neither of those help please " + 134 "file a bug report in our bugtracker using this link:")), GBC.eol()); 135 p.add(new UrlLabel(url.toString(), "http://josm.openstreetmap.de/josmticket?..."), GBC.eop().insets(8,0,0,0)); 136 p.add(new JMultilineLabel( 137 tr("There the error information provided below should already be " + 138 "filled in for you. Please include information on how to reproduce " + 139 "the error and try to supply as much detail as possible.")), GBC.eop()); 140 p.add(new JMultilineLabel( 141 tr("Alternatively, if that does not work you can manually fill in the information " + 142 "below at this URL:")), GBC.eol()); 143 p.add(new UrlLabel("http://josm.openstreetmap.de/newticket"), GBC.eop().insets(8,0,0,0)); 144 try { 145 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(text), new ClipboardOwner(){ 146 public void lostOwnership(Clipboard clipboard, Transferable contents) {} 147 }); 148 p.add(new JLabel(tr("(The text has already been copied to your clipboard.)")), GBC.eop()); 149 } 150 catch (RuntimeException x) {} 151 152 JTextArea info = new JTextArea(text, 20, 60); 153 info.setCaretPosition(0); 154 info.setEditable(false); 155 p.add(new JScrollPane(info), GBC.eop()); 156 157 for (Component c: p.getComponents()) { 158 if (c instanceof JMultilineLabel) { 159 ((JMultilineLabel)c).setMaxWidth(400); 160 } 161 } 162 163 JOptionPane.showMessageDialog(Main.parent, p, tr("You have encountered a bug in JOSM"), JOptionPane.ERROR_MESSAGE); 164 } catch (Exception e1) { 165 e1.printStackTrace(); 143 166 } 144 catch (RuntimeException x) {}145 146 JTextArea info = new JTextArea(text, 20, 60);147 info.setCaretPosition(0);148 info.setEditable(false);149 p.add(new JScrollPane(info), GBC.eop());150 151 for (Component c: p.getComponents()) {152 if (c instanceof JMultilineLabel) {153 ((JMultilineLabel)c).setMaxWidth(400);154 }155 }156 157 JOptionPane.showMessageDialog(Main.parent, p, tr("You have encountered a bug in JOSM"), JOptionPane.ERROR_MESSAGE);158 } catch (Exception e1) {159 e1.printStackTrace();160 167 } 168 } finally { 169 handlingInProgress = false; 161 170 } 162 171 } 172 public static boolean exceptionHandlingInProgress() { 173 return handlingInProgress; 174 } 163 175 }
Note:
See TracChangeset
for help on using the changeset viewer.