Merge pull request #1116 from SiboVG/fix-license-layout

Fix layout issues license dialog
This commit is contained in:
SiboVG 2022-02-11 16:00:25 +01:00 committed by GitHub
commit 0c03f631ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 31 deletions

View File

@ -12,19 +12,16 @@ import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.swing.JTextPane;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.JEditorPane;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingUtilities;
import net.sf.openrocket.util.BugException;
@SuppressWarnings("serial")
public class DescriptionArea extends JScrollPane {
@ -180,5 +177,17 @@ public class DescriptionArea extends JScrollPane {
});
editorPane.scrollRectToVisible(new Rectangle(0, 0, 1, 1));
}
/**
* Set the font to use for the text pane. If null, then the default font from OR is used.
* @param font font to use
*/
public void setTextFont(Font font) {
if (editorPane == null) return;
editorPane.putClientProperty(JTextPane.HONOR_DISPLAY_PROPERTIES, true);
if (font != null) {
editorPane.setFont(font);
}
}
}

View File

@ -18,8 +18,8 @@ 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 javax.swing.UIManager;
import com.jogamp.opengl.JoglVersion;
@ -73,6 +73,7 @@ public class BugReportDialog extends JDialog {
final JEditorPane editorPane = new JEditorPane("text/html", formatNewlineHTML(message));
editorPane.putClientProperty(JTextPane.HONOR_DISPLAY_PROPERTIES, true);
editorPane.setFont(UIManager.getFont("Label.font"));
editorPane.setPreferredSize(new Dimension(600, 400));
editorPane.setEditable(true);
editorPane.setCaretPosition(0); // Scroll to the top by default
@ -180,7 +181,8 @@ public class BugReportDialog extends JDialog {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
sb.append(sw.getBuffer());
String stackTrace = unformatHTML(String.valueOf(sw.getBuffer()));
sb.append(stackTrace);
sb.append('\n');
@ -207,39 +209,47 @@ public class BugReportDialog extends JDialog {
}
private static void addSystemInformation(StringBuilder sb) {
sb.append("OpenRocket version: " + BuildProperties.getVersion() + "\n");
sb.append("OpenRocket source: " + BuildProperties.getBuildSource() + "\n");
sb.append("OpenRocket location: " + JarUtil.getCurrentJarFile() + "\n");
sb.append("JOGL version: " + JoglVersion.getInstance().getImplementationVersion() + "\n");
sb.append("Current default locale: " + Locale.getDefault() + "\n");
sb.append("System properties:\n");
StringBuilder sbTemp = new StringBuilder();
sbTemp.append("OpenRocket version: " + BuildProperties.getVersion() + "\n");
sbTemp.append("OpenRocket source: " + BuildProperties.getBuildSource() + "\n");
sbTemp.append("OpenRocket location: " + JarUtil.getCurrentJarFile() + "\n");
sbTemp.append("JOGL version: " + JoglVersion.getInstance().getImplementationVersion() + "\n");
sbTemp.append("Current default locale: " + Locale.getDefault() + "\n");
sbTemp.append("System properties:\n");
// Sort the keys
SortedSet<String> keys = new TreeSet<String>();
for (Object key : System.getProperties().keySet()) {
keys.add((String) key);
}
for (String key : keys) {
String value = System.getProperty(key);
sb.append(" " + key + "=");
sbTemp.append(" " + key + "=");
if (key.equals("line.separator")) {
for (char c : value.toCharArray()) {
sb.append(String.format("\\u%04x", (int) c));
sbTemp.append(String.format("\\u%04x", (int) c));
}
} else {
sb.append(value);
sbTemp.append(value);
}
sb.append('\n');
sbTemp.append('\n');
}
String message = unformatHTML(sbTemp.toString());
sb.append(message);
}
private static void addErrorLog(StringBuilder sb) {
StringBuilder sbTemp = new StringBuilder();
LogLevelBufferLogger buffer = LoggingSystemSetup.getBufferLogger();
List<LogLine> logs = buffer.getLogs();
for (LogLine l : logs) {
sb.append(l.toString()).append('\n');
sbTemp.append(l.toString()).append('\n');
}
String message = unformatHTML(sbTemp.toString());
sb.append(message);
}
/**
@ -252,5 +262,14 @@ public class BugReportDialog extends JDialog {
private static String formatNewlineHTML(String text) {
return text.replaceAll("\n(.*?)(?=(\n|$))", "<p style=\"margin-top: 0\">$1</p>");
}
/**
* Makes text HTML unformatted by replacing '<' and '>' by the HTML character equivalent
* @param text text to be replaced
* @return HTML unformatted text
*/
private static String unformatHTML(String text) {
return text.replace("<", "&lt;").replace(">", "&gt;");
}
}

View File

@ -1,21 +1,14 @@
package net.sf.openrocket.gui.dialogs;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.UIManager;
import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.gui.components.DescriptionArea;
@ -39,7 +32,7 @@ public class LicenseDialog extends JDialog {
// OpenRocket logo
panel.add(new JLabel(Icons.loadImageIcon("pix/icon/icon-about.png", "OpenRocket")), "top");
panel.add(new StyledLabel("Software Licenses", 10), "ax 50%, wrap para");
panel.add(new StyledLabel("Software Licenses", 10), "ax 50%, pushx, wrap para");
final String jarUrl = "jar:" + getClass().getProtectionDomain().getCodeSource().getLocation().toString();
final String copyrightYear = BuildProperties.getCopyrightYear();
@ -146,8 +139,9 @@ public class LicenseDialog extends JDialog {
/*****************************************************************************************************************************/
DescriptionArea info = new DescriptionArea(20);
info.setTextFont(UIManager.getFont("Label.font"));
info.setText(orLicense + componentsLicense + fontLicense + commonmarkLicense);
panel.add(info, "newline, width 600lp, height 150lp, grow, spanx, wrap para");
panel.add(info, "newline, width 700lp, height 250lp, pushy, grow, spanx, wrap para");
//Close button
JButton close = new SelectColorButton(trans.get("dlg.but.close"));
@ -157,7 +151,7 @@ public class LicenseDialog extends JDialog {
LicenseDialog.this.dispose();
}
});
panel.add(close, "right");
panel.add(close, "spanx, right");
this.add(panel);
this.setTitle("OpenRocket license");