diff --git a/app/src/processing/app/helpers/BasicNotifier.java b/app/src/processing/app/helpers/BasicNotifier.java new file mode 100644 index 000000000..72146188b --- /dev/null +++ b/app/src/processing/app/helpers/BasicNotifier.java @@ -0,0 +1,25 @@ +package processing.app.helpers; + +import static processing.app.I18n._; + +public class BasicNotifier implements UserNotifier { + + public void showError(String title, String message, Throwable e) { + showError(title, message, e, 1); + } + + /** + * Show an error message that's actually fatal to the program. + * This is an error that can't be recovered. Use showWarning() + * for errors that allow P5 to continue running. + */ + public void showError(String title, String message, Throwable e, int exit_code) { + if (title == null) title = _("Error"); + + System.err.println(title + ": " + message); + + if (e != null) e.printStackTrace(); + System.exit(exit_code); + } + +} diff --git a/app/src/processing/app/helpers/GUINotifier.java b/app/src/processing/app/helpers/GUINotifier.java new file mode 100644 index 000000000..ecee305d0 --- /dev/null +++ b/app/src/processing/app/helpers/GUINotifier.java @@ -0,0 +1,29 @@ +package processing.app.helpers; + +import static processing.app.I18n._; + +import java.awt.Frame; + +import javax.swing.JOptionPane; + +public class GUINotifier implements UserNotifier { + + public void showError(String title, String message, Throwable e) { + showError(title, message, e, 1); + } + + /** + * Show an error message that's actually fatal to the program. + * This is an error that can't be recovered. Use showWarning() + * for errors that allow P5 to continue running. + */ + public void showError(String title, String message, Throwable e, int exit_code) { + if (title == null) title = _("Error"); + + JOptionPane.showMessageDialog(new Frame(), message, title, + JOptionPane.ERROR_MESSAGE); + + if (e != null) e.printStackTrace(); + System.exit(exit_code); + } +} diff --git a/app/src/processing/app/helpers/UserNotifier.java b/app/src/processing/app/helpers/UserNotifier.java new file mode 100644 index 000000000..62388de68 --- /dev/null +++ b/app/src/processing/app/helpers/UserNotifier.java @@ -0,0 +1,9 @@ +package processing.app.helpers; + +public interface UserNotifier { + + public void showError(String title, String message, Throwable e); + + public void showError(String title, String message, Throwable e, int exit_code); + +}