From e48804feabb86845e2984bbd78d1da0b52fdfdb0 Mon Sep 17 00:00:00 2001 From: Sibo Van Gool Date: Fri, 28 Jan 2022 22:34:03 +0100 Subject: [PATCH 1/3] Improve bug report formatting --- .../gui/dialogs/BugReportDialog.java | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/dialogs/BugReportDialog.java b/swing/src/net/sf/openrocket/gui/dialogs/BugReportDialog.java index 2fd0f26b4..c3ce4d470 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/BugReportDialog.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/BugReportDialog.java @@ -14,10 +14,12 @@ import java.util.TreeSet; import javax.swing.JButton; import javax.swing.JDialog; +import javax.swing.JEditorPane; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; +import javax.swing.JTextPane; import com.jogamp.opengl.JoglVersion; @@ -68,11 +70,13 @@ public class BugReportDialog extends JDialog { panel.add(new JLabel(trans.get("bugreport.dlg.otherwise") + " "), "gapleft para, split 2, gapright rel"); panel.add(new URLLabel(REPORT_EMAIL_URL, REPORT_EMAIL), "growx, wrap para"); - - - final JTextArea textArea = new JTextArea(message, 20, 70); - textArea.setEditable(true); - panel.add(new JScrollPane(textArea), "grow, wrap"); + + final JEditorPane editorPane = new JEditorPane("text/html", message.replace("\n", "
")); + editorPane.putClientProperty(JTextPane.HONOR_DISPLAY_PROPERTIES, true); + editorPane.setPreferredSize(new Dimension(600, 400)); + editorPane.setEditable(true); + editorPane.setCaretPosition(0); // Scroll to the top by default + panel.add(new JScrollPane(editorPane), "grow, wrap"); panel.add(new StyledLabel(trans.get("bugreport.lbl.Theinformation"), -1), "wrap para"); @@ -106,17 +110,18 @@ public class BugReportDialog extends JDialog { StringBuilder sb = new StringBuilder(); - sb.append("---------- Bug report ----------\n"); + sb.append("---------- Bug report ----------\n"); sb.append('\n'); - sb.append("Include detailed steps on how to trigger the bug:\n"); + sb.append("Include detailed steps on how to trigger the bug:\n"); + sb.append("(You can edit text directly in this window)\n"); sb.append('\n'); sb.append("1. \n"); sb.append("2. \n"); sb.append("3. \n"); sb.append('\n'); - sb.append("What does the software do and what in your opinion should it do in the " + - "case described above:\n"); + sb.append("What does the software do and what in your opinion should it do in the " + + "case described above:\n"); sb.append('\n'); sb.append('\n'); sb.append('\n'); @@ -133,7 +138,7 @@ public class BugReportDialog extends JDialog { addSystemInformation(sb); sb.append("---------- Error log ----------\n"); addErrorLog(sb); - sb.append("---------- End of bug report ----------\n"); + sb.append("---------- End of bug report ----------\n"); sb.append('\n'); BugReportDialog reportDialog = new BugReportDialog(parent, @@ -152,14 +157,15 @@ public class BugReportDialog extends JDialog { public static void showExceptionDialog(Window parent, Thread t, Throwable e) { StringBuilder sb = new StringBuilder(); - sb.append("---------- Bug report ----------\n"); - sb.append('\n'); - sb.append("Please include a description about what actions you were " + - "performing when the exception occurred:\n"); - sb.append('\n'); - sb.append('\n'); + sb.append("---------- Bug report ----------\n"); sb.append('\n'); + sb.append("Please include a description about what actions you were " + + "performing when the exception occurred:\n"); + sb.append("(You can edit text directly in this window)\n"); sb.append('\n'); + sb.append("1. \n"); + sb.append("2. \n"); + sb.append("3. \n"); sb.append("Include your email address (optional; it helps if we can " + @@ -191,7 +197,7 @@ public class BugReportDialog extends JDialog { addSystemInformation(sb); sb.append("---------- Error log ----------\n"); addErrorLog(sb); - sb.append("---------- End of bug report ----------\n"); + sb.append("---------- End of bug report ----------\n"); sb.append('\n'); BugReportDialog reportDialog = From ec8d88fa0192eb8fb5fc180036a5d032bba83d74 Mon Sep 17 00:00:00 2001 From: Sibo Van Gool Date: Fri, 28 Jan 2022 22:35:13 +0100 Subject: [PATCH 2/3] Use fixed Locale for LogLine number formatting Keep consistency over bug reports (e.g. on my machine, the time stamp was with commas as decimal separators, but I've seen people with dots) --- swing/src/net/sf/openrocket/logging/LogLine.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/swing/src/net/sf/openrocket/logging/LogLine.java b/swing/src/net/sf/openrocket/logging/LogLine.java index c4c0d4cb1..af6f74f54 100644 --- a/swing/src/net/sf/openrocket/logging/LogLine.java +++ b/swing/src/net/sf/openrocket/logging/LogLine.java @@ -1,6 +1,7 @@ package net.sf.openrocket.logging; import java.io.PrintWriter; +import java.util.Locale; import java.util.concurrent.atomic.AtomicInteger; /** @@ -127,7 +128,7 @@ public class LogLine implements Comparable { public String toString() { if (formattedMessage == null) { String str; - str = String.format("%4d %10.3f %-" + LogLevel.LENGTH + "s %s %s", + str = String.format(Locale.ENGLISH, "%4d %10.3f %-" + LogLevel.LENGTH + "s %s %s", count, timestamp / 1000.0, (level != null) ? level.toString() : "NULL", getLocation(), message); From 0773cfbdf539fcc7c1fa7d79c3e036fea6d5d531 Mon Sep 17 00:00:00 2001 From: Sibo Van Gool Date: Fri, 28 Jan 2022 22:52:35 +0100 Subject: [PATCH 3/3] Use special HTML newline With the
HTML newline, when a user would want to copy-paste the bug report, it would just be one long string of text, because the
tag would just be replaced by a space instead of a newline. --- .../sf/openrocket/gui/dialogs/BugReportDialog.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/swing/src/net/sf/openrocket/gui/dialogs/BugReportDialog.java b/swing/src/net/sf/openrocket/gui/dialogs/BugReportDialog.java index c3ce4d470..6b1817990 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/BugReportDialog.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/BugReportDialog.java @@ -71,7 +71,7 @@ public class BugReportDialog extends JDialog { "gapleft para, split 2, gapright rel"); panel.add(new URLLabel(REPORT_EMAIL_URL, REPORT_EMAIL), "growx, wrap para"); - final JEditorPane editorPane = new JEditorPane("text/html", message.replace("\n", "
")); + final JEditorPane editorPane = new JEditorPane("text/html", formatNewlineHTML(message)); editorPane.putClientProperty(JTextPane.HONOR_DISPLAY_PROPERTIES, true); editorPane.setPreferredSize(new Dimension(600, 400)); editorPane.setEditable(true); @@ -241,5 +241,16 @@ public class BugReportDialog extends JDialog { sb.append(l.toString()).append('\n'); } } + + /** + * Replace newline character \n to an HTML newline. Instead of just using a
tag, we replace newlines with a + * paragraph tag with zero margin. This is so that when you copy the HTML text and paste it somewhere, that the + * HTML newlines are also interpreted as newlines in the new text. A
tag would just be replaced by a space. + * @param text text to be formatted + * @return text with HTML newlines + */ + private static String formatNewlineHTML(String text) { + return text.replaceAll("\n(.*?)(?=(\n|$))", "

$1

"); + } }