Merged l10n branch to trunk
[debian/openrocket] / src / net / sf / openrocket / gui / dialogs / BugReportDialog.java
index 7f397810078e132a143824f17b960e4fdb5d4c76..9966dbe50ada1695b4d6f331f5e32d7d6794efcf 100644 (file)
@@ -13,6 +13,8 @@ import java.io.UnsupportedEncodingException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URLEncoder;
+import java.util.List;
+import java.util.Locale;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
@@ -28,6 +30,10 @@ import net.miginfocom.swing.MigLayout;
 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;
@@ -36,10 +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 Translator trans = Application.getTranslator();
 
+       
        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"));
                
@@ -49,15 +57,17 @@ public class BugReportDialog extends JDialog {
                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");
                
@@ -66,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 StyledLabel("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) {
@@ -83,25 +91,26 @@ 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) {
@@ -109,20 +118,28 @@ public class BugReportDialog extends JDialog {
                                try {
                                        
                                        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);
                                }
                        }
                });
@@ -137,9 +154,9 @@ public class BugReportDialog extends JDialog {
                
                GUIUtil.setDisposableDialogOptions(this, send);
        }
-
        
        
+
        /**
         * Show a general bug report dialog allowing the user to input information about
         * the bug they encountered.
@@ -147,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");
@@ -166,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');
@@ -175,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,
-                                       "<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.", 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);
        }
        
@@ -196,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");
@@ -215,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();
@@ -224,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.");
@@ -233,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, "<html><b>Please include a short description about " +
-                                       "what you were doing when the exception occurred.</b>", 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);
        }
        
@@ -250,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<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);
@@ -273,7 +292,16 @@ public class BugReportDialog extends JDialog {
        }
        
        
+       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.
         * Note that this does not work on some systems even if Desktop.isSupported()
@@ -292,11 +320,11 @@ public class BugReportDialog extends JDialog {
                        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);