01: // The contents of this file are subject to the Mozilla Public License Version
02: // 1.1
03: //(the "License"); you may not use this file except in compliance with the
04: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
05: //
06: //Software distributed under the License is distributed on an "AS IS" basis,
07: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
08: //for the specific language governing rights and
09: //limitations under the License.
10: //
11: //The Original Code is "The Columba Project"
12: //
13: //The Initial Developers of the Original Code are Frederik Dietz and Timo
14: // Stich.
15: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16: //
17: //All Rights Reserved.
18: package org.columba.chat;
19:
20: import javax.swing.event.EventListenerList;
21:
22: import org.columba.chat.config.api.IAccount;
23: import org.columba.chat.conn.api.ConnectionChangedEvent;
24: import org.columba.chat.conn.api.IConnection;
25: import org.columba.chat.conn.api.IConnectionChangedListener;
26: import org.jivesoftware.smack.XMPPConnection;
27:
28: public class Connection implements IConnection {
29:
30: private STATUS status;
31:
32: private EventListenerList listenerList = new EventListenerList();
33:
34: public static XMPPConnection XMPPConnection;
35:
36: public Connection() {
37: super ();
38: }
39:
40: public STATUS getStatus() {
41: return status;
42: }
43:
44: public void setStatus(STATUS status) {
45: this .status = status;
46:
47: fireSelectionChanged(MainInterface.config.getAccount(), status);
48: }
49:
50: /**
51: * Adds a listener.
52: */
53: public void addConnectionChangedListener(
54: IConnectionChangedListener listener) {
55: listenerList.add(IConnectionChangedListener.class, listener);
56: }
57:
58: /**
59: * Removes a previously registered listener.
60: */
61: public void removeConnectionChangedListener(
62: IConnectionChangedListener listener) {
63: listenerList.remove(IConnectionChangedListener.class, listener);
64: }
65:
66: /**
67: * Propagates an event to all registered listeners notifying them that the
68: * connection status has changed
69: */
70: public void fireSelectionChanged(IAccount account, STATUS status) {
71: ConnectionChangedEvent e = new ConnectionChangedEvent(this ,
72: account, status);
73: // Guaranteed to return a non-null array
74: Object[] listeners = listenerList.getListenerList();
75:
76: // Process the listeners last to first, notifying
77: // those that are interested in this event
78: for (int i = listeners.length - 2; i >= 0; i -= 2) {
79: if (listeners[i] == IConnectionChangedListener.class) {
80: ((IConnectionChangedListener) listeners[i + 1])
81: .connectionChanged(e);
82: }
83: }
84: }
85:
86: }
|