Fixed line wrapping in the error dialog

This commit is contained in:
dragonmacher 2023-08-17 17:18:40 -04:00
parent fc39db9b6a
commit 8a5fbdfa9a

View file

@ -157,21 +157,7 @@ public class ErrLogDialog extends AbstractErrDialog {
new GIconLabel(UIManager.getIcon("OptionPane.errorIcon"), SwingConstants.RIGHT),
BorderLayout.WEST);
JLabel messageLabel;
if (HTMLUtilities.isHTML(message)) {
messageLabel = new GHtmlLabel(message) {
@Override
public Dimension getPreferredSize() {
// rendering HTML the label can expand larger than the screen; keep it reasonable
Dimension size = super.getPreferredSize();
size.width = 300;
return size;
}
};
}
else {
messageLabel = new GLabel(message);
}
JLabel messageLabel = createMessageLabel(message);
introPanel.add(messageLabel, BorderLayout.CENTER);
@ -209,6 +195,25 @@ public class ErrLogDialog extends AbstractErrDialog {
detailsPane.selectFirstError();
}
private JLabel createMessageLabel(String message) {
if (HTMLUtilities.isHTML(message)) {
// Client HTML; keep as-is
return new MaxWidthHtmlLabel(message);
}
if (message.indexOf('\n') != 0) {
// JLabels do not handle newlines, so we must update the text to reflect the client's
// desired newlines. Escape any content that may have angle brackets so it does not get
// removed when we convert the text to HTML. Convert newlines to break tags so the
// label will correctly line wrap as intended by the client.
String html = HTMLUtilities.toLiteralHTML(message, 0);
return new MaxWidthHtmlLabel(html);
}
return new GLabel(message);
}
@Override
protected void cancelCallback() {
close();
@ -270,6 +275,10 @@ public class ErrLogDialog extends AbstractErrDialog {
return baseTitle;
}
//=================================================================================================
// Inner Classes
//=================================================================================================
private class ErrorDetailsSplitPane extends JSplitPane {
private final double TOP_PREFERRED_RESIZE_WEIGHT = .80;
@ -584,4 +593,19 @@ public class ErrLogDialog extends AbstractErrDialog {
}
}
}
private class MaxWidthHtmlLabel extends GHtmlLabel {
MaxWidthHtmlLabel(String text) {
super(text);
}
@Override
public Dimension getPreferredSize() {
// rendering HTML can expand larger than the screen; keep it reasonable
Dimension size = super.getPreferredSize();
size.width = 300;
return size;
}
}
}