Merge remote-tracking branch 'origin/GP-828-dragonmacher-bad-message-wrapping--SQUASHED'

This commit is contained in:
ghidra1 2021-05-10 20:50:41 -04:00
commit 6fd613d4f9
2 changed files with 32 additions and 10 deletions

View File

@ -17,13 +17,16 @@ package docking;
import java.awt.Component;
import java.awt.Window;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.WordUtils;
import docking.widgets.OkDialog;
import docking.widgets.OptionDialog;
import ghidra.util.*;
import ghidra.util.exception.MultipleCauses;
import ghidra.util.html.HtmlLineSplitter;
public class DockingErrorDisplay implements ErrorDisplay {
@ -60,6 +63,31 @@ public class DockingErrorDisplay implements ErrorDisplay {
throwable);
}
private static String wrap(String text) {
StringBuilder buffy = new StringBuilder();
List<String> lines = HtmlLineSplitter.split(text, 100, true);
String newline = "\n";
for (String line : lines) {
if (buffy.length() != 0) {
buffy.append(newline);
}
if (StringUtils.isBlank(line)) {
// this will trim all leading blank lines, but preserve internal blank lines,
// which clients may be providing for visual line separation
continue;
}
// wrap any poorly formatted text that gets displayed in the label; 80-100 chars is
// a reasonable line length based on historical print margins
String wrapped = WordUtils.wrap(line, 100, null, true);
buffy.append(wrapped);
}
return buffy.toString();
}
private void displayMessage(MessageType messageType, ErrorLogger errorLogger, Object originator,
Component parent, String title, Object message, Throwable throwable) {
@ -73,7 +101,7 @@ public class DockingErrorDisplay implements ErrorDisplay {
// wrap any poorly formatted text that gets displayed in the label; 80-100 chars is
// a reasonable line length based on historical print margins
messageString = WordUtils.wrap(safeMessage, 100, null, true);
messageString = wrap(safeMessage);
}
String unformattedMessage = HTMLUtilities.fromHTML(messageString);

View File

@ -16,7 +16,6 @@
package docking.widgets;
import java.awt.*;
import java.util.StringTokenizer;
import javax.swing.JFrame;
import javax.swing.JPanel;
@ -103,15 +102,10 @@ public class MultiLineLabel extends JPanel {
"exception with no message from the line of code below:\n\n" + getCallerString();
Msg.debug(label, label, new Throwable());
}
StringTokenizer t = new StringTokenizer(label, "\n");
num_lines = t.countTokens();
lines = new String[num_lines];
lines = label.split("\n");
num_lines = lines.length;
line_widths = new int[num_lines];
for (int i = 0; i < num_lines; i++) {
lines[i] = t.nextToken();
}
}
private String getCallerString() {
@ -331,7 +325,7 @@ public class MultiLineLabel extends JPanel {
public static void main(String[] args) {
MultiLineLabel mlab = new MultiLineLabel(
"This is a test\nof a multi-line label\nLine One\n" + "Line Two\nLine Three.", 20, 20,
"This is a test\nof a multi-line label\nLine One\n\nLine Two\nLine Three.", 20, 20,
MultiLineLabel.CENTER);
JFrame f = new JFrame("Test MultiLineLabel");
f.getContentPane().add(mlab);