Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-critical mode for CR #36

Merged
merged 5 commits into from
Mar 13, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ private CrashReporter() {
* Can be called from any thread.
* @param throwable the exception to report
* @param logFileFolder the log file folder or <code>null</code>
* @param ifCritical true if CrashReporter is in the critical mode
*/
public static void report(final Throwable throwable, final Path logFileFolder) {
public static void report(final Throwable throwable, final Path logFileFolder, final boolean ifCritical) {
// Swing element methods must be called in the swing thread
try {
SwingUtilities.invokeAndWait(new Runnable() {
Expand All @@ -57,7 +58,7 @@ public void run() {
e.printStackTrace();
}
GlobalProperties properties = new GlobalProperties();
showModalDialog(throwable, properties, logFileFolder);
showModalDialog(throwable, properties, logFileFolder,ifCritical);
try {
UIManager.setLookAndFeel(oldLaF);
} catch (Exception e) {
Expand All @@ -70,15 +71,15 @@ public void run() {
}
}

protected static void showModalDialog(Throwable throwable, GlobalProperties properties, Path logFolder) {
String dialogTitle = I18N.getMessage("dialogTitle");
protected static void showModalDialog(Throwable throwable, GlobalProperties properties, Path logFolder, boolean ifCritical) {
String dialogTitle = I18N.getMessage(ifCritical ? "dialogTitle" : "dialogTitleNonCritical");
String version = Resources.getVersion();

if (version != null) {
dialogTitle += " " + version;
}

RootPanel panel = new RootPanel(throwable, properties, logFolder);
RootPanel panel = new RootPanel(throwable, properties, logFolder,ifCritical);
JDialog dialog = new JDialog((Dialog) null, dialogTitle, true);
dialog.setIconImage(Resources.loadImage(properties.get(KEY.RES_SERVER_ICON)));
dialog.setContentPane(panel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ public class RootPanel extends JPanel {
* @param exception the exception that occurred
* @param properties the properties for this dialog wizard
* @param logFolderFile the log file or <code>null</code>
* @param ifCritical true if CrashReporter is in the critical mode
*/
public RootPanel(Throwable exception, GlobalProperties properties, Path logFolderFile) {
public RootPanel(Throwable exception, GlobalProperties properties, Path logFolderFile, boolean ifCritical) {

setLayout(new BorderLayout());
Font buttonFont = getFont().deriveFont(Font.BOLD, 14f);
Expand All @@ -69,7 +70,7 @@ public RootPanel(Throwable exception, GlobalProperties properties, Path logFolde
final Icon closeIcon = Resources.loadIcon(properties.get(KEY.RES_EXIT_ICON));

List<JComponent> pages = new ArrayList<>();
final ErrorMessagePanel errorMessagePanel = new ErrorMessagePanel(properties, exception, logFolderFile);
final ErrorMessagePanel errorMessagePanel = new ErrorMessagePanel(properties, exception, logFolderFile, ifCritical);
pages.add(errorMessagePanel);
final UserInfoPanel userInfoPanel = new UserInfoPanel(properties,
errorMessagePanel.getLog(), errorMessagePanel.getLogFile());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ public class ErrorMessagePanel extends JPanel {
* @param exception the exception to display
* @param logFileFolder the folder that contains the relevant log files
* @param properties the properties for this dialog wizard
* @param ifCritical true if CrashReporter is in the critical mode

*/
public ErrorMessagePanel(GlobalProperties properties, Throwable exception, Path logFileFolder) {
public ErrorMessagePanel(GlobalProperties properties, Throwable exception, Path logFileFolder, boolean ifCritical) {

JPanel mainPanel = this;
mainPanel.setLayout(new BorderLayout(0, 5));
Expand All @@ -77,8 +79,8 @@ public ErrorMessagePanel(GlobalProperties properties, Throwable exception, Path
// Replace newline chars. with html newline elements (not needed in most cases)
text = text.replaceAll("\\r?\\n", "<br/>");

String firstLine = I18N.getMessage("firstLine");
Icon titleIcon = Resources.loadIcon(properties.get(KEY.RES_ERROR_TITLE_IMAGE));
String firstLine = I18N.getMessage( ifCritical ? "firstLine" : "firstLineNonCritical");
Icon titleIcon = Resources.loadIcon(properties.get( ifCritical ? KEY.RES_ERROR_TITLE_IMAGE : KEY.RES_INFO_TITLE_IMAGE));

String htmlText = "<html><h3>" + firstLine + "</h3>" + text + "</html>";
JLabel message = new JLabel(htmlText, titleIcon, SwingConstants.LEFT);
Expand Down
2 changes: 2 additions & 0 deletions cr-core/src/main/resources/i18n/MessagesBundle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
dialogTitle=Crash Reporter
dialogTitleNonCritical=Issue Reporter
firstLine=A fatal error occurred
firstLineNonCritical=Current game log
editBeforeUpload=NOTE: you can edit the content of the log file before uploading
viewLog=Log file
logFileUrl=Log file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static void main(String[] args) throws Exception {

if (!GraphicsEnvironment.isHeadless()) {
Path logPath = Paths.get(".");
CrashReporter.report(e, logPath);
CrashReporter.report(e, logPath,true);
}
}
}
Expand Down