Added notifier interface and classes.

This commit is contained in:
Claudio Indellicati 2014-08-21 19:46:16 +02:00 committed by Cristian Maglie
parent a43d207e4f
commit fa0d37dad6
3 changed files with 63 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}