1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.firemox.network;
20
21 import net.sf.firemox.network.message.ChatMessage;
22 import net.sf.firemox.tools.Log;
23 import net.sf.firemox.ui.MagicUIComponents;
24
25 /***
26 * This chat is a thread looking for a chat data in the big pipe Display
27 * discussion is : $user - $message When a null length message is sent, that
28 * would say "disconnection" since user can't send a null length message. So if
29 * user want to send a null length message nothing is sent. When disconnection
30 * is detected, a message like " **disconnection **" is printed into the history
31 * text area.
32 *
33 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
34 * @since 0.3
35 */
36 public class MChat {
37
38 /***
39 * Create a new instance private of this class.
40 */
41 private MChat() {
42 super();
43 }
44
45 /***
46 * Send a specified message to opponent and display it into our chat.
47 *
48 * @param message
49 * is the specified message to send.
50 */
51 public void sendMessage(String message) {
52 try {
53 MagicUIComponents.chatHistoryText.append(0, message);
54 MBigPipe.instance.send(new ChatMessage(message));
55 } catch (Throwable t) {
56 MBigPipe.instance.send(new ChatMessage("<i>" + message
57 + "</i> could not be sent : " + t.getMessage()));
58 Log.error("Message could not be sent", t);
59 }
60 }
61
62 /***
63 * To receive a message.
64 *
65 * @param message
66 * the input message.
67 */
68 public void receiveMessage(ChatMessage message) {
69 MagicUIComponents.chatHistoryText.append(1, message.getText());
70 }
71
72 /***
73 * Return the unique instance of this class.
74 *
75 * @return the unique instance of this class.
76 */
77 public static MChat getInstance() {
78 return instance;
79 }
80
81 /***
82 * Unique instance of this class.
83 */
84 private final static MChat instance = new MChat();
85 }