Skip to content

Commit fa0d37d

Browse files
bitroncmaglie
authored andcommitted
Added notifier interface and classes.
1 parent a43d207 commit fa0d37d

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package processing.app.helpers;
2+
3+
import static processing.app.I18n._;
4+
5+
public class BasicNotifier implements UserNotifier {
6+
7+
public void showError(String title, String message, Throwable e) {
8+
showError(title, message, e, 1);
9+
}
10+
11+
/**
12+
* Show an error message that's actually fatal to the program.
13+
* This is an error that can't be recovered. Use showWarning()
14+
* for errors that allow P5 to continue running.
15+
*/
16+
public void showError(String title, String message, Throwable e, int exit_code) {
17+
if (title == null) title = _("Error");
18+
19+
System.err.println(title + ": " + message);
20+
21+
if (e != null) e.printStackTrace();
22+
System.exit(exit_code);
23+
}
24+
25+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package processing.app.helpers;
2+
3+
import static processing.app.I18n._;
4+
5+
import java.awt.Frame;
6+
7+
import javax.swing.JOptionPane;
8+
9+
public class GUINotifier implements UserNotifier {
10+
11+
public void showError(String title, String message, Throwable e) {
12+
showError(title, message, e, 1);
13+
}
14+
15+
/**
16+
* Show an error message that's actually fatal to the program.
17+
* This is an error that can't be recovered. Use showWarning()
18+
* for errors that allow P5 to continue running.
19+
*/
20+
public void showError(String title, String message, Throwable e, int exit_code) {
21+
if (title == null) title = _("Error");
22+
23+
JOptionPane.showMessageDialog(new Frame(), message, title,
24+
JOptionPane.ERROR_MESSAGE);
25+
26+
if (e != null) e.printStackTrace();
27+
System.exit(exit_code);
28+
}
29+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package processing.app.helpers;
2+
3+
public interface UserNotifier {
4+
5+
public void showError(String title, String message, Throwable e);
6+
7+
public void showError(String title, String message, Throwable e, int exit_code);
8+
9+
}

0 commit comments

Comments
 (0)