Source code: plugins/Messenger/AbstractConversation.java
1 /*
2 This file is part of DeXter - Java Internet Communication Solution
3 Copyright (c) 2002 Tobias Riemer
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
13 GNU 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 program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20 /*
21 * AbstractConversation.java
22 *
23 * Created on November 4, 2002, 1:56 PM
24 */
25
26 package plugins.Messenger;
27
28 import java.util.*;
29 import plugins.Messenger.event.*;
30
31 /**
32 *
33 * @author christoph
34 */
35 public abstract class AbstractConversation implements Conversation {
36
37 private java.util.Vector conversationListeners = new java.util.Vector();
38
39 protected ChatFrame interactionFrame = null;
40
41 /** Creates a new instance of AbstractConversation */
42 public AbstractConversation() {
43 }
44
45 public void addConversationListener(ConversationListener cl) {
46 conversationListeners.add(cl);
47 }
48
49 public void removeConversationListener(ConversationListener cl) {
50 conversationListeners.remove(cl);
51 }
52
53 public void fireMessageReceived(String login, String nick, String msg) {
54 Iterator listenerIter = conversationListeners.iterator();
55
56 while (listenerIter.hasNext()) {
57 ConversationListener listener = (ConversationListener)listenerIter.next();
58 listener.messageReceived(login, nick, msg);
59 }
60 }
61
62 public void fireUserLeft(String account) {
63
64 Iterator listenerIter = conversationListeners.iterator();
65
66 while (listenerIter.hasNext()) {
67 ConversationListener listener = (ConversationListener)listenerIter.next();
68 listener.userLeft(account);
69 }
70 }
71
72 public void fireUserTyping(String login, String nick) {
73 Iterator listenerIter = conversationListeners.iterator();
74
75 while (listenerIter.hasNext()) {
76 ConversationListener listener = (ConversationListener)listenerIter.next();
77 listener.userTyping(login, nick);
78 }
79 }
80
81 /**
82 * @todo need an implementation of IRO & JOI Command. This is wrong!!!!
83 */
84 public void fireUserJoined(String login, String nick) {
85 Iterator listenerIter = conversationListeners.iterator();
86
87 while (listenerIter.hasNext()) {
88 ConversationListener listener = (ConversationListener)listenerIter.next();
89 listener.userJoined(login,nick);
90 }
91 }
92
93 protected void showFrame(boolean visible) {
94
95 if (visible) {
96 if (interactionFrame == null) {
97 // Create a PluginChain for this Conversation
98 PluginChain chain = PluginManager.createPluginChain(this);
99 interactionFrame = ChatFrameFactory.createChatFrame(chain, getMessengerEngine());
100 interactionFrame.show();
101 }
102 else if (!interactionFrame.isVisible()) {
103 interactionFrame.setVisible(true);
104 }
105 }
106 else {
107 if (interactionFrame != null) {
108 interactionFrame.setVisible(false);
109 }
110 }
111 }
112 }