X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fnet%2Fsf%2Fopenrocket%2Fgui%2Fdialogs%2FBugReportDialog.java;h=9966dbe50ada1695b4d6f331f5e32d7d6794efcf;hb=8e4a8571c20ba96164ddd8a68226d43ccd549d21;hp=b58d48a356f371360205ac76190781489c307adf;hpb=dfc10c016c5f1bb4b7714dff414562f2f32e2866;p=debian%2Fopenrocket diff --git a/src/net/sf/openrocket/gui/dialogs/BugReportDialog.java b/src/net/sf/openrocket/gui/dialogs/BugReportDialog.java index b58d48a3..9966dbe5 100644 --- a/src/net/sf/openrocket/gui/dialogs/BugReportDialog.java +++ b/src/net/sf/openrocket/gui/dialogs/BugReportDialog.java @@ -7,15 +7,14 @@ import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; -import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.StringWriter; import java.io.UnsupportedEncodingException; -import java.net.HttpURLConnection; import java.net.URI; import java.net.URISyntaxException; -import java.net.URL; import java.net.URLEncoder; +import java.util.List; +import java.util.Locale; import java.util.SortedSet; import java.util.TreeSet; @@ -28,8 +27,14 @@ import javax.swing.JScrollPane; import javax.swing.JTextArea; import net.miginfocom.swing.MigLayout; -import net.sf.openrocket.gui.components.ResizeLabel; +import net.sf.openrocket.communication.BugReporter; import net.sf.openrocket.gui.components.SelectableLabel; +import net.sf.openrocket.gui.components.StyledLabel; +import net.sf.openrocket.l10n.Translator; +import net.sf.openrocket.logging.LogLevelBufferLogger; +import net.sf.openrocket.logging.LogLine; +import net.sf.openrocket.startup.Application; +import net.sf.openrocket.util.BugException; import net.sf.openrocket.util.GUIUtil; import net.sf.openrocket.util.JarUtil; import net.sf.openrocket.util.Prefs; @@ -37,18 +42,12 @@ import net.sf.openrocket.util.Prefs; public class BugReportDialog extends JDialog { private static final String REPORT_EMAIL = "openrocket-bugs@lists.sourceforge.net"; - - private static final String REPORT_URL = - "http://openrocket.sourceforge.net/actions/reportbug"; + private static final Translator trans = Application.getTranslator(); - private static final String REPORT_VERSION_PARAM = "version"; - private static final String REPORT_PARAM = "content"; - private static final int REPORT_RESPONSE_CODE = HttpURLConnection.HTTP_ACCEPTED; - private static final int REPORT_TIMEOUT = 10000; // in milliseconds - public BugReportDialog(Window parent, String labelText, String message) { - super(parent, "Bug report", Dialog.ModalityType.APPLICATION_MODAL); + //// Bug report + super(parent, trans.get("bugreport.dlg.title"), Dialog.ModalityType.APPLICATION_MODAL); JPanel panel = new JPanel(new MigLayout("fill")); @@ -58,15 +57,17 @@ public class BugReportDialog extends JDialog { d.width = 100000; label.setMaximumSize(d); panel.add(label, "gapleft para, wrap para"); - - label = new JLabel("If connected to the Internet, you can simply click " + - "Send bug report."); + + //// If connected to the Internet, you can simply click + //// Send bug report. + label = new JLabel(trans.get("bugreport.dlg.connectedInternet")); d = label.getPreferredSize(); d.width = 100000; label.setMaximumSize(d); panel.add(label, "gapleft para, wrap"); - panel.add(new JLabel("Otherwise, send the text below to the address: "), + //// Otherwise, send the text below to the address: + panel.add(new JLabel(trans.get("bugreport.dlg.otherwise") +" "), "gapleft para, split 2, gapright rel"); panel.add(new SelectableLabel(REPORT_EMAIL), "growx, wrap para"); @@ -75,15 +76,13 @@ public class BugReportDialog extends JDialog { textArea.setEditable(true); panel.add(new JScrollPane(textArea), "grow, wrap"); + + panel.add(new StyledLabel(trans.get("bugreport.lbl.Theinformation"), -1), "wrap para"); - panel.add(new ResizeLabel("The information above may be included in a public " + - "bug report. Make sure it does not contain any sensitive information you " + - "do not want to be made public.", -1), "wrap para"); - - - - //// Close button - JButton close = new JButton("Close"); + + + ////Close button + JButton close = new JButton(trans.get("dlg.but.close")); close.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -92,45 +91,55 @@ public class BugReportDialog extends JDialog { }); panel.add(close, "right, sizegroup buttons, split"); - + //// Mail button -// if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Action.MAIL)) { -// JButton mail = new JButton("Open email"); -// mail.setToolTipText("Open email client with the suitable email ready."); -// mail.addActionListener(new ActionListener() { -// @Override -// public void actionPerformed(ActionEvent e) { -// String text = textArea.getText(); -// openEmail(text); -// } -// }); -// panel.add(mail, "right, sizegroup buttons"); -// } + // if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Action.MAIL)) { + // JButton mail = new JButton("Open email"); + // mail.setToolTipText("Open email client with the suitable email ready."); + // mail.addActionListener(new ActionListener() { + // @Override + // public void actionPerformed(ActionEvent e) { + // String text = textArea.getText(); + // openEmail(text); + // } + // }); + // panel.add(mail, "right, sizegroup buttons"); + // } - - //// Send button - JButton send = new JButton("Send bug report"); - send.setToolTipText("Automatically send the bug report to the OpenRocket developers."); + + //// Send bug report button + JButton send = new JButton(trans.get("bugreport.dlg.but.Sendbugreport")); + //// Automatically send the bug report to the OpenRocket developers. + send.setToolTipText(trans.get("bugreport.dlg.but.Sendbugreport.Ttip")); send.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String text = textArea.getText(); try { - sendReport(text); + BugReporter.sendBugReport(text); + // Success if we came here - JOptionPane.showMessageDialog(BugReportDialog.this, + //bugreport.dlg.successmsg + /*JOptionPane.showMessageDialog(BugReportDialog.this, new Object[] { "Bug report successfully sent.", - "Thank you for helping make OpenRocket better!" }, - "Bug report sent", JOptionPane.INFORMATION_MESSAGE); + "Thank you for helping make OpenRocket better!" }, + "Bug report sent", JOptionPane.INFORMATION_MESSAGE);*/ + JOptionPane.showMessageDialog(BugReportDialog.this, + new Object[] { trans.get("bugreport.dlg.successmsg1"), + trans.get("bugreport.dlg.successmsg2") }, + trans.get("bugreport.dlg.successmsg3"), JOptionPane.INFORMATION_MESSAGE); } catch (Exception ex) { // Sending the message failed. JOptionPane.showMessageDialog(BugReportDialog.this, - new Object[] { "OpenRocket was unable to send the bug report:", - ex.getClass().getSimpleName() + ": " + ex.getMessage(), " ", - "Please send the report manually to " + REPORT_EMAIL }, - "Error sending report", JOptionPane.ERROR_MESSAGE); + //// OpenRocket was unable to send the bug report: + new Object[] { trans.get("bugreport.dlg.failedmsg1"), + ex.getClass().getSimpleName() + ": " + ex.getMessage(), " ", + //// Please send the report manually to + trans.get("bugreport.dlg.failedmsg2") +" " + REPORT_EMAIL }, + //// Error sending report + trans.get("bugreport.dlg.failedmsg3"), JOptionPane.ERROR_MESSAGE); } } }); @@ -142,12 +151,12 @@ public class BugReportDialog extends JDialog { this.pack(); this.pack(); this.setLocationRelativeTo(parent); - GUIUtil.installEscapeCloseOperation(this); - GUIUtil.setDefaultButton(send); + + GUIUtil.setDisposableDialogOptions(this, send); } - + /** * Show a general bug report dialog allowing the user to input information about * the bug they encountered. @@ -155,7 +164,7 @@ public class BugReportDialog extends JDialog { * @param parent the parent window (may be null). */ public static void showBugReportDialog(Window parent) { - + StringBuilder sb = new StringBuilder(); sb.append("---------- Bug report ----------\n"); @@ -174,7 +183,7 @@ public class BugReportDialog extends JDialog { sb.append('\n'); sb.append("Include your email address (optional; it helps if we can " + - "contact you in case we need additional information):\n"); + "contact you in case we need additional information):\n"); sb.append('\n'); sb.append('\n'); sb.append('\n'); @@ -183,15 +192,15 @@ public class BugReportDialog extends JDialog { sb.append("(Do not modify anything below this line.)\n"); sb.append("---------- System information ----------\n"); addSystemInformation(sb); - sb.append("---------- End of information ----------\n"); + sb.append("---------- Error log ----------\n"); + addErrorLog(sb); + sb.append("---------- End of bug report ----------\n"); sb.append('\n'); - BugReportDialog reportDialog = - new BugReportDialog(parent, - "You can report a bug in OpenRocket by filling in and submitting " + - "the form below.
" + - "You can also report bugs and include attachments on the project " + - "web site.", sb.toString()); + BugReportDialog reportDialog = + new BugReportDialog(parent, + //// You can report a bug in OpenRocket by filling in and submitting the form below.
You can also report bugs and include attachments on the project web site. + trans.get("bugreport.reportDialog.txt"), sb.toString()); reportDialog.setVisible(true); } @@ -204,7 +213,6 @@ public class BugReportDialog extends JDialog { * @param e the exception. */ public static void showExceptionDialog(Window parent, Thread t, Throwable e) { - StringBuilder sb = new StringBuilder(); sb.append("---------- Bug report ----------\n"); @@ -223,7 +231,7 @@ public class BugReportDialog extends JDialog { sb.append('\n'); sb.append('\n'); sb.append('\n'); - + sb.append("(Do not modify anything below this line.)\n"); sb.append("---------- Exception stack trace ----------\n"); StringWriter sw = new StringWriter(); @@ -232,7 +240,7 @@ public class BugReportDialog extends JDialog { sb.append(sw.getBuffer()); sb.append('\n'); - + sb.append("---------- Thread information ----------\n"); if (t == null) { sb.append("Thread is not specified."); @@ -241,15 +249,17 @@ public class BugReportDialog extends JDialog { } sb.append('\n'); - + sb.append("---------- System information ----------\n"); addSystemInformation(sb); - sb.append("---------- End of information ----------\n"); + sb.append("---------- Error log ----------\n"); + addErrorLog(sb); + sb.append("---------- End of bug report ----------\n"); sb.append('\n'); - BugReportDialog reportDialog = - new BugReportDialog(parent, "Please include a short description about " + - "what you were doing when the exception occurred.", sb.toString()); + BugReportDialog reportDialog = + //// Please include a short description about what you were doing when the exception occurred. + new BugReportDialog(parent, trans.get("bugreport.reportDialog.txt2"), sb.toString()); reportDialog.setVisible(true); } @@ -258,20 +268,21 @@ public class BugReportDialog extends JDialog { sb.append("OpenRocket version: " + Prefs.getVersion() + "\n"); sb.append("OpenRocket source: " + Prefs.getBuildSource() + "\n"); sb.append("OpenRocket location: " + JarUtil.getCurrentJarFile() + "\n"); + sb.append("Current default locale: " + Locale.getDefault() + "\n"); sb.append("System properties:\n"); - + // Sort the keys SortedSet keys = new TreeSet(); - for (Object key: System.getProperties().keySet()) { - keys.add((String)key); + for (Object key : System.getProperties().keySet()) { + keys.add((String) key); } - for (String key: keys) { + for (String key : keys) { String value = System.getProperty(key); sb.append(" " + key + "="); if (key.equals("line.separator")) { - for (char c: value.toCharArray()) { - sb.append(String.format("\\u%04x", (int)c)); + for (char c : value.toCharArray()) { + sb.append(String.format("\\u%04x", (int) c)); } } else { sb.append(value); @@ -281,50 +292,15 @@ public class BugReportDialog extends JDialog { } - - /** - * Send the provided report to the OpenRocket bug report URL. If the connection - * fails or the server does not respond with the correct response code, an - * exception is thrown. - * - * @param report the report to send. - * @throws IOException if an error occurs while connecting to the server or - * the server responds with a wrong response code. - */ - private void sendReport(String report) throws IOException { - URL url = new URL(REPORT_URL); - - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - - connection.setConnectTimeout(REPORT_TIMEOUT); - connection.setInstanceFollowRedirects(true); - connection.setRequestMethod("POST"); - connection.setUseCaches(false); - connection.setRequestProperty("X-OpenRocket-Version", Prefs.getVersion()); - - String post; - post = (REPORT_VERSION_PARAM + "=" + URLEncoder.encode(Prefs.getVersion(), "UTF-8") - + "&" + REPORT_PARAM + "=" + URLEncoder.encode(report, "UTF-8")); - - OutputStreamWriter wr = null; - try { - // Send post information - connection.setDoOutput(true); - wr = new OutputStreamWriter(connection.getOutputStream(), "UTF-8"); - wr.write(post); - wr.flush(); - - if (connection.getResponseCode() != REPORT_RESPONSE_CODE) { - throw new IOException("Server responded with code " + - connection.getResponseCode() + ", expecting " + REPORT_RESPONSE_CODE); - } - } finally { - if (wr != null) - wr.close(); - connection.disconnect(); + private static void addErrorLog(StringBuilder sb) { + LogLevelBufferLogger buffer = Application.getLogBuffer(); + List logs = buffer.getLogs(); + for (LogLine l : logs) { + sb.append(l.toString()).append('\n'); } } + /** * Open the default email client with the suitable bug report. @@ -341,14 +317,14 @@ public class BugReportDialog extends JDialog { text = URLEncoder.encode(text, "UTF-8"); version = URLEncoder.encode(Prefs.getVersion(), "UTF-8"); } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); + throw new BugException(e); } - - + + String mailto = "mailto:" + REPORT_EMAIL - + "?subject=Bug%20report%20for%20OpenRocket%20" + version - + "?body=" + text; + + "?subject=Bug%20report%20for%20OpenRocket%20" + version + + "?body=" + text; URI uri; try { uri = new URI(mailto);