1 package processing.app.helpers; 2 3 import processing.app.Base; 4 5 import static processing.app.I18n.tr; 6 7 import javax.swing.JOptionPane; 8 9 public class GUIUserNotifier extends UserNotifier { 10 11 private final Base base; 12 GUIUserNotifier(Base base)13 public GUIUserNotifier(Base base) { 14 this.base = base; 15 } 16 17 /** 18 * Show an error message that's actually fatal to the program. 19 * This is an error that can't be recovered. Use showWarning() 20 * for errors that allow P5 to continue running. 21 */ showError(String title, String message, Throwable e, int exit_code)22 public void showError(String title, String message, Throwable e, int exit_code) { 23 if (title == null) title = tr("Error"); 24 25 JOptionPane.showMessageDialog(base.getActiveEditor(), message, title, 26 JOptionPane.ERROR_MESSAGE); 27 28 if (e != null) e.printStackTrace(); 29 System.exit(exit_code); 30 } 31 32 /** 33 * "No cookie for you" type messages. Nothing fatal or all that 34 * much of a bummer, but something to notify the user about. 35 */ showMessage(String title, String message)36 public void showMessage(String title, String message) { 37 if (title == null) title = tr("Message"); 38 39 JOptionPane.showMessageDialog(base.getActiveEditor(), message, title, 40 JOptionPane.INFORMATION_MESSAGE); 41 } 42 43 /** 44 * Non-fatal error message with optional stack trace side dish. 45 */ showWarning(String title, String message, Exception e)46 public void showWarning(String title, String message, Exception e) { 47 if (title == null) title = tr("Warning"); 48 49 JOptionPane.showMessageDialog(base.getActiveEditor(), message, title, 50 JOptionPane.WARNING_MESSAGE); 51 52 if (e != null) e.printStackTrace(); 53 } 54 55 } 56