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;
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;
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"));
d.width = 100000;
label.setMaximumSize(d);
panel.add(label, "gapleft para, wrap para");
-
- label = new JLabel("<html>If connected to the Internet, you can simply click " +
- "<em>Send bug report</em>.");
+
+ //// <html>If connected to the Internet, you can simply click
+ //// <em>Send bug report</em>.
+ 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");
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) {
});
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);
}
}
});
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.
* @param parent the parent window (may be null).
*/
public static void showBugReportDialog(Window parent) {
-
+
StringBuilder sb = new StringBuilder();
sb.append("---------- Bug report ----------\n");
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');
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,
- "<html>You can report a bug in OpenRocket by filling in and submitting " +
- "the form below.<br>" +
- "You can also report bugs and include attachments on the project " +
- "web site.", sb.toString());
+ BugReportDialog reportDialog =
+ new BugReportDialog(parent,
+ //// <html><b>You can report a bug in OpenRocket by filling in and submitting the form below.</b><br>You can also report bugs and include attachments on the project web site.
+ trans.get("bugreport.reportDialog.txt"), sb.toString());
reportDialog.setVisible(true);
}
* @param e the exception.
*/
public static void showExceptionDialog(Window parent, Thread t, Throwable e) {
-
StringBuilder sb = new StringBuilder();
sb.append("---------- Bug report ----------\n");
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();
sb.append(sw.getBuffer());
sb.append('\n');
-
+
sb.append("---------- Thread information ----------\n");
if (t == null) {
sb.append("Thread is not specified.");
}
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 =
+ //// <html><b>Please include a short description about what you were doing when the exception occurred.</b>
+ new BugReportDialog(parent, trans.get("bugreport.reportDialog.txt2"), sb.toString());
reportDialog.setVisible(true);
}
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<String> keys = new TreeSet<String>();
- 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);
}
-
- /**
- * 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<LogLine> logs = buffer.getLogs();
+ for (LogLine l : logs) {
+ sb.append(l.toString()).append('\n');
}
}
+
/**
* Open the default email client with the suitable bug report.
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);