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,11 @@ public final class ExceptionAlert extends Alert {
4947
5048 private final String exceptionMessage ;
5149 private final String systemInfoMessage ;
50+ private final String message ;
5251 private final Throwable initialCause ;
5352
5453 private final ButtonType openGitHubIssuesBtnType = new ButtonType ("Open GitHub Issues" );
5554 private final ButtonType copyToClipboardBtnType = new ButtonType ("Copy To Clipboard" );
56- private final ButtonType closeBtnType = new ButtonType ("Cancel" , ButtonBar .ButtonData .CANCEL_CLOSE );
5755 private final Node initialFocusElement ;
5856
5957 /**
@@ -62,17 +60,21 @@ public final class ExceptionAlert extends Alert {
6260 * the issue website.
6361 * @see <a href="http://code.makery.ch/blog/javafx-dialogs-official/">Inspiration</a>
6462 */
65- public ExceptionAlert (final Parent root , final Throwable throwable , final HostServices services ) {
63+ public ExceptionAlert (final Parent root , final Throwable throwable , final String message , boolean isFatal , final HostServices services ) {
6664 super (AlertType .ERROR );
65+ checkNotNull (root , "The parent can not be null" );
6766 checkNotNull (throwable , "The Throwable can not be null" );
67+ this .message = checkNotNull (message , "The message can not be null" );
6868 checkNotNull (services , "HostServices can not be null" );
6969
70+ final ButtonType closeBtnType = new ButtonType (isFatal ? "Quit" : "Cancel" , ButtonBar .ButtonData .CANCEL_CLOSE );
71+
7072 this .exceptionMessage = generateExceptionMessage (throwable );
7173 this .systemInfoMessage = generateSystemInfoMessage ();
72- this .initialCause = generateInitialCause (throwable );
74+ this .initialCause = getInitialCause (throwable );
7375
7476 this .setTitle (initialCause .getClass ().getSimpleName ());
75- this .setHeaderText (initialCause . getMessage () );
77+ this .setHeaderText (( isFatal ? "FATAL: " : "" ) + message );
7678
7779 // Set stylesheet
7880 this .getDialogPane ().styleProperty ().bind (root .styleProperty ());
@@ -91,7 +93,7 @@ public ExceptionAlert(final Parent root, final Throwable throwable, final HostSe
9193 final Label issuePasteLabel = new Label (ISSUE_PROMPT_TEXT );
9294 issuePasteLabel .setWrapText (true );
9395
94- final TextArea issueText = new TextArea (stackTrace (throwable ));
96+ final TextArea issueText = new TextArea (Throwables . getStackTraceAsString (throwable ));
9597 issuePasteLabel .setLabelFor (issueText );
9698 issueText .setEditable (false );
9799 issueText .setWrapText (true );
@@ -152,22 +154,16 @@ public final void setInitialFocus() {
152154 * @param throwable The throwable to iterate through.
153155 * @return The initial throwable
154156 */
155- private Throwable generateInitialCause (Throwable throwable ) {
157+ private Throwable getInitialCause (Throwable throwable ) {
156158 if (throwable .getCause () == null ) {
157159 return throwable ;
158160 } else {
159- return generateInitialCause (throwable .getCause ());
161+ return getInitialCause (throwable .getCause ());
160162 }
161163 }
162164
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 ();
165+ private String getAdditionalInfoMessage () {
166+ return "Message: " + message + "\n " ;
171167 }
172168
173169 /**
@@ -177,7 +173,7 @@ private String stackTrace(Throwable throwable) {
177173 * @return The markdown for the exception.
178174 */
179175 private String generateExceptionMessage (Throwable throwable ) {
180- return new StringBuilder (stackTrace (throwable )
176+ return new StringBuilder (Throwables . getStackTraceAsString (throwable )
181177 /* Allow users to maintain anonymity */
182178 .replace (System .getProperty ("user.home" ), "$HOME" ).replace (System .getProperty ("user.name" ), "$USER" ))
183179 .insert (0 , "## Stack Trace:\n ```java\n " ).append ("\n ```" ).toString ();
@@ -203,10 +199,9 @@ private String generateSystemInfoMessage() {
203199 * @return The fully constructed issue text.
204200 */
205201 private String issueText () {
206- return new StringBuilder (ISSUE_PROMPT_QUESTION )
207- .append ("\n \n \n \n " )
208- .append (systemInfoMessage )
209- .append (exceptionMessage ).toString ();
202+ final StringBuilder builder = new StringBuilder (ISSUE_PROMPT_QUESTION ).append ("\n \n \n \n " )
203+ .append (getAdditionalInfoMessage ()).append ("\n " ).append (systemInfoMessage ).append (exceptionMessage );
204+ return builder .toString ();
210205 }
211206
212207
0 commit comments