11package edu .wpi .grip .ui ;
22
3+ import com .google .common .base .Throwables ;
34import com .google .common .net .UrlEscapers ;
45import javafx .application .HostServices ;
56import javafx .application .Platform ;
1112import javafx .scene .input .ClipboardContent ;
1213import javafx .scene .layout .GridPane ;
1314
14- import java .io .PrintWriter ;
15- import java .io .StringWriter ;
16-
1715import static com .google .common .base .Preconditions .checkNotNull ;
1816
1917/**
@@ -49,11 +47,12 @@ public final class ExceptionAlert extends Alert {
4947
5048 private final String exceptionMessage ;
5149 private final String systemInfoMessage ;
50+ private final String additionalInfoMessage ;
51+ private final String message ;
5252 private final Throwable initialCause ;
5353
5454 private final ButtonType openGitHubIssuesBtnType = new ButtonType ("Open GitHub Issues" );
5555 private final ButtonType copyToClipboardBtnType = new ButtonType ("Copy To Clipboard" );
56- private final ButtonType closeBtnType = new ButtonType ("Cancel" , ButtonBar .ButtonData .CANCEL_CLOSE );
5756 private final Node initialFocusElement ;
5857
5958 /**
@@ -62,17 +61,22 @@ public final class ExceptionAlert extends Alert {
6261 * the issue website.
6362 * @see <a href="http://code.makery.ch/blog/javafx-dialogs-official/">Inspiration</a>
6463 */
65- public ExceptionAlert (final Parent root , final Throwable throwable , final HostServices services ) {
64+ public ExceptionAlert (final Parent root , final Throwable throwable , final String message , boolean isFatal , final HostServices services ) {
6665 super (AlertType .ERROR );
66+ checkNotNull (root , "The parent can not be null" );
6767 checkNotNull (throwable , "The Throwable can not be null" );
68+ this .message = checkNotNull (message , "The message can not be null" );
6869 checkNotNull (services , "HostServices can not be null" );
6970
71+ final ButtonType closeBtnType = new ButtonType (isFatal ? "Quit" : "Cancel" , ButtonBar .ButtonData .CANCEL_CLOSE );
72+
7073 this .exceptionMessage = generateExceptionMessage (throwable );
7174 this .systemInfoMessage = generateSystemInfoMessage ();
72- this .initialCause = generateInitialCause (throwable );
75+ this .additionalInfoMessage = generateAdditionalInfoMessage ();
76+ this .initialCause = getInitialCause (throwable );
7377
7478 this .setTitle (initialCause .getClass ().getSimpleName ());
75- this .setHeaderText (initialCause . getMessage () );
79+ this .setHeaderText (( isFatal ? "FATAL: " : "" ) + message );
7680
7781 // Set stylesheet
7882 this .getDialogPane ().styleProperty ().bind (root .styleProperty ());
@@ -91,7 +95,7 @@ public ExceptionAlert(final Parent root, final Throwable throwable, final HostSe
9195 final Label issuePasteLabel = new Label (ISSUE_PROMPT_TEXT );
9296 issuePasteLabel .setWrapText (true );
9397
94- final TextArea issueText = new TextArea (stackTrace (throwable ));
98+ final TextArea issueText = new TextArea (Throwables . getStackTraceAsString (throwable ));
9599 issuePasteLabel .setLabelFor (issueText );
96100 issueText .setEditable (false );
97101 issueText .setWrapText (true );
@@ -152,22 +156,16 @@ public final void setInitialFocus() {
152156 * @param throwable The throwable to iterate through.
153157 * @return The initial throwable
154158 */
155- private Throwable generateInitialCause (Throwable throwable ) {
159+ private Throwable getInitialCause (Throwable throwable ) {
156160 if (throwable .getCause () == null ) {
157161 return throwable ;
158162 } else {
159- return generateInitialCause (throwable .getCause ());
163+ return getInitialCause (throwable .getCause ());
160164 }
161165 }
162166
163- /**
164- * Generates the Throwable's stack trace as a string.
165- */
166- private String stackTrace (Throwable throwable ) {
167- final StringWriter sw = new StringWriter ();
168- final PrintWriter pw = new PrintWriter (sw );
169- throwable .printStackTrace (pw );
170- return sw .toString ();
167+ private String generateAdditionalInfoMessage () {
168+ return "Message: " + message + "\n " ;
171169 }
172170
173171 /**
@@ -177,7 +175,7 @@ private String stackTrace(Throwable throwable) {
177175 * @return The markdown for the exception.
178176 */
179177 private String generateExceptionMessage (Throwable throwable ) {
180- return new StringBuilder (stackTrace (throwable )
178+ return new StringBuilder (Throwables . getStackTraceAsString (throwable )
181179 /* Allow users to maintain anonymity */
182180 .replace (System .getProperty ("user.home" ), "$HOME" ).replace (System .getProperty ("user.name" ), "$USER" ))
183181 .insert (0 , "## Stack Trace:\n ```java\n " ).append ("\n ```" ).toString ();
@@ -203,10 +201,12 @@ private String generateSystemInfoMessage() {
203201 * @return The fully constructed issue text.
204202 */
205203 private String issueText () {
206- return new StringBuilder (ISSUE_PROMPT_QUESTION )
207- .append ("\n \n \n \n " )
208- .append (systemInfoMessage )
209- .append (exceptionMessage ).toString ();
204+ return ISSUE_PROMPT_QUESTION
205+ + "\n \n \n \n "
206+ + additionalInfoMessage
207+ + "\n "
208+ + systemInfoMessage
209+ + exceptionMessage ;
210210 }
211211
212212
0 commit comments