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