mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-09-28 17:11:11 -09:00
GP-2844 - Updated the error dialog to prevent the loss of messages using
html brackets
This commit is contained in:
@@ -109,18 +109,9 @@ public class DockingErrorDisplay implements ErrorDisplay {
|
|||||||
|
|
||||||
int dialogType = OptionDialog.PLAIN_MESSAGE;
|
int dialogType = OptionDialog.PLAIN_MESSAGE;
|
||||||
|
|
||||||
String messageString = message != null ? message.toString() : null;
|
String cleanMessage = cleanupMessage(message);
|
||||||
if (messageString != null) {
|
|
||||||
// prevent excessive message degenerate cases
|
|
||||||
int maxChars = 1000;
|
|
||||||
String safeMessage = StringUtilities.trimMiddle(messageString, maxChars);
|
|
||||||
|
|
||||||
// wrap any poorly formatted text that gets displayed in the label; 80-100 chars is
|
String unformattedMessage = HTMLUtilities.fromHTML(cleanMessage);
|
||||||
// a reasonable line length based on historical print margins
|
|
||||||
messageString = wrap(safeMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
String unformattedMessage = HTMLUtilities.fromHTML(messageString);
|
|
||||||
switch (messageType) {
|
switch (messageType) {
|
||||||
case INFO:
|
case INFO:
|
||||||
dialogType = OptionDialog.INFORMATION_MESSAGE;
|
dialogType = OptionDialog.INFORMATION_MESSAGE;
|
||||||
@@ -140,7 +131,25 @@ public class DockingErrorDisplay implements ErrorDisplay {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
showDialog(title, throwable, dialogType, messageString, getWindow(parent));
|
showDialog(title, throwable, dialogType, cleanMessage, getWindow(parent));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String cleanupMessage(Object message) {
|
||||||
|
|
||||||
|
if (message == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// prevent excessive message degenerate cases
|
||||||
|
int maxChars = 1000;
|
||||||
|
String messageString = message.toString();
|
||||||
|
String safeMessage = StringUtilities.trimMiddle(messageString, maxChars);
|
||||||
|
|
||||||
|
// 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 = wrap(safeMessage);
|
||||||
|
|
||||||
|
return messageString;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Component getWindow(Component component) {
|
private Component getWindow(Component component) {
|
||||||
@@ -150,20 +159,19 @@ public class DockingErrorDisplay implements ErrorDisplay {
|
|||||||
return component;
|
return component;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showDialog(String title, Throwable throwable, int dialogType,
|
private void showDialog(String title, Throwable throwable, int dialogType, String messageString,
|
||||||
String messageString, Component parent) {
|
Component parent) {
|
||||||
|
|
||||||
if (dialogType == OptionDialog.ERROR_MESSAGE) {
|
if (dialogType == OptionDialog.ERROR_MESSAGE) {
|
||||||
showDialogOnSwing(title, throwable, dialogType, messageString, parent);
|
showErrorDialogOnSwing(title, throwable, messageString, parent);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DockingWindowManager.showDialog(parent,
|
DockingWindowManager.showDialog(parent, new OkDialog(title, messageString, dialogType));
|
||||||
new OkDialog(title, messageString, dialogType));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showDialogOnSwing(String title, Throwable throwable, int dialogType,
|
private void showErrorDialogOnSwing(String title, Throwable throwable, String messageString,
|
||||||
String messageString, Component parent) {
|
Component parent) {
|
||||||
|
|
||||||
if (activeDialog != null) {
|
if (activeDialog != null) {
|
||||||
activeDialog.addException(messageString, throwable);
|
activeDialog.addException(messageString, throwable);
|
||||||
|
|||||||
@@ -4,9 +4,9 @@
|
|||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
@@ -24,8 +24,7 @@ import java.util.List;
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
import docking.widgets.ScrollableTextArea;
|
import docking.widgets.ScrollableTextArea;
|
||||||
import docking.widgets.label.GHtmlLabel;
|
import docking.widgets.label.*;
|
||||||
import docking.widgets.label.GIconLabel;
|
|
||||||
import docking.widgets.table.*;
|
import docking.widgets.table.*;
|
||||||
import generic.json.Json;
|
import generic.json.Json;
|
||||||
import generic.util.WindowUtilities;
|
import generic.util.WindowUtilities;
|
||||||
@@ -157,16 +156,24 @@ public class ErrLogDialog extends AbstractErrDialog {
|
|||||||
introPanel.add(
|
introPanel.add(
|
||||||
new GIconLabel(UIManager.getIcon("OptionPane.errorIcon"), SwingConstants.RIGHT),
|
new GIconLabel(UIManager.getIcon("OptionPane.errorIcon"), SwingConstants.RIGHT),
|
||||||
BorderLayout.WEST);
|
BorderLayout.WEST);
|
||||||
String html = HTMLUtilities.toHTML(message);
|
|
||||||
introPanel.add(new GHtmlLabel(html) {
|
JLabel messageLabel;
|
||||||
@Override
|
if (HTMLUtilities.isHTML(message)) {
|
||||||
public Dimension getPreferredSize() {
|
messageLabel = new GHtmlLabel(message) {
|
||||||
// rendering HTML the label can expand larger than the screen; keep it reasonable
|
@Override
|
||||||
Dimension size = super.getPreferredSize();
|
public Dimension getPreferredSize() {
|
||||||
size.width = 300;
|
// rendering HTML the label can expand larger than the screen; keep it reasonable
|
||||||
return size;
|
Dimension size = super.getPreferredSize();
|
||||||
}
|
size.width = 300;
|
||||||
}, BorderLayout.CENTER);
|
return size;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
messageLabel = new GLabel(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
introPanel.add(messageLabel, BorderLayout.CENTER);
|
||||||
|
|
||||||
mainPanel = new JPanel(new BorderLayout(10, 20));
|
mainPanel = new JPanel(new BorderLayout(10, 20));
|
||||||
mainPanel.add(introPanel, BorderLayout.NORTH);
|
mainPanel.add(introPanel, BorderLayout.NORTH);
|
||||||
|
|||||||
Reference in New Issue
Block a user