KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > reunion > ReunionMessage


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2004 Jonathan Riboux <jonathan.riboux@wanadoo.fr>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package org.lucane.applications.reunion;
20
21 import java.io.Serializable JavaDoc;
22 import java.text.DateFormat JavaDoc;
23 import java.util.Date JavaDoc;
24
25 /**
26  * @author Jonathan Riboux
27  *
28  * Creates and format messages that are used under the meeting plugin.
29  */

30 public class ReunionMessage implements Serializable JavaDoc {
31   /** type of the message */
32   private int type;
33   /** datas */
34   private Object JavaDoc data;
35
36   /**
37    * Text message type. Concerns normal text messages.
38    */

39   public static final int TYPE_TEXT = 1;
40
41   /**
42    * Join message type. Concerns join messages to inform users that a new one
43    * joined the meeting.
44    */

45   public static final int TYPE_JOIN = 2;
46
47   /**
48    * End message type. Concerns end messages to inform users that the meeting
49    * has ended.
50    */

51   public static final int TYPE_END = 3;
52
53   /**
54    * Leave message type. Concerns leave messages to inform users that a user
55    * left the meeting.
56    */

57   public static final int TYPE_LEAVE = 4;
58
59   
60   /**
61    * Send the user list
62    */

63   public static final int TYPE_USERLIST = 5;
64
65   /**
66    * Constructor.
67    * @param type
68    * The message type.
69    * @param data
70    * The data to transfer.
71    */

72   protected ReunionMessage(int type, Object JavaDoc data) {
73     this.type = type;
74     this.data = data;
75   }
76
77   /**
78    * Creates a text message.
79    * @param user
80    * The user login who sent the message.
81    * @param text
82    * The text sent by the user
83    * @return
84    * A new instance of ReunionMessage.
85    */

86   public static ReunionMessage createTextInstance(String JavaDoc user, String JavaDoc text) {
87     String JavaDoc[] dt = { user, text };
88     return new ReunionMessage(TYPE_TEXT, dt);
89   }
90
91   /**
92    * Creates a join message.
93    * @param user
94    * The user login who joint the meeting.
95    * @return
96    * A new instance of ReunionMessage.
97    */

98   public static ReunionMessage createJoinInstance(String JavaDoc user) {
99     return new ReunionMessage(TYPE_JOIN, user);
100   }
101
102   /**
103    * Creates a leave message.
104    * @param user
105    * The user login who left the meeting.
106    * @return
107    * A new instance of ReunionMessage.
108    */

109   public static ReunionMessage createLeaveInstance(String JavaDoc user) {
110     return new ReunionMessage(TYPE_LEAVE, user);
111   }
112
113   /**
114    * Creates an end message.
115    * @return
116    * A new instance of ReunionMessage.
117    */

118   public static ReunionMessage createEndInstance() {
119     return new ReunionMessage(TYPE_END, null);
120   }
121     
122   /**
123    * Creates a user list instance
124    * @return
125    * A new instance of ReunionMessage.
126    */

127   public static ReunionMessage createUserListInstance(ReunionUsersProperties props) {
128     return new ReunionMessage(TYPE_USERLIST, props);
129   }
130
131   /**
132    * Retrieves the data contained in the message.
133    * @return
134    * The data contained in the message.
135    */

136   public Object JavaDoc getData() {
137     return data;
138   }
139
140   /**
141      * Sets the data contained in the message.
142      * @param object
143      * The data to put in the message.
144      */

145   public void setData(Object JavaDoc object) {
146     data = object;
147   }
148
149   /**
150    * Retrieves the type of the message.
151    * @return
152    * The type of the message.
153    */

154   public int getType() {
155     return type;
156   }
157
158   /**
159    * Sets the type of the message.
160    * @param i
161    * The type of the message.
162    */

163   public void setType(int i) {
164     type = i;
165   }
166
167   /**
168    * Creates the HTML code to show in the reunion plugin.
169    * @param reunion The plugin using this instance of ReunionMessage
170    * @return The HTML code to show in the reunion plugin.
171    */

172   public String JavaDoc toString(Reunion reunion) {
173     if (type == TYPE_TEXT)
174       return createHTMLTextMessage(
175         reunion,
176         ((String JavaDoc[]) data)[0],
177         ((String JavaDoc[]) data)[1]);
178     else if (type == TYPE_END)
179       return createHTMLInfoMessage(reunion, reunion.tr("endMsg"));
180     else if (type == TYPE_JOIN)
181       return createHTMLInfoMessage(
182         reunion,
183         reunion.tr("joinMsg") + (String JavaDoc) data);
184     else if (type == TYPE_LEAVE)
185       return createHTMLInfoMessage(
186         reunion,
187         reunion.tr("leaveMsg") + (String JavaDoc) data);
188     return null;
189   }
190
191   /**
192    * Creates the HTML code to show in the reunion plugin.
193    * @param reunion The plugin using this instance of ReunionMessage
194    * @param user The user who wrote the message.
195    * @param message The message wroten by the user.
196    * @return The HTML code to show in the reunion plugin.
197    */

198   public static String JavaDoc createHTMLTextMessage(
199     Reunion reunion,
200     String JavaDoc user,
201     String JavaDoc message) {
202     String JavaDoc res = null;
203     ReunionUserProperties rup = reunion.getUsersProperties().getUserProperties(user);
204     res =
205       "<DIV "
206         + "STYLE=\"padding:0px;margin-bottom:2px;"
207         + "border-width:1px;border-style:solid;border-color:"+rup.getFgColor()+";"
208         + "background-color:"+rup.getBgColor()+";width:100%;\">"
209         + "<font size=2>"
210         + DateFormat.getTimeInstance(DateFormat.SHORT).format(new Date JavaDoc())
211         + "</font>&nbsp;<b><font size=4 color=\""+rup.getFgColor()+"\">"
212         + user
213         + "</font><font size=4>&nbsp;&gt; </font></b>"
214         + "<font size=4>"
215         + message
216         + "</font></DIV>";
217     return res;
218   }
219
220   /**
221    * Creates the HTML code to show in the reunion plugin.
222    * @param reunion The plugin using this instance of ReunionMessage
223    * @param message The message to display.
224    * @return the HTML info message
225    */

226   public static String JavaDoc createHTMLInfoMessage(Reunion reunion, String JavaDoc message) {
227     String JavaDoc res;
228     res = "<DIV><FONT SIZE=4 COLOR=#888888>" + message + "</FONT></DIV>";
229     return res;
230   }
231 }
232
Popular Tags