1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package org.microemu.app.ui;
28
29 import java.util.Iterator;
30 import java.util.List;
31 import java.util.Vector;
32
33 import org.microemu.log.Logger;
34
35
36
37
38
39
40
41
42 public class Message {
43
44 public static final int ERROR = 0;
45
46 public static final int INFO = 1;
47
48 public static final int WARN = 2;
49
50 private static List listeners = new Vector();
51
52 static {
53 Logger.addLogOrigin(Message.class);
54 }
55
56
57
58
59
60
61
62 public static void error(String title, String text) {
63 Logger.error("Message: " + title + ": " + text);
64 callListeners(ERROR, title, text, null);
65 }
66
67
68
69
70
71
72 public static void error(String text) {
73 Logger.error("Message: Error: " + text);
74 callListeners(ERROR, "Error", text, null);
75 }
76
77
78
79
80
81
82
83 public static void error(String title, String text, Throwable throwable) {
84 Logger.error("Message: " + title + ": " + text, throwable);
85 callListeners(ERROR, title, text, throwable);
86 }
87
88 public static void error(String text, Throwable throwable) {
89 Logger.error("Message: Error : " + text, throwable);
90 callListeners(ERROR, "Error", text, throwable);
91 }
92
93
94
95
96
97
98 public static void info(String text) {
99 Logger.info("Message: info: " + text);
100 callListeners(INFO, "Info", text, null);
101 }
102
103
104
105
106
107
108 public static void warn(String text) {
109 Logger.warn("Message: warn: " + text);
110 callListeners(INFO, "Warning", text, null);
111 }
112
113
114
115
116
117
118 public static String getCauseMessage(Throwable throwable) {
119 if (throwable.getCause() == null) {
120 return throwable.toString();
121 } else {
122 return getCauseMessage(throwable.getCause());
123 }
124 }
125
126 private static void callListeners(int level, String title, String text, Throwable throwable) {
127 for (Iterator iter = listeners.iterator(); iter.hasNext();) {
128 MessageListener a = (MessageListener) iter.next();
129 a.showMessage(level, title, text, throwable);
130 };
131 }
132
133 public static void addListener(MessageListener newListener) {
134 listeners.add(newListener);
135 }
136 }