001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.client.event;
019:
020: import java.util.logging.Logger;
021:
022: /**
023: * Created when a user message is sent from the server.
024: */
025: public class MessageEvent extends AbstractContelligentEvent {
026:
027: /**
028: * For logging messages and errors.
029: */
030: private static Logger logger = Logger.getLogger(MessageEvent.class
031: .getName());
032:
033: /**
034: * The importance of the message is invalid.
035: */
036: public static final int IMPORTANCE_NIL = 0;
037:
038: /**
039: * The importance of the message is medium.
040: */
041: public static final int IMPORTANCE_MEDIUM = 1;
042:
043: /**
044: * The importance of the message is high.
045: */
046: public static final int IMPORTANCE_HIGH = 2;
047:
048: /**
049: * The message type is invalid.
050: */
051: public static final int TYPE_NIL = 0;
052:
053: /**
054: * The message has been sent from the user.
055: */
056: public static final int TYPE_FROM = 1;
057:
058: /**
059: * The message is being sent to the user.
060: */
061: public static final int TYPE_TO = 2;
062:
063: /**
064: * The message is being sent to all users.
065: */
066: public static final int TYPE_TO_ALL = 3;
067:
068: /**
069: * The user has sent himself a message.
070: */
071: public static final int TYPE_TO_SELF = 4;
072:
073: /**
074: * The name of the user who sent or is receiving the message.
075: */
076: private String user = null;
077:
078: /**
079: * The message text.
080: */
081: private String message = null;
082:
083: /**
084: * The importance of the message. This may be one of the importance levels
085: * IMPORTANCE_*.
086: */
087: private int importance = IMPORTANCE_NIL;
088:
089: /**
090: * The message type. This may be one of the types TYPE_*.
091: */
092: private int type = TYPE_NIL;
093:
094: /**
095: * Creates a message event.
096: *
097: * @param source
098: * the object which produced this event.
099: * @param user
100: * if `type' is `from', `to-all' or `to-self', this is the name
101: * of the user who sent the message. Otherwise, it is the name of
102: * the name of the user receiving the message.
103: * @param message
104: * the message text.
105: * @param importance
106: * the importance of the message. This can be either `medium' or
107: * `high'.
108: * @param type
109: * the type of message being sent. This may be `from', `to',
110: * `to-all' or `to-self'.
111: */
112: public MessageEvent(Object source, String user, String message,
113: String importance, String type) {
114: super (source);
115: this .user = user;
116: this .message = message;
117: if (importance.equals("high")) {
118: this .importance = IMPORTANCE_HIGH;
119: } else if (importance.equals("medium")) {
120: this .importance = IMPORTANCE_MEDIUM;
121: } else {
122: // Use default importance.
123: }
124: logger.info("message event type: " + type);
125: if (type.equals("from")) {
126: this .type = TYPE_FROM;
127: } else if (type.equals("to")) {
128: this .type = TYPE_TO;
129: } else if (type.equals("to-all")) {
130: this .type = TYPE_TO_ALL;
131: } else if (type.equals("to-self")) {
132: this .type = TYPE_TO_SELF;
133: } else {
134: // Use default type.
135: }
136: }
137:
138: /**
139: * Get how important the message is.
140: *
141: * @return the importance of the message.
142: */
143: public int getImportance() {
144: return importance;
145: }
146:
147: /**
148: * Get the message text.
149: *
150: * @return the message text.
151: */
152: public String getMessage() {
153: return message;
154: }
155:
156: /**
157: * Get the type of the message. This may be one of the types TYPE_*.
158: *
159: * @return the type of the message.
160: */
161: public int getType() {
162: return type;
163: }
164:
165: /**
166: * Get the name of the user who sent or is receiving the message.
167: *
168: * @return the name of the user.
169: */
170: public String getUser() {
171: return user;
172: }
173:
174: public String toString() {
175: return getClass().getName() + "[user=" + user + ", message="
176: + message + ", importance=" + message + ", type="
177: + type + "]";
178: }
179: }
|